centos搭建gitlab服务器

柔光的暖阳◎ 2022-06-16 05:10 415阅读 0赞

背景

本来花了些时间安装git和gitolite,但是它没有界面,而且权限管理每次都要传pub,配置文件,不方便直观使用,便直接安装gitlab版本,这样使用更加方便,也便于直观的管理,当然最重要的是界面很炫不是么。

安装依赖,postfix为邮件服务

  1. sudo yum install curl policycoreutils openssh-server openssh-clients
  2. sudo systemctl enable sshd
  3. sudo systemctl start sshd
  4. sudo yum install postfix
  5. sudo systemctl enable postfix
  6. sudo systemctl start postfix
  7. sudo firewall-cmd --permanent --add-service=http
  8. sudo systemctl reload firewalld

开启邮件服务的时候报错如下

ERRO:

fatal: parameter inet_
http://blog.csdn.net/xiangshanqishi/article/details/23439397

解决办法为
vi /etc/postfix/main.cf
发现配置为:

  1. inet_interfaces = localhost
  2. inet_protocols = all

改成:

  1. inet_interfaces = all
  2. inet_protocols = all

安装gitlab

国外镜像下载太慢,官网的安装方式不适合
直接下载清华镜像上的最新版本的rpm
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/
安装该版本
rpm -i gitlab-ce-XXX.rpm

gitlab参数配置

自GitLab 7.6开始的新安装包, 已经默认将所有的参数写入到 /etc/gitlab/gitlab.rb 文件中.
vim /etc/gitlab/gitlab.rb

修改默认端口

external_url ‘http://gitlabServer’
修改为
external_url ‘http://localhost:90’

去掉注释并修改port为9080

unicorn[‘listen’] = ‘127.0.0.1’
unicorn[‘port’] = 9080

成功访问web

重新生成gitlab
sudo gitlab-ctl reconfigure

http://ip:90
开始会让你root登陆然后设置新密码
这里写图片描述

修改项目显示地址localhost为实际地址

在GitLab上新建一个项目test_gitlab,刚开始仓库地址是http://localhost/yulei/test_gitlab.git .

  1. vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

修改gitlab下host值为实际的域名或服务器IP地址即可,保存退出
图片地址

重启GitLab
gitlab-ctl restart

注意:这种方法只是暂时性的,如果你sudo gitlab-ctl reconfigure 之后还是会遇到这个问题,根本解决办法如下

这里的host和port都是根据/etc/gitlab/gitlab.rb
中的external_url的值取的host和port,因此修改gitlab.rb中的external_url
external_url “http://119.1001.11.1:90”
然后
sudo gitlab-ctl reconfigure
才是根本解决办法

修改仓库存放位置

系统盘容量太小,创建新地址:

  1. mkdir -p /mnt/opt/gitlab/git-data
  2. [root@gitlabServer gitlab-rails]# mkdir -r /mnt/opt/gitlab/git-data
  3. # git_data_dirs({ "default" => { "path" => "/var/opt/gitlab/git-data", 'gitaly_address' => 'unix:/var/opt/gitlab/gitaly/gitaly.socket' } })
  4. git_data_dirs({ "default" => { "path" => "/mnt/opt/gitlab/git-data", 'gitaly_address' => 'unix:/var/opt/gitlab/gitaly/gitaly.socket' } })

修改备份地址

  1. [root@gitlabServer gitlab-rails]# mkdir -r /mnt/opt/gitlab/backups
  2. gitlab_rails['backup_path'] = "/mnt/opt/gitlab/backups"

修改上传为文件地址

  1. [root@gitlabServer gitlab-rails]# mkdir -r /mnt/opt/gitlab/gitlab-rails/uploads
  2. gitlab_rails['uploads_directory'] = "/mnt/opt/gitlab/gitlab-rails/uploads"
  3. [root@gitlabServer gitlab-rails]# cp -r /var/opt/gitlab/gitlab-rails/uploads/* /mnt/opt/gitlab/gitlab-rails/uploads
  4. [root@gitlabServer gitlab-rails]# chown -R git:git /mnt/opt/gitlab
  5. [root@gitlabServer gitlab-rails]# ls -l /mnt/opt/gitlab/
  6. total 12
  7. drwxr-xr-x 2 git git 4096 May 6 13:09 backups
  8. drwx------ 3 git git 4096 May 5 18:40 git-data
  9. drwxr-xr-x 3 git git 4096 May 6 13:24 gitlab-rails

重新生成gitlab
sudo gitlab-ctl reconfigure

gitlab之坑

卸载问题

一、停止gitlab
sudo gitlab-ctl stop
二、卸载gitlab
sudo rpm -e gitlab-ce
三、查看gitlab进程
ps -ef |grep gitlab
 杀掉第一个守护进程
kill -9 4473
 再次查看gitlab进程是否存在
四、删除gitlab文件
find / -name gitlab|xargs rm -rf 删除所有包含gitlab的文件及目录
删除gitlab-ctl uninstall时自动在root下备份的配置文件

重新安装之:ruby_block[supervise_redis_sleep] action run

此时会一直阻塞到这里,解决办法如下:
CTRL+C 结束当前进程

  1. #sudo systemctl restart gitlab-runsvdir
  2. #再次启动配置
  3. #sudo gitlab-ctl reconfigure

此解决方法原文出自:
https://gitlab.com/gitlab-org/omnibus-gitlab/issues/160

解决私有仓库的地址指向localhost的问题

git@localhost:test/test.git
私有仓库的地址居然是localhost,不是本机的IP地址
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
修改gitlab下host值为实际的域名或服务器IP地址即可,保存退出

  1. production: &base
  2. #
  3. # 1. GitLab app settings
  4. # ==========================
  5. ## GitLab settings
  6. gitlab:
  7. ## Web server settings (note: host is the FQDN, do not include http://)
  8. host: 192.190.116.10 #改成你自己的IP
  9. port: 90 #改成你自己配置的端口

数据库配置(建议不动,下面的操作目前我测试是失败的,有操作成功或者修改为mysql的请联系我)

默认情况下,GitLab会将数据库文件放在 /var/opt/gitlab/postgresql/data 中。
如果要修改数据库文件位置,需要将 /var/opt/gitlab/postgresql/data 中的所有文件复制到新的位置,然后在 /etc/gitlab/gitlab.rb 中设置以下4个配置至新的位置:

  1. # postgresql['dir'] = "/var/opt/gitlab/postgresql"
  2. # postgresql['data_dir'] = "/var/opt/gitlab/postgresql/data"
  3. # postgresql['log_directory'] = "/var/log/gitlab/postgresql"
  4. # postgresql['home'] = "/var/opt/gitlab/postgresql"
  5. postgresql['dir'] = "/mnt/opt/gitlab/postgresql"
  6. postgresql['data_dir'] = "/mnt/opt/gitlab/postgresql/data"
  7. postgresql['log_directory'] = "/mnt/opt/gitlab/postgresql/log"
  8. postgresql['home'] = "/mnt/opt/gitlab/postgresql"
  9. mkdir -p /mnt/opt/gitlab/postgresql/data
  10. mkdir -p /mnt/opt/gitlab/postgresql/log
  11. chown -R gitlab-psql /mnt/opt/gitlab/postgresql

保存退出,并执行完成
sudo gitlab-ctl reconfigure

解决gitlab组成员提交文件被拒绝的问题

git客户端报错:
remote: GitLab: You are not allowed to push code to protected branches on this project.
项目所属者点击项目点击settting,下图中Allowed to push下拉选择”Master+Developers”即可,它会自动保存设置
这里写图片描述

配置gitlab发送邮件人为自定义邮箱

以163邮箱为例
打开/etc/gitlab/gitlab.rb文件,将以下设置添加到文件中,保存。

  1. gitlab_rails['smtp_enable'] = true
  2. gitlab_rails['smtp_address'] = smtp.163.com
  3. gitlab_rails['smtp_port'] = 25
  4. gitlab_rails['smtp_user_name'] = zjcjava@163.com
  5. gitlab_rails['smtp_password'] = "smtp password"
  6. gitlab_rails['smtp_authentication']= login" gitlab_rails['smtp_enable_starttls_auto']= true
  7. gitlab_rails['gitlab_email_from']= 'zjcjava@163.com'
  8. gitlab_rails['gitlab_email_reply_to']= ‘zjcjava@163.com'

参考资料

https://www.gitlab.com.cn/downloads/#centos7
https://docs.gitlab.com.cn/omnibus/settings/configuration.html

发表评论

表情:
评论列表 (有 0 条评论,415人围观)

还没有评论,来说两句吧...

相关阅读