CentOS搭建GITLAB服务器

1.配置环境

安装依赖包

[root@ ~]# yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python


也可以先查询软件是否安装

rpm -qa | grep vsftpd(软件名)


查询软件最新版本

yum list | grep vsftpd

启动postfix,并设置开机自启

[root@ ~]# systemctl start postfix
[root@ ~]# systemctl enable postfix


设置防火墙

firewall-cmd --add-service=http --permanent
firewall-cmd --reload

2. 国内镜像下载安装
https://mirrors.tuna.tsinghua.edu.cn/help/gitlab-ce/

新建 /etc/yum.repos.d/gitlab-ce.repo,内容为

 

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

 

再执行

sudo yum makecache
sudo yum install gitlab-ce


一键安装后可以利用rpm -ql gitlab-ce查询其文件安装路径及相关文件路径,其默认安装路径为/opt/gitlab/、程序数据及配置文件保存路
径为/var/opt/gitlab下。

相关默认位置
代码仓库保存位置:/var/opt/gitlab/git-data/repositories/
代码仓库备份位置:/var/opt/gitlab/backups/
postgresql数据及配置目录:/var/opt/gitlab/postgresql/data/
redis默认配置目录:/var/opt/gitlab/redis
gitlab主要配置文件:/etc/gitlab/gitlab.rb


3. 修改配置
编辑/etc/gitlab/gitlab.rb

修改gitlab运行外部URL默认的访问地址
# 未修gitlab.rb配置文件中nginx配置时这个配置默认配置gitlab自带的nginx端口

external_url 'http://172.17.17.10:8088' 


# 修改防火墙,开启端口

firewall-cmd --zone=public --add-port=8080/tcp --permanent


4. 重新加载配置文件

[root@ ~]# gitlab-ctl reconfigure
[root@ ~]# gitlab-ctl restart


5. 密码修改的邮件业务

修改配置文件

[root@ ~]# vim /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'] = "smtp user@163.com"

gitlab_rails['smtp_password'] = "password"

gitlab_rails['smtp_domain'] = "163.com"

gitlab_rails['smtp_authentication'] = "login"

gitlab_rails['smtp_enable_starttls_auto'] = true

# 修改gitlab配置的发信人

gitlab_rails['gitlab_email_from'] = "smtp user@163.com"

user["git_user_email"] = "smtp user@163.com"

 

重新加载配置并重启服务


[root@ ~]# gitlab-ctl reconfigure
[root@ ~]# gitlab-ctl restart


6. 数据单独移植

gitlab搭建成功后,在远程服务器目录/var/opt/gitlab/git-data/下会自动生成一个仓库repositories来存放你将来push到该服务器上的数
据。

新建目录/mnt/gitlab/git-data,将移动硬盘sdb挂载到目录/mnt/gitlab/git-data下

mount /dev/sdb /mnt/gitlab/git-data


修改文件/etc/fstab

修改gitlab配置,指定数据存储目录
使用vim打开文件/etc/gitlab/gitlab.rb,搜索git_data_dirs,添加一行字符串来指定目录.

7. 代码仓中默认地址

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

把localhost 换成本机的IP地址,修改方式如下:

修改gitlab.yml文件:

[root@ ]# cd /opt/gitlab/embedded/service/gitlab-rails/config
修改gitlab.yml文件
[root@ ]# vim gitlab.yml

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

重新配置,重启.

 

8. 备份

#Gitlab的备份目录路径设置


[root@code-server ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/gitlab/backups"    //gitlab备份目录
gitlab_rails['backup_archive_permissions'] = 0644       //生成的备份文件权限
gitlab_rails['backup_keep_time'] = 31536000              //备份保留天数为1年,单位秒

手动备份gitlab

[root@code-server backups]# gitlab-rake gitlab:backup:create

编写备份脚本 

[root@code-server backups]# pwd
/data/gitlab/backups
[root@code-server backups]# vim gitlab_backup.sh
#!/bin/bash
/usr/bin/gitlab-rake gitlab:backup:create CRON=1

Gitlab恢复操作

 
GItlab只能还原到与备份文件相同的gitlab版本。
假设在上面gitlab备份之前创建了test项目,然后不小心误删了test项目,现在就进行gitlab恢复操作:
  
1)停止相关数据连接服务
[root@code-server backups]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@code-server backups]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 1s, normally up
[root@code-server backups]# gitlab-ctl status
run: gitaly: (pid 98087) 1883s; run: log: (pid 194202) 163003s
run: gitlab-monitor: (pid 98101) 1883s; run: log: (pid 194363) 163002s
run: gitlab-workhorse: (pid 98104) 1882s; run: log: (pid 194362) 163002s
run: logrotate: (pid 98117) 1882s; run: log: (pid 5793) 160832s
run: nginx: (pid 98123) 1881s; run: log: (pid 194359) 163002s
run: node-exporter: (pid 98167) 1881s; run: log: (pid 194360) 163002s
run: postgres-exporter: (pid 98173) 1881s; run: log: (pid 194204) 163003s
run: postgresql: (pid 98179) 1880s; run: log: (pid 194365) 163002s
run: prometheus: (pid 98187) 1880s; run: log: (pid 194364) 163002s
run: redis: (pid 98230) 1879s; run: log: (pid 194358) 163002s
run: redis-exporter: (pid 98234) 1879s; run: log: (pid 194208) 163003s
down: sidekiq: 8s, normally up; run: log: (pid 194437) 163001s
down: unicorn: 21s, normally up; run: log: (pid 194443) 163001s
  
2)现在通过之前的备份文件进行恢复(必须要备份文件放到备份路径下,这里备份路径我自定义的/data/gitlab/backups,默认的是/var/opt/gitlab/backups)
[root@code-server backups]# pwd
/data/gitlab/backups
[root@code-server backups]# ll
total 244
-rw-r--r-- 1 git git 245760 Nov 12 15:33 1510472027_2017_11_12_9.4.5_gitlab_backup.tar
  
Gitlab的恢复操作会先将当前所有的数据清空,然后再根据备份数据进行恢复
[root@code-server backups]# gitlab-rake gitlab:backup:restore BACKUP=1510472027_2017_11_12_9.4.5
Unpacking backup ... done
Before restoring the database we recommend removing all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.
  
Do you want to continue (yes/no)?
........
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
WARNING:  no privileges were granted for "public"
GRANT
[DONE]
done
Restoring repositories ...
 * treesign/treesign ... [DONE]
 * gateway/gateway ... [DONE]
 * treesign/treesign-doc ... [DONE]
 * qwsign/qwsign ... [DONE]
 * qwsign/qwsign-doc ... [DONE]
 * test/test ... [DONE]
Put GitLab hooks in repositories dirs [DONE]
done
Restoring uploads ...
done
Restoring builds ...
done
Restoring artifacts ...
done
Restoring pages ...
done
Restoring lfs objects ...
done
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
Do you want to continue (yes/no)? yes
  
  
Deleting tmp directories ... done
done
done
done
done
done
done
done
[root@code-server backups]#
  
最后再次启动Gitlab
[root@code-server backups]# gitlab-ctl start
ok: run: gitaly: (pid 98087) 2138s
ok: run: gitlab-monitor: (pid 98101) 2138s
ok: run: gitlab-workhorse: (pid 98104) 2137s
ok: run: logrotate: (pid 98117) 2137s
ok: run: nginx: (pid 98123) 2136s
ok: run: node-exporter: (pid 98167) 2136s
ok: run: postgres-exporter: (pid 98173) 2136s
ok: run: postgresql: (pid 98179) 2135s
ok: run: prometheus: (pid 98187) 2135s
ok: run: redis: (pid 98230) 2134s
ok: run: redis-exporter: (pid 98234) 2134s
ok: run: sidekiq: (pid 104494) 0s
ok: run: unicorn: (pid 104497) 1s
[root@code-server backups]# gitlab-ctl status
run: gitaly: (pid 98087) 2142s; run: log: (pid 194202) 163262s
run: gitlab-monitor: (pid 98101) 2142s; run: log: (pid 194363) 163261s
run: gitlab-workhorse: (pid 98104) 2141s; run: log: (pid 194362) 163261s
run: logrotate: (pid 98117) 2141s; run: log: (pid 5793) 161091s
run: nginx: (pid 98123) 2140s; run: log: (pid 194359) 163261s
run: node-exporter: (pid 98167) 2140s; run: log: (pid 194360) 163261s
run: postgres-exporter: (pid 98173) 2140s; run: log: (pid 194204) 163262s
run: postgresql: (pid 98179) 2139s; run: log: (pid 194365) 163261s
run: prometheus: (pid 98187) 2139s; run: log: (pid 194364) 163261s
run: redis: (pid 98230) 2138s; run: log: (pid 194358) 163261s
run: redis-exporter: (pid 98234) 2138s; run: log: (pid 194208) 163262s
run: sidekiq: (pid 104494) 4s; run: log: (pid 194437) 163260s
run: unicorn: (pid 104497) 4s; run: log: (pid 194443) 163260s
 
恢复命令完成后,可以check检查一下恢复情况
[root@code-server backups]# gitlab-rake gitlab:check SANITIZE=true
Checking GitLab Shell ...
 
GitLab Shell version >= 5.3.1 ? ... OK (5.3.1)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
5/1 ... ok
6/2 ... ok
5/3 ... repository is empty
12/4 ... ok
12/5 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK
Send ping to redis server: OK
gitlab-shell self-check successful
 
Checking GitLab Shell ... Finished
 
Checking Sidekiq ...
 
Running? ... yes
Number of Sidekiq processes ... 1
 
Checking Sidekiq ... Finished
 
Checking Reply by email ...
 
Reply by email is disabled in config/gitlab.yml
 
Checking Reply by email ... Finished
 
Checking LDAP ...
 
LDAP is disabled in config/gitlab.yml
 
Checking LDAP ... Finished
 
Checking GitLab ...
 
Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ...
5/1 ... yes
6/2 ... yes
5/3 ... yes
12/4 ... yes
12/5 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.3 ? ... yes (2.3.3)
Git version >= 2.7.3 ? ... yes (2.13.4)
Active users: ... 11
 
Checking GitLab ... Finished
  
然后稍等一会(如果启动gitlab后,访问出现500,这是因为redis等程序还没完全启动,等一会儿访问就ok了),再次登录Gitlab,就会发现之前误删除的test项目已经恢复了!
  
另外:Gitlab迁移与恢复一样,但是要求两个GitLab版本号一致
注意:环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出

https://www.cnblogs.com/kevingrace/p/7821529.html

 

https://www.cnblogs.com/zhangycun/p/10312909.html

https://zhuanlan.zhihu.com/p/62042884

https://www.jianshu.com/p/fcba3326c125

 http://www.senra.me/build-your-own-cloud-storage-series-seafile-focus-on-storage-support-ceph/

https://mirrors.tuna.tsinghua.edu.cn/help/gitlab-ce/

https://www.jianshu.com/p/aec2fcb88f6f

clone域名

https://blog.csdn.net/yulei_qq/article/details/53134654?utm_source=blogxgwz1

开发者无法push

https://www.cnblogs.com/xxcanghai/p/5009926.html

使用GITLAB

https://blog.csdn.net/zangxueyuan88/article/details/81032764

原文地址:https://www.cnblogs.com/flyflit/p/13056514.html