Centos 7搭建Gitlab服务器、发邮件修改密码、修改默认端口号(更新时间2020/01/10 12:56)

1、安装gitlab服务器之前我们需要去下载gitlab源

# 先检查是否有wget下载工具
[root@VM_0_3_centos ~]# wget --version
GNU Wget 1.14 built on linux-gnu.
.......
.......
# 我这里是有的,如果没有就安装
[root@VM_0_3_centos ~]# yum install -y wget

# 准备下载gitlab源
[root@VM_0_3_centos ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm

# 下载完成之后需要安装postfix用来git已邮件通知, 一般centos都会自带,
[root@VM_0_3_centos ~]# yum install postfix
# 所以只需要设备开机自动启动就行
[root@VM_0_3_centos ~]# systemctl enable postfix


# 安装gitlab源
[root@VM_0_3_centos ~]# rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
error: Failed dependencies:
	policycoreutils-python is needed by gitlab-ce-10.0.0-ce.0.el7.x86_64

# 上面提示我需要先安装policycoreutils-python, 我就先安装policycoreutils-python
# 安装policycoreutils-python
[root@VM_0_3_centos ~]# yum install -y policycoreutils-python

# 安装完成之后我们继续安装gitlab服务器
[root@VM_0_3_centos ~]# rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  


     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ \`/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

[root@VM_0_3_centos ~]# 
# 说明安装成功

2、修改配置、正常访问

# 安装的gitlab默认配置文件在/etc/gitlab下面
[root@VM_0_3_centos ~]# vim /etc/gitlab/gitlab.rb 
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
#####################################
external_url 'http://localhost:8953'
#####################################
# 修改口号, 我这里改成了8953, 有domain的建议用domain, 
# 否则配置下面发送邮件的地址, 邮件中就显示localhost:8953
#

3、启动

# 配置gitlab, 可能时间会比较久
[root@VM_0_3_centos ~]# gitlab-ctl reconfigure

# 重启
[root@VM_0_3_centos ~]# gitlab-ctl restart
ok: run: gitaly: (pid 20455) 1s
ok: run: gitlab-monitor: (pid 20471) 0s
ok: run: gitlab-workhorse: (pid 20477) 0s
ok: run: logrotate: (pid 20521) 1s
ok: run: nginx: (pid 20527) 0s
ok: run: node-exporter: (pid 20536) 1s
ok: run: postgres-exporter: (pid 20540) 0s
ok: run: postgresql: (pid 20555) 1s
ok: run: prometheus: (pid 20570) 0s
ok: run: redis: (pid 20575) 1s
ok: run: redis-exporter: (pid 20580) 0s
ok: run: sidekiq: (pid 20589) 0s
ok: run: unicorn: (pid 20598) 0s
[root@VM_0_3_centos ~]# 
# 说明重启成功

4、访问, 可能天让你new password,这个时候输入的是root账号的密码。如果出现502:Whoops错误/或者收不到邮件,请看最下面。

 5、修改root默认密码,记住密码至少8个字符

# gitlab-rails console production 执行时可能会有点久
[root@VM_0_3_centos ~]# gitlab-rails console production
Loading production environment (Rails 4.2.8)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = '123123'
=> "123123"
irb(main):003:0> user.password_confirmation = '123123'
=> "123123"
irb(main):004:0> user.save!
ActiveRecord::RecordInvalid: Validation failed: Password is too short (minimum is 8 characters)
# 验证失败:密码太短(最少8个字符)
.....
.....
.....
.....
irb(main):009:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: 84d45288-fe2d-4e54-a813-b876f9ea8772) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", gid://gitlab/User/1
=> true
irb(main):010:0> exit
[root@VM_0_3_centos ~]# 

6、关于502: Whoops, GitLab is taking too much time to respond.
     那是因为你没有修改默认的端口号8080端口被启动了,有进程占用了。我们需要 修改端口,与上面修改端口号方式一样
     [root@VM_0_3_centos ~]# vim /etc/gitlab/gitlab.rb
     然后重新加载一次配置
     [root@VM_0_3_centos ~]# gitlab-ctl reconfigure
     [root@VM_0_3_centos ~]# gitlab-ctl restart

7、GitLab收不到邮件问题

# 修改邮件配置
[root@localhost ~]# vim /etc/gitlab/gitlab.rb

# 直接插入
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "1sXXXX8"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = :login
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

gitlab_rails['gitlab_email_from'] = '[email protected]'
user["git_user_email"] = "[email protected]"


# 一共修改四个点, 用163邮箱举例, 用一个邮箱作为发送的服务端, 比如: [email protected]
gitlab_rails['smtp_user_name'] = '[email protected]'
gitlab_rails['smtp_password'] = "1st00001" # 客户端授权密码, 登录163邮箱获取
# 发送的邮箱
gitlab_rails['gitlab_email_from'] = '[email protected]'
user["git_user_email"] = "[email protected]"

# 重新加载配置
[root@localhost ~]# gitlab-ctl reconfigure

# 测试发送, 多等一会儿, 可能需要点时间,直到irb(main):003:0>出来
[root@localhost ~]# gitlab-rails console
irb(main):003:0> Notify.test_email('[email protected]', 'Message Subject', 'Message Body').deliver_now

8、修改默认端口号、可能版本不一致(仅供参考), 个人建议没必要去修改就8080,修改不好样式也会乱,所以我个人的就是external_url 'http://git.domain.cn',  啥也不加,也不改。同样邮箱也可以使用。下面就是我修改之后的,样式乱了

# 打开配置文件
[root@localhost etc]# vim /etc/gitlab/gitlab.rb
# 发现把端口号写在
external_url 'http://git.coxxxum.cn:8953'
# 这样写是可以,但是如果你要邮件修改密码的时候,如若你的防火墙没有开放8953端口,那将无法修改
# 这里实现的的是修改密码的邮件也没有端口, 我的防火墙是没有吧8953开放的, 用的nginx转发

# 第一步: 只需要/etc/gitlab/gitlab.rb加入
unicorn['port'] = 8953

# 第二步: 修改监听的端口号为8953, 可能目录不在这里(版本不一样,仅供参考)
[root@localhost etc]# vim /var/opt/gitlab/gitlab-rails/etc/unicorn.rb 

# 默认的时候8080, 我们修改和我们上面的unicorn['port']的端口一样, 改为8953, 保存退出
# What ports/sockets to listen on, and what options for them.
listen "127.0.0.1:8953", :tcp_nopush => true


# 第三步: 重载配置
[root@localhost etc]# gitlab-ctl reconfigure

看看我服务器的端口号:

发布了76 篇原创文章 · 获赞 47 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_40058321/article/details/103526366
今日推荐