一、软件包获取

查看 gitlab 包列表

二、环境说明

三、开始安装

安装对应的环境依赖

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

如果没有安装上面的包会报如下错误

warning: gitlab-ce-14.2.1-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY error: Failed dependencies: policycoreutils-python is needed by gitlab-ce-14.2.1-ce.0.el7.x86_64

正式执行 gitlab 的 yum 安装命令

sudo yum install gitlab-ce-14.2.1-ce.0.el7.x86_64

安装提示检测到不可用的 hostname
image.png
此时需要修改 gitlab.rb 配置

vi /etc/gitlab/gitlab.rb 
# 把 external_url 参数改成你的域名即可

四、配置说明

/etc/gitlab/gitlab.rb

邮箱信息配置

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.feishu.cn"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "git@xxx"
gitlab_rails['smtp_password'] = "xxx"
gitlab_rails['smtp_domain'] = "smtp.feishu.cn"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

LDAP 对接公司统一登录

label: 'xxx-LDAP'
     host: 'ldap.xx.xx'
     port: 10389
     uid: 'uid'
     bind_dn: 'cn=gitlabac,ou=servers,dc=xx,dc=xx'
     password: 'xx'

备份路径设置

gitlab_rails['backup_path'] = '/data/xxx/backups'

git 数据目录指定

 git_data_dirs({
   "default" => {
     "path" => "/data/xxx/git-data"
    }
 })

服务域名设置

external_url 'http://git.xxx.xxx'

五、常用命令

查看状态

gitlab-ctl status

修改配置加载

gitlab-ctl reconfigure

重启

gitlab-ctl restart

停止

gitlab-ctl stop

六、常见后端管理配置

七、备份

linux 系统设置 cron 定时器

# vi /var/spool/cron/root
05 0 * * * /data/scripts/BackupGitlab.sh >/dev/null 2>&1

定时脚本 BackupGitlab.sh

#!/bin/bash

riqi=`date +%Y%m%d`
log_file="/data/scripts/Gitlab_Backup_log.txt"
gitlabetc="/etc/gitlab"
key="/var/opt/gitlab/.ssh/authorized_keys"
backupsdir="/data/moboxgit/backups"

echo "Start (gitlab:backup:create) Time:" >> $log_file
date >> $log_file
echo "" >> $log_file

#gitlab-rake gitlab:backup:create RAILS_ENV=production >> $log_file
gitlab-backup create SKIP=artifacts >> $log_file

cp -rp $gitlabetc/gitlab.rb           $backupsdir/gitlab.rb_$riqi
cp -rp $gitlabetc/gitlab-secrets.json $backupsdir/gitlab-secrets.json_$riqi
cp -rp $key                           $backupsdir/authorized_keys_$riqi
echo "" >> $log_file
echo "End (gitlab:backup:create) Time:" >> $log_file
date >> $log_file
echo "-----------------------------" >> $log_file
echo "" >> $log_file

#only save 7 days backup files
cd $backupsdir
ls -alc $backupsdir | grep gitlab_backup.tar   | head -n -7 | awk -F " " '{print $9}' | xargs rm -f
ls -alc $backupsdir | grep gitlab-secrets.json | head -n -7 | awk -F " " '{print $9}' | xargs rm -f
ls -alc $backupsdir | grep authorized_keys     | head -n -7 | awk -F " " '{print $9}' | xargs rm -f
ls -alc $backupsdir | grep gitlab.rb           | head -n -7 | awk -F " " '{print $9}' | xargs rm -f
cd -

echo "-----------------------------" >> $log_file
echo "" >> $log_file

点赞(5) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部