CentOS7搭建GitLab服务器

  • A+
所属分类:linux技术
摘要

网上很多GitLab的安装教程,但是很多都有一些坑,今天根据我安装过程中的发现的坑和如何解决的过程记录下来,希望方便到和我遇到类似问题的人。

网上很多GitLab的安装教程,但是很多都有一些坑,今天根据我安装过程中的发现的坑和如何解决的过程记录下来,希望方便到和我遇到类似问题的人。

1. 安装依赖软件

【yum -y install policycoreutils openssh-server openssh-clients postfix】

2.设置postfix开机自启,并启动,postfix支持gitlab发信功能

【systemctl enable postfix && systemctl start postfix】

3.下载gitlab安装包,然后安装

centos 7系统的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7

【wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-8.0.0-ce.0.el7.x86_64.rpm】

【rpm -i gitlab-ce-8.0.0-ce.0.el7.x86_64.rpm】

4.修改gitlab配置文件指定服务器ip和自定义端口:

【vim  /etc/gitlab/gitlab.rb】   进入到配置文件

 CentOS7搭建GitLab服务器

 通过vim的查找命令【/external_url】快速找到需要修改的地方,然后通过命令:【i】,进去编辑页面,去到external_url的位置,设置访问gitlab的访问ip和端口。编辑完成之后,按下键盘:【ESC】键,然后输入命令【 :wq】退出并保存。

5.重置并启动GitLab

执行:

gitlab-ctl reconfigure

gitlab-ctl restart

ok: run: gitlab-git-http-server: (pid 3922) 1s

ok: run: logrotate: (pid 3929) 0s

ok: run: nginx: (pid 3936) 1s

ok: run: postgresql: (pid 3941) 0s

ok: run: redis: (pid 3950) 0s

ok: run: sidekiq: (pid 3955) 0s

ok: run: unicorn: (pid 3961) 1s

提示“ok: run:”表示启动成功

6.访问 GitLab页面

如果没有域名,直接输入服务器ip和指定端口进行访问,但是很不巧,输入网址和域名之后,显示的不是登陆,出现错误提示页面:

CentOS7搭建GitLab服务器

 经过各种百度,试过几种方法,最终找到最大存在的原因,8080端口被占用,感觉这个可能性最大,因为gitlab配置文件有些监听用到8080端口,所以马上按照别人的提示进行了修改,修改内容如下:

通过命令【vim  /etc/gitlab/gitlab.rb】 找到gitlab.rb这个配置文件进行修改,按照上面的快速查找方法,找到下面两行内容进行修改

566:# gitlab_workhorse['auth_backend'] = "http://localhost:8080" 633:# unicorn['port'] = 8080

把前面的注释打开,然后修改成别空的端口,
#使配置生效
【gitlab-ctl reconfigure】
#重新启动GitLab
【gitlab-ctl restart】
即可生效,重新试着打开上面配置的服务器ip和指定端口进行访问,可以正确打开登陆页面,但是第一次默认登陆的账户密码是多少呢?下一步就是解决这个问题。

7.获取/修改超级管理员root的密码

执行如下命令:

a、 切换目录:【cd /opt/gitlab/bin】

b、执行 :sudo gitlab-rails console production 命令 开始初始化密码

c、在irb(main):001:0> 后面通过 u=User.where(id:1).first 来查找与切换账号(User.all 可以查看所有用户)

d、通过u.password='12345678'设置密码为12345678(这里的密码看自己喜欢):

e、通过u.password_confirmation='12345678' 再次确认密码

f、通过 u.save!进行保存(切记切记 后面的 !)

g、如果看到上面截图中的true ,恭喜你已经成功了,执行 exit 退出当前设置流程即可。

h、回到gitlab ,可以通过 root/12345678 这一超级管理员账号登录了,至此大功告成。

CentOS7搭建GitLab服务器

8.设置gitlab发信功能,需要注意一点:

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'] = "qinxxxxx" 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]'

gitlab-ctl reconfigure

gitlab-ctl restart

进入控制台:

gitlab-rails console

测试邮件发送:

Notify.test_email('[email protected]', '测试报告', '这是我的测试报告,请查收!').deliver_now