简单说明:
依据《CentOS7实验机模板搭建部署》克隆实验机,并进一步配置主机名和hosts文件:
HOSTNAME=gitlab
hostnamectl set-hostname "$HOSTNAME"
echo "$HOSTNAME">/etc/hostname
echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts
echo "$(ip a|grep "inet "|grep -v 127|awk -F'[ /]' '{print $6}') $HOSTNAME">>/etc/hosts
安装部署:
使用清华镜像源安装gitlab
不建议安装最新版本的gitlab,汉化时可能会失败
下载地址 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
当前最新版本为:gitlab-ce-10.8.1-ce.0.el7.x86_64.rpm
建议安装上一个版本:gitlab-ce-10.7.4-ce.0.el7.x86_64.rpm
# 将rpm包下载到本地,本地安装
yum -y localinstall gitlab-ce-10.7.4-ce.0.el7.x86_64.rpm
# 安装后首次配置并启动,首次配置耗时较长,配置后自动启动
gitlab-ctl reconfigure
gitlab-ctl status|column -t
# 设置开机启动,安装后必须进行首次配置,否则无法设置开机启动
systemctl is-enabled gitlab-runsvdir.service
# 也可以下载yum配置文件,使用yum从官网地址安装
# curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
# yum install -y gitlab-ee
相关配置:
1° 配置URL地址:
sed -i "s|http://gitlab.example.com|http://$(hostname -i)|g" /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure
gitlab-ctl restart
# 使用浏览器,打开 http://gitlab主机IP 进行配置
# 第一次访问会要求重置root密码,必须是一个强密码
# 配置后退出登录
2° 汉化:
# 查看安装的gitlab版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
head -1 /opt/gitlab/version-manifest.txt
# 安装git客户端
yum -y install git
# 使用git下载中文包
cd /tmp/
VERSION=v$(cat /opt/gitlab/embedded/service/gitlab-rails/VERSION)
ZH_VERSION=v$(cat /opt/gitlab/embedded/service/gitlab-rails/VERSION)-zh
git clone https://gitlab.com/xhang/gitlab.git -b ${ZH_VERSION}
# 关闭gitlab
gitlab-ctl stop
# 获取最新版本到本地
cd gitlab
git fetch
# 对比英文版和中文版差异,保存到文件中
git diff ${VERSION} ${ZH_VERSION}>/tmp/a.diff
# 安装patch命令
yum -y install patch
# 根据版本差异打patch,如果版本太新,有可能报错找不到文件
patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < /tmp/a.diff
# 重新配置gitlab并启动
gitlab-ctl reconfigure
gitlab-ctl start
# 汉化后,明显感觉重启或者重新配置变慢了,使用命令监控日志
gitlab-ctl tail unicorn
3° 关闭注册,新用户只能由管理员生成:
“管理区域”——>”设置”——>”Sign-up restrictions”展开——>勾掉”Sign-up enabled”——>”Save”
退出后再次登录,已经没有用户注册标签页了
4° 设置邮件发送功能,如新建用户时发送激活邮件:
成功设置了126邮箱,QQ邮箱没有成功
# 设置126邮箱发送邮件
cat >>/etc/gitlab/gitlab.rb<<EOF
# mail alert setup
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = 'smtp.126.com'
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = '[email protected]'
gitlab_rails['smtp_password'] = 'xxxx'
gitlab_rails['smtp_authentication'] = 'login'
gitlab_rails['smtp_enable_starttls_auto']= true
gitlab_rails['gitlab_email_from']= '[email protected]'
gitlab_rails['gitlab_email_reply_to']= '[email protected]'
EOF
gitlab-ctl reconfigure
# 配置调试命令:
gitlab-rails console production
ActionMailer::Base.delivery_method
ActionMailer::Base.smtp_settings
Notify.test_email('[email protected]', '搭建测试', '测试邮件').deliver_now
exit
# 测试
CMD="Notify.test_email('[email protected]', '搭建测试', '测试邮件').deliver_now"
echo ${CMD}|gitlab-rails console
GitLab备份恢复:
# 配置备份留存时间604800秒,即7天
sed -i "s/^.*backup_keep_time.*$/gitlab_rails['backup_keep_time'] = 604800/g" /etc/gitlab/gitlab.rb
# 备份命令
/opt/gitlab/bin/gitlab-rake gitlab:backup:create
# 自动备份任务
crontab -l>/tmp/crontab.tmp
echo '# GitLab Backup Job'>>/tmp/crontab.tmp
echo '30 0 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create'>>/tmp/crontab.tmp
cat /tmp/crontab.tmp |crontab
rm -rf /tmp/crontab.tmp
# 恢复测试
# 使用备份进行恢复,必须是同一版本的gitlab,否则报错
# 删除git仓库目录下所有代码工程
rm -rf /var/opt/gitlab/git-data/repositories/*
# 停掉相关组件,其他组件保持启动状态
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# 使用备份恢复
cd /var/opt/gitlab/backups
# 比如最新的备份文件为:1527569314_2018_05_29_10.7.4_gitlab_backup.tar
# 该备份文件的前缀是:1527569314_2018_05_29_10.7.4
# 使用前缀进行还原,需要交互输入yes
gitlab-rake gitlab:backup:restore BACKUP=1527569314_2018_05_29_10.7.4
# 启动
gitlab-ctl start
# 验证恢复
du -sh /var/opt/gitlab/git-data/repositories/*
# 网页登陆验证
简单维护:
# RPM 安装Gitlab的默认位置在/opt下
# 初次配置服务,或者修改配置文件后需要重新配置
gitlab-ctlreconfigure
# 启动服务
gitlab-ctl start
# 停止服务
gitlab-ctl stop
# 重启服务
gitlab-ctl restart
# 状态查看
gitlab-ctl status
#监控unicorn日志
gitlab-ctl tail unicorn
gitlab-ctl tail
# unicorn进程是ruby版本的http server
# 默认监控8080端口,nginx做的是反向代理
ps -ef|grep nginx|grep master
# 参数-p指定了nginx运行的家目录
# 进入该目录的conf子目录可以查看对应的配置文件
# gitlab 相关配置文件:
# gitlab 配置文件 /etc/gitlab/gitlab.rb
# unicorn 配置文件 /var/opt/gitlab/gitlab-rails/etc/unicorn.rb
# nginx 配置文件 /var/opt/gitlab/nginx/conf/gitlab-http.conf
# gitlab 仓库默认位置 /var/opt/gitlab/git-data/repositories
GitLab升级:
小版本升级可以将新的rpm包下载到本地,使用yum命令升级
如 gitlab-ce-10.7.4-ce.0.el7.x86_64.rpm 升级 gitlab-ce-10.8.1-ce.0.el7.x86_64.rpm:
yum -y localupdate gitlab-ce-10.8.1-ce.0.el7.x86_64.rpm
升级后需要重新汉化,最新的版本包可能汉化操作有问题
大版本升级,比如从 8.1.1 升级 10.7.4 建议还是将项目工程重新灌入
[TOC]