doina

一个小菜鸟运维工程师.

Gitlab + Jenkins + Ansible 自动部署 --安装篇

环境:

软件 版本
Java Version 1.8.0_45
Tomcat Version Tomcat/8.5.4
Ansible Version 2.4
GitLab Version 11.1.2
Jenkins Version 2.121.2
操作系统 CentOS 7.3
安装Ansible
[root@deploy ~]# yum -y install ansible
[root@deploy ~]# ansible --version
ansible 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

#优化ansible配置文件
[root@deploy ~]# vim /etc/ansible/ansible.cfg 

1.长连接设置
将
#ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s
修改为
ssh_args = -C -o ControlMaster=auto -o ControlPersist=5d

2.开启pipelining
将
#pipelining = False
修改为
pipelining = True

3.开启缓存 
在 #gathering = implicit 下面追加
gathering = smart
fact_caching_timeout = 86400 
fact_caching = jsonfile 
fact_caching_connection = /tmp/ansible_fact_cache
安装GitLab
#配置yum源
[root@deploy ~]# cat > /etc/yum.repos.d/gitlab-ce.repo << EOF
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el\$releasever/
gpgcheck=0
enabled=1
EOF

#更新yum缓存
[root@deploy ~]# yum clean all
[root@deploy ~]# yum makecache

#安装GitLab依赖包
[root@deploy ~]# yum install -y curl policycoreutils-python openssh-server iptables-services

#安装GitLab,安装过程中会出现下图的图案
[root@deploy ~]# sudo yum -y install gitlab-ce 

《Gitlab + Jenkins + Ansible 自动部署 --安装篇》

配置GitLab
#编辑配置文件
[root@deploy ~]# vim /etc/gitlab/gitlab.rb

#修改访问地址
external_url 'http://10.241.0.1'

#开启备份
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
gitlab_rails['backup_keep_time'] = 604800

#初始化配置,并启动服务
[root@deploy ~]# gitlab-ctl reconfigure

#查看状态
[root@deploy ~]# gitlab-ctl status
run: alertmanager: (pid 22380) 17s; run: log: (pid 22496) 15s
run: gitaly: (pid 22287) 18s; run: log: (pid 22397) 17s
run: gitlab-monitor: (pid 22310) 17s; run: log: (pid 22342) 17s
run: gitlab-workhorse: (pid 22266) 18s; run: log: (pid 22350) 17s
run: logrotate: (pid 21787) 75s; run: log: (pid 22352) 17s
run: nginx: (pid 21754) 77s; run: log: (pid 22351) 17s
run: node-exporter: (pid 22018) 63s; run: log: (pid 22398) 16s
run: postgres-exporter: (pid 22406) 16s; run: log: (pid 22498) 15s
run: postgresql: (pid 21475) 127s; run: log: (pid 22313) 17s
run: prometheus: (pid 22353) 17s; run: log: (pid 22373) 17s
run: redis: (pid 21415) 133s; run: log: (pid 22312) 17s
run: redis-exporter: (pid 22054) 51s; run: log: (pid 22343) 17s
run: sidekiq: (pid 21718) 84s; run: log: (pid 22315) 17s
run: unicorn: (pid 22511) 12s; run: log: (pid 22314) 17s

#查看gitlab版本号
[root@deploy ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
11.1.2

#开启防火墙
[root@deploy ~]# systemctl  stop firewalld 
[root@deploy ~]# systemctl  disable firewalld 
[root@deploy ~]# systemctl  start iptables
[root@deploy ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@deploy ~]# service  iptables save          
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

#访问gitlab, 第一次登陆会要求设置密码
浏览器打开 http://10.241.0.1
汉化Gitlab,可省略
#安装git
[root@deploy ~]# yum install -y git

#下载相同版本的汉化补丁,和gitlab版本保持一致
[root@deploy ~]# git clone https://gitlab.com/xhang/gitlab.git gitlab-cn -b v11.1.2-zh

#查看该汉化补丁的版本
[root@deploy ~]# cat gitlab/VERSION
11.1.2

停止gitlab服务
[root@deploy ~]# gitlab-ctl stop

#切换到gitlab汉化包所在的目录(即步骤二获取的汉化版gitlab) 
[root@deploy ~]# cd gitlab-cn

#比较汉化标签和原标签,导出 patch 用的 diff 文件到/root下 
[root@deploy gitlab-cn]# git diff v11.1.2 v11.1.2-zh > ../11.1.2-zh.diff

#将10.7.0-zh.diff作为补丁更新到gitlab中 
[root@deploy gitlab-cn]# cd ..
[root@deploy ~]# yum install patch -y
[root@deploy ~]# patch  -d /opt/gitlab/embedded/service/gitlab-rails -p1 < 11.1.2-zh.diff 

#出现以下提供一直按回车即可
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/app/assets/javascripts/awards_handler.js b/app/assets/javascripts/awards_handler.js
|index 70f20c5..b8089dd 100644
|--- a/app/assets/javascripts/awards_handler.js
|+++ b/app/assets/javascripts/awards_handler.js
--------------------------
File to patch: 

#启动gitlab
[root@deploy ~]# gitlab-ctl start

#再次访问已经可以看到汉化完成

《Gitlab + Jenkins + Ansible 自动部署 --安装篇》

安装jenkins
#可以从我的服务器上下载 也可以从官网下载
[root@deploy ~]# wget http://download.baiyongjie.com/deploy/jdk-8u45-linux-x64.tar.gz
[root@deploy ~]# wget http://download.baiyongjie.com/deploy/jenkins_2.121.2.war
[root@deploy ~]# wget http://download.baiyongjie.com/deploy/apache-tomcat-8.5.4.tar.gz

#安装jdk
[root@deploy ~]# tar zxvf jdk-8u45-linux-x64.tar.gz
[root@deploy ~]# mv  jdk1.8.0_45  /usr/local/
[root@deploy ~]# mv jdk-8u45-linux-x64.tar.gz  /usr/local/src/

#添加到系统的环境变量
[root@deploy ~]# cat >>/etc/profile << EOF
export JAVA_HOME=/usr/local/jdk1.8.0_45
export JRE_HOME=\${JAVA_HOME}/jre
export CLASSPATH=.:\${JAVA_HOME}/lib:\${JRE_HOME}/lib
export PATH=\${JAVA_HOME}/bin:\$PATH
EOF

#使profile文件生效,并查看java版本
[root@deploy ~]# source  /etc/profile   
[root@deploy ~]# java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

#安装tomcat
[root@deploy ~]# tar zxvf apache-tomcat-8.5.4.tar.gz 
[root@deploy ~]# mv apache-tomcat-8.5.4  /usr/local/jenkins
[root@deploy ~]# rm -rf /usr/local/jenkins/webapps/*
[root@deploy ~]# mv apache-tomcat-8.5.4.tar.gz  /usr/local/src/

#修改tomcat字符集,及端口
[root@deploy ~]# vim /usr/local/jenkins/conf/server.xml 
    <Connector port="8080" URIEncoding="UTF-8" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

#启动jenkins
[root@deploy ~]# mv jenkins_2.121.2.war  /usr/local/jenkins/webapps/jenkins.war
[root@deploy ~]# /usr/local/jenkins/bin/startup.sh

#查看tomcat日志
[root@deploy ~]# tail -f /usr/local/jenkins/logs/catalina.out 
31-Jul-2018 19:17:39.687 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /usr/local/jenkins/webapps/jenkins.war has finished in 18,725 ms
31-Jul-2018 19:17:39.692 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8090]
31-Jul-2018 19:17:39.697 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-8009]
31-Jul-2018 19:17:39.698 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 18776 ms

#配置防火墙
[root@deploy ~]# iptables -I INPUT -p tcp --dport  8090 -j ACCEPT
[root@deploy ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

#访问Jenkins
http://10.241.0.1

#第一次打开jenkins需要初始化密码
[root@deploy ~]# cat /root/.jenkins/secrets/initialAdminPassword
23952aded0864751a5abf5676a6a81d3

#解决jenkins插件问题,访问
http://10.241.0.1/jenkins/pluginManager/advanced

#修改最下面的升级站点地址
http://updates.jenkins-ci.org/update-center.json
#清华大学镜像源 https://mirrors.tuna.tsinghua.edu.cn/jenkins/
#上海大学镜像源 https://mirrors.shu.edu.cn/jenkins/

#如配置地址后仍然无法在线使用,那可以采用下载插件,手动安装
http://mirror.xmission.com/jenkins/plugins/


#重启jenkins命令
kill -9 `ps -ef|grep '/usr/local/jenkins' | grep -v grep | awk '{print $2}' `
/usr/local/jenkins/bin/startup.sh   

《Gitlab + Jenkins + Ansible 自动部署 --安装篇》

点赞

发表评论

邮箱地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据