gitlab服务搭建

centos下搭建

1. 关闭Selinux

vim /etc/selinux/config

SELINUX=enforcing //把enforcing改为disabled

重启计算机生效配置

reboot

2. 添加镜像地址(使用国内源)

vim /etc/yum.repos.d/gitlab-ce.repo

粘贴如下内容:

[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key

3. 安装依赖

安装和配置openssh

yum -y install curl policycoreutils-python openssh-server openssh-clients

4. 下载gitlab-ce,版本:10.8.7

查看gitlab都有哪些版本:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

下载版本:

curl -LJO https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.10.11-ce.0.el7.x86_64.rpm

5. 安装gitlab-ce

rpm -i gitlab-ce-12.10.11-ce.0.el7.x86_64.rpm

安装完删除安装包:

rm -f gitlab-ce-12.10.11-ce.0.el7.x86_64.rpm

6. 关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

7. gitlab配置

vim /etc/gitlab/gitlab.rb

修改external_url

external_url 'http://47.75.147.153:8080

8. 对gitlab执行配置,时间比较长

gitlab-ctl reconfigure

9. 启动gitlab

gitlab-ctl start

10. 打开浏览器访问gitlab

http://47.75.147.153

Ubuntu下搭建

1. 安装配置依赖项

sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates

2. 安装发送邮件

sudo apt-get install -y postfix

3. 下载安装脚本

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

4. 修改安装脚本

sudo vim /etc/apt/sources.list.d/gitlab_gitlab-ce.list

把原来的两行删除或者注释(#是行注释),然后增加

deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu bionic main
deb-src https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu bionic main

5. 再次执行

sudo apt-get update

6. 执行安装脚本

sudo apt-get install gitlab-ce=12.10.11-ce.0

7. gitlab配置

sudo vim /etc/gitlab/gitlab.rb

修改external_url

external_url 'http://47.75.147.153:8080'

8. 开启端口号防火墙

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

9. 对gitlab执行配置,时间比较长

sudo gitlab-ctl reconfigure

10. 启动gitlab

sudo gitlab-ctl start

11. 打开浏览器访问gitlab

http://47.75.147.153

发送邮件配置(以阿里企业邮箱为例)

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

systemctl enable postfix && systemctl start postfix

2. 编辑配置文件

sudo vim /etc/gitlab/gitlab.rb

配置邮箱

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qiye.aliyun.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]"    #发送方邮箱账号
gitlab_rails['smtp_password'] = "xxxxxxx     #发送方邮箱密码
gitlab_rails['smtp_domain'] = "smtp.mxhichina.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'
user['git_user_email'] = "[email protected]"
user['git_user_name'] = "GitLab系统邮件"

3. 执行重新配置命令

gitlab-ctl reconfigure

4. 重启服务

gitlab-ctl restart

5. 测试发送邮件能否成功

进入gitlab控制台:

gitlab-rails console

执行这条命令给自己发送邮件:

Notify.test_email('[email protected]', 'Test123Title', 'Test123Body').deliver_now

定时备份

1. GITLAB备份参数设置

vim /etc/gitlab/gitlab.rb

gitlab_rails['manage_backup_path']=true
gitlab_rails['backup_path']="/var/opt/gitlab/backups"  #gitlab备份目录
gitlab_rails['backup_archive_permissions']=0644    #生成的备份文件权限
gitlab_rails['backup_keep_time'] = 7776000       #备份保留天数,秒计算,这里是90天

2. 设置备份目录权限

chmod -R 777 /var/opt/gitlab/backups

3. 执行重新配置命令

gitlab-ctl reconfigure

4. 创建定时任务

crontab -e

输入:每天晚上1点开始备份

0 1 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

查看定时任务:

crontab -l

5. 重启cron

centos:

sudo systemctl restart crond

ubuntu:

sudo service cron restart

数据恢复

1. 将备份的文件拷贝至:/var/opt/gitlab/backups

2. 执行命令停止相关数据连接服务

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

3. 执行恢复命令

gitlab-rake gitlab:backup:restore BACKUP=1565599695_2019_08_12_10.8.7

指令执行过程中有两次交互,都输入yes即可。

4. 最后重启gitlab

gitlab-ctl restart

你可能感兴趣的:(gitlab服务搭建)