之前在本地部署了Docker +Jenkins + Gitlab
,因为博客服务器在香港,直接传输不方便,还通过成都的腾讯云服务器+ Aliyun Code
进行转发,完整的过程参考[腾讯云][阿里云]网站迁移小结
现在打算直接在云服务器上部署Jenkins + Gitlab
,这样的构建逻辑更加直接,能够进一步压缩博客部署过程。Let's go !!!
整体流程 在本地均通过Docker
方式部署Jenkins
和Gitlab
,所以Jenkins
相关的数据保存在Docker Volume
中,Gitlab
相关数据保存在本地。整体实现流程如下:
将本地Jenkins
和Gitlab
数据打包到云服务器并解压 下载Jenkins
和Gitlab
镜像并启动容器 注册SSL
证书,配置Https
连接 设置腾讯云安全组,开放端口 对于Gitlab
来说,其内置了Nginx
,所以提供了相关的SSL
配置参数,直接配置即可;而对于Jenkins
,通过Nginx
反向代理的方式设置SSL
连接
Gitlab 数据迁移 打包本地数据
1 $ tar zcvf /srv/gi tlab gitlab.tar.gz
上传到云服务器
1 $ scp gitlab.tar .gz ubuntu@xxx.xxx .xxx :/home/ubuntu
解压回原位置
1 $ tar zxvf gitlab.tar.gz /srv/
容器服务 下载镜像
1 $ docker pull gitlab/gitlab-ce: latest
Jenkins 数据迁移 备份和还原卷操作,参考[docker volume]创建和管理卷
容器服务 下载镜像
1 $ docker pull jenkins/jenkins: latest
容器部署 通过docker-compose
方式编排容器Jenkins、Gitlab和Nginx
SSL 在阿里云下载免费的SSL证书
Gitlab 在gitlab.rb
配置文件中保存相关的Nginx
配置参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 # # # # # nginx['enable' ] = true # nginx['client_max_body_size' ] = '250m' # nginx['redirect_http_to_https' ] = false # nginx['redirect_http_to_https_port' ] = 80 # # nginx['ssl_client_certificate' ] = "/etc/gitlab/ssl/ca.crt" # # nginx['ssl_verify_client' ] = "off" # # nginx['ssl_verify_depth' ] = "1" # nginx['ssl_certificate' ] = "/etc/gitlab/ssl/#{node['fqdn']}.crt" # nginx['ssl_certificate_key' ] = "/etc/gitlab/ssl/#{node['fqdn']}.key" # nginx['ssl_ciphers' ] = "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256" # nginx['ssl_prefer_server_ciphers' ] = "on" # # # nginx['ssl_protocols' ] = "TLSv1.2 TLSv1.3" # # nginx['ssl_session_cache' ] = "builtin:1000 shared:SSL:10m" # # nginx['ssl_session_timeout' ] = "5m" ... ... # # # nginx['listen_port' ] = nil
结合在Nginx或Tengine服务器上安装证书 ,完整的配置参数如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 external_url 'https://xxx.xxx.xxx:7010' # 当前访问地址 gitlab_rails['gitlab_shell_ssh_port' ] = 7020 # SSH 监听端口 unicorn['listen' ] = 'localhost' unicorn['port' ] = 8999 nginx['listen_port' ] = 7010 # Https 监听端口 nginx['enable' ] = true nginx['ssl_certificate' ] = "/etc/gitlab/ssl/gitlab.pem" # SSL 证书配置 nginx['ssl_certificate_key' ] = "/etc/gitlab/ssl/gitlab.key" nginx['ssl_ciphers' ] = "ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4" nginx['ssl_prefer_server_ciphers' ] = "on" nginx['ssl_protocols' ] = "TLSv1 TLSv1.1 TLSv1.2" nginx['ssl_session_timeout' ] = "5m"
开放了两个端口用于Https
和SSH
连接 ssl_ciphers
具体配置参数需要参考相关文档Jenkins+Nginx 对于Docker Jenkins
本身而言,不需要其他的设置,开放8080
端口即可;其Https
设置通过Docker Nginx
完成
其配置文件如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 $ cat jenkins.conf server { listen 7700 ssl; server_name xxx.xxx.xxx; ssl_certificate cert/jenkins.pem; ssl_certificate_key cert/jenkins.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE :ECDH :AES :HIGH :!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { proxy_set _header X-Rea $remote_addr; proxy_set _header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set _header Host $http_host; proxy_set _header X-Nginx-Proxy true ; proxy_pass http://xxx.xxx.xxx :7070 ; proxy_set _header X-Forwarded-Proto $scheme; } }
设置Nginx
发布的端口 配置相关SSL
参数 通过内网地址转发到jenkins
docker-compose 使用了两个docker-compose.yml
,一个用于启动Jenkins + Gitlab
,另一个用于启动Nginx
Jenkins + Gitlab 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 $ cat docker-compose.yml version: "3.7" services: jenkins: labels: AUTHOR: "zhujian <zjzstu@github.com>" container_name: jenkins user: jenkins image: jenkins/jenkins volumes: - "jenkins_home:/var/jenkins_home" ports: - "7070:8080" - "50000:50000" restart: always tty: true stdin_open: true gitlab: labels: AUTHOR: "zhujian <zjzstu@github.com>" container_name: gitlab image: gitlab/gitlab-ce:latest volumes: - "/srv/gitlab/config:/etc/gitlab" - "/srv/gitlab/logs:/var/log/gitlab" - "/srv/gitlab/data:/var/opt/gitlab" ports: - "7000:7000" - "7010:7010" - "7020:22" restart: always tty: true stdin_open: truevolumes: jenkins_home: external: true
Nginx 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 $ cat docker-compose.yml version: "3" services: nginx: container_name: nginx image: nginx ports: - "7700:7700" volumes: - "~/software/nginx/cert:/etc/nginx/cert" - "~/software/nginx/www:/opt/www" - "~/software/nginx/logs:/var/log/nginx" - "~/software/nginx/conf.d:/etc/nginx/conf.d" - "~/software/nginx/nginx.conf:/etc/nginx/nginx.conf" restart: always
安全组 最后还需要去腾讯云服务器的安全组中开放相应的端口号
博客部署 之前因为备案的关系,将博客服务器迁到香港;又因为墙的关系,在本地编译完成后,将文件上传到Aliyun Code
,然后通过腾讯云服务器发送提醒消息给博客服务器,博客服务器再从远程仓库中下载相应的文件,完成更新
现在因为部署在了云服务器上,所以完成后可以直接传输提醒消息给博客服务器了
问题 Jenkins Gitlab 相关阅读