gitlab

gitlab安装

配置:2核/2G+

方式方法一:下载gitlab-ce的rpm包
gitlab官方rpm包下载
清华的源

方式二:配置yum源

[root@node2 ~]# vim /etc/yum.repos.d/gitlab.repo
[gitlab-ce]
name=gitlab-ce
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
Repo_gpgcheck=0
Enabled=1
gpgcheck=0
Gpgkey=https://packages.gitlab.com/gpg.key

[root@node2 ~]# yum clean all && yum makecache
[root@node2 ~]# yum -y install gitlab-ce 		===>最新版(会报错)
[root@node2 ~]# yum -y install gitlab-ce-13.6.1	        ===>指定版本
[root@node2 ~]# yum -y install gitlab-ce --nogpgcheck   ===>不检查安装

# 配置gitlab默认配置文件
[root@node2 ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://192.168.1.112'  	===>这里一定要加上http://

==========按需部分=========
配置邮件服务
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "hgzerowzh@qq.com"        # 自己的qq邮箱账号
gitlab_rails['smtp_password'] = "xxx"  			   # 开通smtp时返回的授权码
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"   
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
gitlab_rails['gitlab_email_from'] = "hgzerowzh@qq.com"     # 指定发送邮件的邮箱地址
user["git_user_email"] = "shit@qq.com"                     # 指定接收邮件的邮箱地址
=========================


外网访问的端口,如果服务器已经有服务器占用了80,可将其改成
vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
server {
  listen *:8888;

  server_name gitlab.test.domain.com;

  access_log  /var/log/gitlab/nginx/gitlab_access.log gitlab_access;
  error_log   /var/log/gitlab/nginx/gitlab_error.log;

  if ($http_host = "") {
    set $http_host_with_default "gitlab.test.domain.com:8888";
  }

修改好配置文件后,要使用 gitlab-ctl reconfigure 命令重载一下配置文件,否则不生效
[root@node2 ~]# gitlab-ctl reconfigure 		# 重载配置文件


Gitlab常用命令
# 启停所有 gitlab组件
[root@node2 ~]# gitlab-ctl {start|stop|restart|status} 		
# 启动服务(重新编译gitlab的配置)
[root@node2 ~]# gitlab-ctl reconfigure
# 验证配置文件
[root@node2 ~]# gitlab-ctl show-config   
# 检查gitlab
[root@node2 ~]# gitlab-rake gitlab:check SANITIZE=true --trace    
# 查看日志
[root@node2 ~]# gitlab-ctl tail
gitlab-ctl tail nginx/gitlab_access.log
gitlab-ctl tail nginx/gitlab_error.log


# 常用目录
日志地址:/var/log/gitlab/   # 对应各服务的打印日志 
服务地址:/var/opt/gitlab/   # 对应各服务的主目录 



# 获取首次登陆密码(帐号是root)
[root@node2 ~]# cat /etc/gitlab/initial_root_password | grep ^Password
Password: O49qyh77jH4e4RSwqTEhvh6GP1xKy22ZgpomEuv8zrY=





创建项目(假设项目名叫app01)--->创建组--->创建用户-->添加User到Group中并授权---> |
配置SSH(右上角个人-settings-SSH Keys)--->往项目中添加成员---> |
将本地文件推送到Gitlab--->
# 将app01项目克隆下来
git clone git@192.168.1.112:java/app01.git
# 初始化配置
git config --global user.name "hgzero"
git config --global user.email "hgzero@qq.com"
# 推送到gitlab
git add .
git commit -m "first edition"
git push origin master

GitLab备份和恢复

备份

[root@node2 ~]# vim /etc/gitlab/gitlab.rb
# 备份保存的位置,这里是默认位置,可修改成指定的位置
# gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
# 设置备份保存的时间,超过此时间的日志将会被新覆盖
# gitlab_rails['backup_keep_time'] = 604800		# 这是默认设置,保存7天


如果自定义了备份保存位置,则要修改备份目录的权限,比如:
[root@node2 ~]# chown -R git.git /data/backup/gitlab

# 重读配置文件
gitlab-ctl reconfigure  

# 重启gitlab
gitlab-ctl restart


# 可以将此命令写入crontab,以实现定时备份
[root@node2 ~]# /usr/bin/gitlab-rake gitlab:backup:create
    
设置定时任务
[root@node2 ~]# crontab -e
#每天凌晨2点定时创建备份
0 2 * * * /usr/bin/gitlab-rake gitlab:backup:create		


备份时间的识别
# 备份后的文件类似这样的形式:1494170842_gitlab_backup.tar,可以根据前面的时间戳确认备份生成的时间
[root@node2 ~]# date -d @1494170842
2017年 05月 07日 星期日 11:27:22 EDT

恢复gitlab

# 停止数据写入服务
[root@node2 ~]# gitlab-ctl stop unicorn
[root@node2 ~]# gitlab-ctl stop sidekiq

# 进行恢复
# 下面的时间戳就是刚刚备份的文件前面的时间戳
[root@node2 ~]# gitlab-rake gitlab:backup:restore BACKUP=1494170842  

# 重启
gitlab-ctl restart

服务器修改过ssh端口的坑(需要修改配置ssh端口)
# 如修改了ssh端口,则需在gitlab中配置ssh地址
# gitlab会在前面加上协议头和端口号"ssh://git@gitlab.domain.com:55725/huangdc/test.git"

[root@node2 ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['gitlab_shell_ssh_port'] = 55725
#使配置生效
[root@node2 ~]# gitlab-ctl reconfigure
#重新启动GitLab 
[root@node2 ~]# gitlab-ctl restart

欢迎加入QQ群一起讨论Linux、开源等技术

posted @ 2021-08-15 16:28  Linux大魔王  阅读(49)  评论(0编辑  收藏  举报