1、基本环境安装,官方有一键安装包,没墙速度慢,使用第三方源
1 vim /etc/yum.repos.d/gitlab-ce.repo 2 [gitlab-ce] 3 name=gitlab-ce 4 baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6 5 repo_gpgcheck=0 6 gpgcheck=0 7 enabled=1 8 gpgkey=https://packages.gitlab.com/gpg.key
2、安装最新版本或指定版本
1 yum -y install gitlab-ce 2 yum -y install gitlab-ce-9.0.5
3、修改默认访问方式以及代码仓库存放位置
1 external_url 'http://git.xxxxx.com' 2 git_data_dirs({ "default" => { "path" => "/data/gitlab/git-data" } })
4、配置并启动Gitlab
1 gitlab-ctl reconfigur
5、备份原有Gitlab
1 gitlab-rake gitlab:backup:create 2 # 在docker中运行的gitlab备份 3 docker exec -t <container name> gitlab-rake gitlab:backup:create 4 # 默认会在/var/opt/gitlab/backups/下创建个tar压缩包
6、开始在新服务器上恢复,服务必须为开启状态
1 gitlab-rake gitlab:backup:restore BACKUP=1499310760_2017_07_06_gitlab_backup.tar
7、添加 Webhook
1 项目分支的setting--->integrations,配置url,和token 2 # url:web服务器下的脚本,当gitlab检测到有push操作之后,访问该url,触发后执行git pull操作 3 例如:http://my.example.com/script/script.php;脚本内容如下 4 <?php 5 //git webhook 自动部署脚本 6 $path = "/datas/wwwroot/my.test.com/"; //项目路径 7 $requestBody = file_get_contents("php://input"); 8 if (empty($requestBody)) { 9 die('send fail'); 10 } 11 $content = json_decode($requestBody, true); 12 //若是主分支且提交数大于0 13 if ($content['ref']=='refs/heads/master' && $content['total_commits_count']>0) { 14 $res = shell_exec("cd {$path} && git pull 2>&1");//以www用户运行 15 $res_log = '-------------------------'.PHP_EOL; 16 $res_log .= $content['user_name'] . ' 在' . date('Y-m-d H:i:s') . '向' . $content['repository']['name'] . '项目的' . $content['ref'] . '分支push了' . $content['total_commits_count'] . '个commit:' . PHP_EOL; 17 $res_log .= $res.PHP_EOL; 18 file_put_contents("git-webhook.txt", $res_log, FILE_APPEND);//追加写入 19 }
8、nginx配置
1 server{ 2 listen 81; 3 4 server_name my.example.com; 5 root /datas/wwwroot/script; 6 index index.html; 7 8 location ~ \.php$ { 9 fastcgi_pass unix:/service/webserver/php5.6.10/var/tmp/php.sock; 10 fastcgi_index index.php; 11 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 12 include fastcgi_params; 13 try_files $uri $uri/ =404; 14 } 15 }