gitlab在centos7.3上搭建
最近接到gitlab+jenkins的任务,由于以前只接触过GitHub,并只是简单的使用,这里简单记录gitlab与jenkins搭建的
环境:
centos 7.3
gitlab version:gitlab-ce-12.0.2-ce.0.el7.x86_64
1 安装
# vim /etc/selinux/config SELINUX=disabled # setenforce 0 # getenforce sudo yum install curl policycoreutils openssh-server openssh-clients git -y sudo systemctl enable sshd sudo systemctl start sshd sudo yum install postfix -y sudo systemctl enable postfix sudo systemctl start postfix sudo firewall-cmd --permanent --add-service=http sudo systemctl reload firewalld
新建 /etc/yum.repos.d/gitlab-ce.repo,内容为 ##选择国内的清华的镜像
[gitlab-ce] name=Gitlab CE Repository baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/ gpgcheck=0 enabled=1
sudo yum makecache sudo yum install gitlab-ce [root@localhost home]# mkdir -p /home/data/gitlab_data [root@localhost home]# mkdir -p /home/data/gitlab_backups [root@localhost home]# vim /etc/gitlab/gitlab.rb external_url 'http://192.168.*' git_data_dirs = "/home/data/gitlab_data" gitlab_rails['backup_path'] = "/home/data/gitlab_backups" [root@localhost home]# gitlab-ctl reconfigure Running handlers: Running handlers complete Chef Client finished, 512/1343 resources updated in 03 minutes 10 seconds gitlab Reconfigured! [root@localhost ~]# gitlab-ctl start ok: run: alertmanager: (pid 15250) 226s ok: run: gitaly: (pid 15061) 229s ok: run: gitlab-monitor: (pid 15128) 228s ok: run: gitlab-workhorse: (pid 15087) 229s ok: run: grafana: (pid 15282) 225s ok: run: logrotate: (pid 14464) 300s ok: run: nginx: (pid 14376) 306s ok: run: node-exporter: (pid 15117) 228s ok: run: postgres-exporter: (pid 15270) 226s ok: run: postgresql: (pid 14049) 355s ok: run: prometheus: (pid 15226) 227s ok: run: redis: (pid 13835) 367s ok: run: redis-exporter: (pid 15135) 227s ok: run: sidekiq: (pid 14268) 318s ok: run: unicorn: (pid 14227) 324s [root@localhost ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION 12.0.2 [root@localhost gitlab_backups]# rpm -qa|grep gitlab gitlab-ce-12.0.2-ce.0.el7.x86_64 [root@gitlab ~]# cd /var/log/gitlab/ [root@gitlab gitlab]# ll total 12 drwx------. 2 gitlab-prometheus root 95 Jul 4 17:00 alertmanager drwx------. 2 git root 235 Jul 8 16:58 gitaly drwx------. 2 git root 95 Jul 4 17:00 gitlab-monitor drwx------. 2 git root 4096 Jul 9 00:43 gitlab-rails drwx------. 2 git root 204 Jul 9 00:43 gitlab-shell drwx------. 2 git root 165 Jul 8 16:59 gitlab-workhorse drwx------. 2 gitlab-prometheus root 95 Jul 4 17:00 grafana drwx------. 2 root root 95 Jul 4 16:59 logrotate drwxr-x---. 2 root gitlab-www 4096 Jul 9 00:43 nginx drwx------. 2 gitlab-prometheus root 95 Jul 4 17:00 node-exporter drwx------. 2 gitlab-psql root 95 Jul 4 17:00 postgres-exporter drwx------. 2 gitlab-psql root 95 Jul 4 16:59 postgresql drwx------. 2 gitlab-prometheus root 235 Jul 8 17:00 prometheus drwxr-xr-x. 2 root root 116 Jul 4 09:33 reconfigure drwx------. 2 gitlab-redis root 235 Jul 8 16:58 redis drwx------. 2 gitlab-redis root 95 Jul 4 17:00 redis-exporter drwx------. 2 git root 235 Jul 8 16:59 sidekiq drwx------. 2 git root 4096 Jul 9 00:43 unicorn
修改存储路径
git_data_dirs({ "default" => { "path" => "目标路径" } }) gitlab-ctl reconfigure gitlab-ctl stop rsync -av /var/opt/gitlab/git-data/repositories /home/data/gitlab_data gitlab-ctl upgrade ll /home/data/gitlab_data gitlab-ctl start
gitlab备份
#!/bin/bash clear echo "=========================================================================" echo "linux os gitlab backup ,create by hongquan on 20190709" echo "=========================================================================" echo "" BackDir=/home/data/gitlab_backups ConfigDir=/etc/gitlab/gitlab.rb #NginxDir=/var/opt/gitlab/nginx/conf/ #PostgreSQL=/var/opt/gitlab/postgresql/data #MailDir=/etc/postfix/main.cf curHour=`date +%H` curDate=`date +'%Y%m%d'` logfile=/home/data/gitlab_backups/gitlab_backups.log echo "-----Backup start -------">> ${logfile} if [ ! -d "${BackDir}" ]; then mkdir -p "${BackDir}" echo -e "===${BackDir} does not exsits,created them!" >> ${logfile} fi echo "backup start" `date` >> ${logfile} /bin/cp ${ConfigDir} ${BackDir} >> ${logfile} 2>&1 #/bin/cp -r ${NginxDir} ${BackDir} >> ${logfile} 2>&1 exec gitlab-rake gitlab:backup:create >> ${logfile} 2>&1 if [ $? -eq 0 ];then echo "------------Success!---------" >> ${logfile} echo "Gitlab auto backup end at ${curDate}" >> ${logfile} else echo "------------Failed!----------" >> ${logfile} echo "Gitlab auto backup failed at ${curDate}" >> ${logfile} fi
2 gitlab使用
gitlab跟git的命令都是一样的
3 sourcetree配置