CentOS7.6系统安装及配置 GitLab-ce-11.7.6

1. 安装依赖软件

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

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

systemctl enable postfix && systemctl start postfix

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

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

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

下载rpm包并安装:

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.7.6-ce.0.el7.x86_64.rpm
rpm -ivh gitlab-ce-11.7.6-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-11.7.6-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:gitlab-ce-11.7.6-ce.0.el7        ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  
B

     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  
B
Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

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

vim /etc/gitlab/gitlab.rb

# gitlab服务器地址+端口
external_url 'http://gitlab.example.com'
# 改成:
external_url 'http://10.200.117.79:9000'

# 重置并启动GitLab,执行:
gitlab-ctl reconfigure
gitlab-ctl restart

5.gitlab备份恢复

5.1 修改gitlab备份路径

vim /etc/gitlab/gitlab.rb
# gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
gitlab_rails['backup_path'] = '/mnt/backups'

#修改完成之后使用下面命令重载配置文件即可.
gitlab-ctl reconfigure

5.2 Gitlab自动备份

定时自动备份
m h dom mon dow user command
解释:
- m: 表示分钟,可以是从0到59之间的任何整数。
- h:表示小时,可以是从0到23之间的任何整数。
- dom:表示日期,可以是从1到31之间的任何整数。
- mon:表示月份,可以是从1到12之间的任何整数。
- dow:表示星期几,可以是从0到7之间的任何整数,这里的0或7代表星期日。
- user : 表示执行的用户。
- command:要执行的命令,可以是系统命令,也可以是自己编写的脚本文件(如shell文件)。

 

实现每天凌晨2点进行一次自动备份:通过crontab使用备份命令实现,需重启cron服务
方法1、在命令行输入: crontab -e 然后添加相应的任务,wq存盘退出。
#输入命令crontab -e
crontab -e
#输入相应的任务
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1

方法2、直接编辑/etc/crontab 文件,即vi /etc/crontab,然后添加相应的任务

#编辑 /etc/crontab
vi /etc/crontab 
# 然后再编辑框内输入相应的任务

# edited by ouyang 2017-8-11 添加定时任务,每天凌晨两点,执行gitlab备份
0  2    * * *   root    /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1

5.3 设置备份过期时间

设置只保存最近7天的备份,编辑 /etc/gitlab/gitlab.rb 配置文件,找到gitlab_rails[‘backup_keep_time’],设置为你想要设置的值,然后保存。

gitlab_rails['backup_keep_time'] = 604800

6. Gitlab备份迁移

copy老服务器上面的备份文件到新服务器,确保新Gitlab服务器和老Gitlab服务器版本相同。

  • 第一步,新服务器上的Gitlab的版本必须与创建备份时的Gitlab版本号相同. 比如新服务器安装的是最新的9.4.3版本的Gitlab, 那么迁移之前, 最好将老服务器的Gitlab 升级为9.4.3再进行备份.
  • copy老服务器上面的备份文件到新服务器
  • 第二步,如果你没修改过默认备份目录的话,需要将老服务器上的备份文件目录(/var/opt/gitlab/backups目录)下的备份文件拷贝到新服务器上的/var/opt/gitlab/backups目录。
  • 使用scp命令从远程服务器copy文件或者目录到本地

scp 用户名 @IP 地址 : 文件名 1 远程用户名 @IP 地址 : 文件名 2
如:
scp root@172.28.17.155:/var/opt/gitlab/backups/1502357536_2017_08_10_9.4.3_gitlab_backup.tar /var/opt/gitlab/backups/

从备份文件中恢复gitlab

  • 第一步,将备份文件权限修改为777,不然可能恢复的时候会出现权限不够,不能解压的问题。
  • chmod 777 1502357536_2017_08_10_9.4.3_gitlab_backup.tar
  • 第二步,执行命令停止相关数据连接服务
  • # 停止相关数据连接服务
    gitlab-ctl stop unicorn
    gitlab-ctl stop sidekiq

  • 第三步,执行命令从备份文件中恢复Gitlab
  • gitlab-rake gitlab:backup:restore BACKUP=备份文件编号
    例如我们的备份文件的编号是1502357536_2017_08_10_9.4.3,因此执行下面的命令即可恢复gitlab

  • gitlab-rake gitlab:backup:restore BACKUP=1502357536_2017_08_10_9.4.3
  • 敲完命令后,出现第一个交互页面,如下

root@ubuntu4146:/var/opt/gitlab/backups# gitlab-rake gitlab:backup:restore BACKUP=1502357536_2017_08_10_9.4.3
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)?
输入“yes”继续。

出现第二个交互页面,

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”继续。

  • 第四步,启动Gitlab
  • sudo gitlab-ctl start

打开迁移后的Gitlab,进行对比
对比,可以发现,除了两台服务器的ip地址不一样之外,其他的内容完全一模一样,迁移成功!

备份、恢复及数据迁移
参考文档:https://blog.csdn.net/ouyang_peng/article/details/77070977

gitlab关闭注册功能

git管理员
root/Miaocbin@132

Gitlab配置SMTP服务器

编辑配置文件: /etc/gitlab/gitlab.rb
在mail配置下面,增加配置:

### Email Settings
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "mail.geely.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "thunbu"
gitlab_rails['smtp_password'] = "JKHsaeA234#@$"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'changbin.miao@geely.com'
gitlab_rails['smtp_domain'] = "geely.com"

触发配置生效
gitlab-ctl reconfigure

测试SMTP配置

gitlab-rails console
# liuri@lemonit.cn换成你要实际发送测试邮件的目标邮箱地址
Notify.test_email('liuri@lemonit.cn', 'LemonITCN', 'LemonITCN').deliver_now

官方SMTP配置说明链接:
https://docs.gitlab.com/omnibus/settings/smtp.html

 

GitLab遇到ssh修改了默认端口解决方法

GItLab用ssh免密钥认证确实很好用,只是配置的时候发现修改了ssh默认端口(22),则不可达,不少小伙伴都遇到了这个问题。经过一番思考,觉得需要修改服务端配置,这里把具体写个博客,让大家少点坑。

修改步骤

1、修改ssh端口(此步骤略过)
Port 端口
2、修改/etc/gitlab/gitlab.rb [gitlab.yml中的配置会被这个给覆盖]
//在后面修改自己的ssh端口
gitlab_rails['gitlab_shell_ssh_port'] = 21386
3、使其生效
gitlab-ctl reconfigure
默认是22端口,直接访问则不会出现端口的。)


gitlab默认备份路径:
/var/opt/gitlab/backups
默认备份保存时间:
gitlab_rails['backup_keep_time'] = 604800

 

posted @ 2020-03-13 13:23  冷水泡茶  阅读(539)  评论(0)    收藏  举报