Jenkins.war包构建Jenkins平台

时间:2021-03-09 15:02:55

[root@jenkins ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

[root@jenkins ~]#yum install -y nginx tomcat   #由于时间的关系,我们直接配置yum源,直接yum在本地安装tomcat和nginx

[root@jenkins ~]#wget -O ROOT.war http://mirrors.jenkins.io/war-stable/latest/jenkins.war     #下载Jenkins.war包,并更名为ROOT.war

[root@jenkins ~]# vim /etc/nginx/nginx.conf

#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on;
include /etc/nginx/conf.d/*.conf;
}

[root@jenkins ~]# vim /etc/nginx/conf.d/jenkins.conf

upstream jenkins {
server 192.168.2.157:; } server { listen ;
server_name _; charset utf-;
index index.jsp index.html index.htm; location / {
proxy_pass http://jenkins;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }

[root@jenkins ~]# cp ROOT.war /usr/share/tomcat/webapps/

[root@jenkins ~]# systemctl  restart nginx

[root@jenkins ~]# systemctl restart tomcat

WEB-GUI:安装http://192.168.2.157/

Jenkins.war包构建Jenkins平台

Jenkins.war包构建Jenkins平台

Jenkins.war包构建Jenkins平台

Jenkins.war包构建Jenkins平台

Jenkins.war包构建Jenkins平台

Jenkins.war包构建Jenkins平台

Jenkins.war包构建Jenkins平台

问题故障处理:

Jenkins.war包构建Jenkins平台

解决办法:在tomcat的server.xml中增加utf8字符即可

[root@jenkins ~]# vim /usr/share/tomcat/conf/server.xml

<Connector port="" protocol="HTTP/1.1"
connectionTimeout=""
URIEncoding= "UTF-8"
redirectPort=""
proxyName="jenkins.yellowcong.net"/>

[root@jenkins ~]# systemctl restart tomcat   #重启tomcat之后,我们会发现,这个讨厌的字符集错误已经没有了~

【验证测试】

从SVN仓库中拉去源代码并将logo.png推送到Discuz论坛上,从而替换掉discuz论坛首页的logo图片!

Jenkins.war包构建Jenkins平台

构建操作

Execute shell

ansible all -m shell -a "mv /var/www/html/static/image/common/logo.png /tmp/"
ansible all -m copy -a 'src=/usr/share/tomcat/.jenkins/workspace/www.hexun.com/logo.png dest=/var/www/html/static/image/common/ mode=644 owner=root'
#ssh -l root 192.168.60.101 mv /var/www/html/static/image/common/logo.png /tmp/
#scp /usr/share/tomcat/.jenkins/workspace/www.hexun.com/logo.png root@192.168.60.101:/var/www/html/static/image/common/

ansible配置

这里的jenkins所基于的java进程都是tomcat用户启动的,故在jenkins构建的时候也是以tomcat为基准,从svn拉取完代码推送到目标端时,需要做ssh免秘钥认证,否则会构建失败!

[root@hostname- ~]# ps aux | grep java     #java以及jenkins均已tomcat启动
tomcat 3.4 49.2 ? Ssl : : /usr/lib/jvm/jre/bin/java -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat -Dcatalina.home=/usr/share/tomcat -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/cache/tomcat/temp -Djava.util.logging.config.file=/usr/share/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start
root 0.0 0.0 pts/ S+ : : grep --color=auto java
[root@hostname- ~]# su - tomcat
上一次登录:四 5月 :: CST 2020pts/ 上
-bash-4.2$ cat /etc/ansible/hosts #查看ansible hosts文件中是否存在目标端ip信息
[web]
192.168.60.101 ansible_ssh_user=root
-bash-4.2$ ansible all -m shell -a "df -h" #简单测试一下ssh是否免密是否生效
192.168.60.101 | CHANGED | rc= >>
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root .0G .5G .5G % /
devtmpfs .4G .4G % /dev
tmpfs .4G .4G % /dev/shm
tmpfs .4G 8.9M .4G % /run
tmpfs .4G .4G % /sys/fs/cgroup
/dev/sda1 1014M 125M 890M % /boot
overlay .0G .5G .5G % /var/lib/docker/overlay2/9dc8505645f22a03c80b3ba4146161b7ad6c6dce089ee3e5951a7457e1e4141e/merged
overlay .0G .5G .5G % /var/lib/docker/overlay2/186d62be6b46a302b6c80556492311973280ac1fa9c516deddb7c6dbe9ca31e1/merged
overlay .0G .5G .5G % /var/lib/docker/overlay2/ead99b5cfe0980ba7c12e99c26d243b54e10a09d060971ffc1c863b238182902/merged
overlay .0G .5G .5G % /var/lib/docker/overlay2/1a32cab10af0cadc0a92cc5181f41f4cebefc8ebf760350955540df019e3d519/merged
overlay .0G .5G .5G % /var/lib/docker/overlay2/e91c81b30c27c80d174373cbcf42da01252d258503bd127b1ce6fbf08cf5c5ea/merged

未构建之前logo是如下图所示

Jenkins.war包构建Jenkins平台

开始构建ing~最后可以看到构建成功!

Jenkins.war包构建Jenkins平台

构建之后的页面

Jenkins.war包构建Jenkins平台

END!