临时笔记,以后会整理成详细文案
#新建项目路径
cd /var/opt/gitlab/git-data/repositories/root/
#配置yum源
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
#安装依赖
yum -y install curl openssh-server openssh-clients postfix cronie
#service postfix start
#chkconfig postfix on
#这句是用来做防火墙的,避免用户通过ssh方式和http来访问。
#lokkit -s http -s ssh
yum -y makecache
yum -y install gitlab-ce
gitlab-ctl reconfigure # Configure and start GitLab
#配置域名
vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
# 外网访问的端口,如果服务器已经有服务器占用了80,那么这里可以改成其它
listen *:8888;
server_name gitlab.test.domain.com;
set $http_host_with_default "gitlab.test.domain.com:8088";
#补充说明:因为编译gitlab的配置 /etc/gitlab/gitlab.rb 时会重新生成这个自定义nginx 配置,所以只要 gitlab 的配置配得好,上面的nginx其实不需要自定义的。
#修改密码
gitlab-rails console production
user = User.where(id:1).first
user.password='xhh123456'
user.save!
user = User.all #查看所有用户
#gitlab配置文件
vim /etc/gitlab/gitlab.rb
#外部访问url(经过编译后,自动将这个配置编译到nginx配置,nginx就无需配置了)
external_url 'http://gitlab.test.domain.com:8088' #ip访问502,修改此处
#默认值就是8080。如果端口被占用,可将8080修改为其它(例如:9090)
unicorn['port'] = 8080
#使配置生效
gitlab-ctl reconfigure
#重新启动GitLab
gitlab-ctl restart
#连接测试
ssh -T git@localhost
#备份
# 可以将此命令写入crontab,以实现定时备份
#备份的数据会存储在/var/opt/gitlab/backups,用户通过自定义参数 gitlab_rails['backup_path'],改变默认值。
/usr/bin/gitlab-rake gitlab:backup:create
ll -s /var/opt/gitlab/backups
1559704063_2019_06_05_11.11.1_gitlab_backup.tar
#恢复
# 停止unicorn和sidekiq,保证数据库没有新的连接,不会有写数据情况
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# 进入备份目录进行恢复,1476900742为备份文件的时间戳
cd /var/opt/gitlab/backups
gitlab-rake gitlab:backup:restore BACKUP=1559704063
cd -
# 启动unicorn和sidekiq
gitlab-ctl start unicorn
gitlab-ctl start sidekiq
#gitlab发送邮件配置
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = “smtp.exmail.qq.com”
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = “huangdc@domain.com“
gitlab_rails['smtp_password'] = "smtp password"
gitlab_rails['smtp_authentication']= 'plain"
gitlab_rails['smtp_enable_starttls_auto']= true
gitlab_rails['gitlab_email_from']= 'huangdc@domain.com'
gitlab_rails['gitlab_email_reply_to']= ‘noreply@domain.com'
#服务器修改过ssh端口的坑(需要修改配置ssh端口)
#修改过ssh端口,gitlab中项目的的ssh地址,会在前面加上协议头和端口号“ssh://git@gitlab.domain.com:55725/huangdc/test.git”
#gitlab_rails['gitlab_shell_ssh_port'] = 8082
#GitLab常用命令
gitlab-ctl start # 启动所有 gitlab 组件;
gitlab-ctl stop # 停止所有 gitlab 组件;
gitlab-ctl restart # 重启所有 gitlab 组件;
gitlab-ctl status # 查看服务状态;
vim /etc/gitlab/gitlab.rb # 修改gitlab配置文件;
gitlab-ctl reconfigure # 每次重新配置,都需要执行
#注意:执行 reconfigure 命令会把gitlab的nginx组件的配置还原,导致自定义修改的端口以及域名等都没有了。
gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab;
gitlab-ctl tail # 查看日志;
gitlab-ctl tail nginx/gitlab_access.log
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION # 查看gitlab版本
#常用目录
日志地址:/var/log/gitlab/ # 对应各服务的打印日志
服务地址:/var/opt/gitlab/ # 对应各服务的主目录
原文:https://www.cnblogs.com/orange-lsc/p/11713068.html