centos搭建gitlab服务器

xiaoxiao2021-02-28  78

背景

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

安装依赖,postfix为邮件服务

sudo yum install curl policycoreutils openssh-server openssh-clients sudo systemctl enable sshd sudo systemctl start sshd sudo yum install postfix sudo systemctl enable postfix sudo systemctl start postfix sudo firewall-cmd --permanent --add-service=http sudo systemctl reload firewalld

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

ERRO:

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

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

inet_interfaces = localhost inet_protocols = all

改成:

inet_interfaces = all 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 .

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 才是根本解决办法

修改仓库存放位置

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

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

修改备份地址

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

修改上传为文件地址

[root@gitlabServer gitlab-rails]# mkdir -r /mnt/opt/gitlab/gitlab-rails/uploads gitlab_rails['uploads_directory'] = "/mnt/opt/gitlab/gitlab-rails/uploads" [root@gitlabServer gitlab-rails]# cp -r /var/opt/gitlab/gitlab-rails/uploads/* /mnt/opt/gitlab/gitlab-rails/uploads [root@gitlabServer gitlab-rails]# chown -R git:git /mnt/opt/gitlab [root@gitlabServer gitlab-rails]# ls -l /mnt/opt/gitlab/ total 12 drwxr-xr-x 2 git git 4096 May 6 13:09 backups drwx------ 3 git git 4096 May 5 18:40 git-data 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 结束当前进程

#sudo systemctl restart gitlab-runsvdir #再次启动配置 #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地址即可,保存退出

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

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

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

# postgresql['dir'] = "/var/opt/gitlab/postgresql" # postgresql['data_dir'] = "/var/opt/gitlab/postgresql/data" # postgresql['log_directory'] = "/var/log/gitlab/postgresql" # postgresql['home'] = "/var/opt/gitlab/postgresql" postgresql['dir'] = "/mnt/opt/gitlab/postgresql" postgresql['data_dir'] = "/mnt/opt/gitlab/postgresql/data" postgresql['log_directory'] = "/mnt/opt/gitlab/postgresql/log" postgresql['home'] = "/mnt/opt/gitlab/postgresql" mkdir -p /mnt/opt/gitlab/postgresql/data mkdir -p /mnt/opt/gitlab/postgresql/log 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文件,将以下设置添加到文件中,保存。

gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = “smtp.163.com” gitlab_rails['smtp_port'] = 25 gitlab_rails['smtp_user_name'] = “zjcjava@163.com“ gitlab_rails['smtp_password'] = "smtp password" gitlab_rails['smtp_authentication']= “login" gitlab_rails['smtp_enable_starttls_auto']= true gitlab_rails['gitlab_email_from']= 'zjcjava@163.com' 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

转载请注明原文地址: https://www.6miu.com/read-54087.html

最新回复(0)