• Jenkins.war包构建Jenkins平台


    [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  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    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  0;
        keepalive_timeout  65;
    
        #gzip  on;
        include /etc/nginx/conf.d/*.conf;
    }

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

    upstream jenkins {
        server 192.168.2.157:8080;
    
    }
    
    server {
    
        listen 80;
        server_name _;
    
        charset utf-8;
        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/

    问题故障处理:

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

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

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

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

     【验证测试】

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

     构建操作

    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-60100 ~]# ps aux | grep java     #java以及jenkins均已tomcat启动
    tomcat      893  3.4 49.2 2886312 492316 ?      Ssl  10:16   0:54 /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       1090  0.0  0.0 112732   972 pts/0    S+   10:43   0:00 grep --color=auto java
    [root@hostname-60100 ~]# su - tomcat
    上一次登录:四 5月 14 10:27:52 CST 2020pts/0-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=0 >>
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root  8.0G  6.5G  1.5G   82% /
    devtmpfs                 1.4G     0  1.4G    0% /dev
    tmpfs                    1.4G     0  1.4G    0% /dev/shm
    tmpfs                    1.4G  8.9M  1.4G    1% /run
    tmpfs                    1.4G     0  1.4G    0% /sys/fs/cgroup
    /dev/sda1               1014M  125M  890M   13% /boot
    overlay                  8.0G  6.5G  1.5G   82% /var/lib/docker/overlay2/9dc8505645f22a03c80b3ba4146161b7ad6c6dce089ee3e5951a7457e1e4141e/merged
    overlay                  8.0G  6.5G  1.5G   82% /var/lib/docker/overlay2/186d62be6b46a302b6c80556492311973280ac1fa9c516deddb7c6dbe9ca31e1/merged
    overlay                  8.0G  6.5G  1.5G   82% /var/lib/docker/overlay2/ead99b5cfe0980ba7c12e99c26d243b54e10a09d060971ffc1c863b238182902/merged
    overlay                  8.0G  6.5G  1.5G   82% /var/lib/docker/overlay2/1a32cab10af0cadc0a92cc5181f41f4cebefc8ebf760350955540df019e3d519/merged
    overlay                  8.0G  6.5G  1.5G   82% /var/lib/docker/overlay2/e91c81b30c27c80d174373cbcf42da01252d258503bd127b1ce6fbf08cf5c5ea/merged

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

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

     

    构建之后的页面

     

    END!

  • 相关阅读:
    设计模式---对象创建模式之抽象工厂模式(Abstract Factory)
    设计模式---对象创建模式之工厂方法模式(Factory Method)
    设计模式---单一职责模式之桥模式(Bridge)
    设计模式---单一职责模式之装饰模式(Decorator)
    设计模式---组件协作模式之观察者模式(Observer)
    设计模式---组件协作模式之策略模式(Strategy)
    设计模式---组件协作模式之模板方法模式(Tempalte Method)
    设计模式---设计模式的分类
    考勤相关资料
    HR-人力资源管理系统(Human Resources Management System,HRMS)
  • 原文地址:https://www.cnblogs.com/bixiaoyu/p/9560992.html
Copyright © 2020-2023  润新知