码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx(TLS) + Tomcat + Jenkins

时间:2018-09-17 23:04:36      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:cer   end   start   nginx配置   参考   xmx   备份   code   apache   

一、安装JDK

1.解压jdk的tar包

$ tar zxvf jdk-8u181-linux-x64.tar.gz -C /usr/local/

2.创建软连接

$ ln -sv /usr/local/jdk1.8.0_181/ /usr/local/java

3.添加环境变量

$ vim /etc/profile.d/java.sh

JAVA_HOME=/usr/local/java
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH

4.执行环境变量文件

$ source /etc/profile.d/java.sh

5.检查JDK版本

$ java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

二、安装Tomcat

1.解压tomcat

$ tar zxvf apache-tomcat-9.0.12.tar.gz -C /usr/local

2.创建软连接

$ ln -sv /usr/local/apache-tomcat-9.0.12/ /usr/local/tomcat

3.修改tomcat绑定的IP地址

$ cd /usr/local/tomcat

$ vim ./conf/server.xml
    <Connector port="8080" address="192.168.101.100" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

4.启动tomcat

$ ./bin/catalina.sh start

$ ss -tunl | grep -E "8080|8009|8005"
tcp    LISTEN     0      1      ::ffff:127.0.0.1:8005                 :::*                  
tcp    LISTEN     0      100      :::8009                 :::*                  
tcp    LISTEN     0      100      ::ffff:192.168.101.100:8080                 :::* 

5.curl测试

$ curl -I http://192.168.101.100:8080
HTTP/1.1 200 
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 17 Sep 2018 13:31:56 GMT

三、安装jenkins

1.关闭tomcat

$ ./bin/catalina.sh stop

2.备份webapps

$ cp -a -rf ./webapps ./webapps-bak

3.删除webapps目录种内容

$ rm -rf ./webapps/*

4.将jenkins.war放入webapps, 并修改为ROOT.war

$ mv webapps/jenkins.war webapps/ROOT.war

5.设置jenkins home

$ mkdir /usr/local/jenkins

$ vim /etc/profile.d/jenkins.sh
export CATALINA_OPTS="-DJENKINS_HOME=/usr/local/jenkins/ -Xmx512m"

$ source /etc/profile.d/jenkins.sh

$ echo $CATALINA_OPTS
-DJENKINS_HOME=/usr/local/jenkins/ -Xmx512m

6.重新启动tomcat

$ ./bin/catalina.sh start

7.浏览器打开192.168.101.100:8080, 初始化jenkins

四、安装nginx

1.安装nginx

$ yum install -y nginx

2.制作TLS证书

3.修改nginx配置文件

upstream jenkins {
    server 192.168.101.100:8080 fail_timeout=0;
}

server {
    listen 443 ssl;
    server_name rancher.leistudy.com;

    ssl_certificate /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;

    location / {
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_redirect http:// https://;
            proxy_pass      http://jenkins;
            proxy_http_version 1.1;
            proxy_request_buffering off;
            #add_header ‘X-SSH-Endpoint‘ ‘rancher.leistudy.com:22‘ always;
    }
}

4.检查nginx配置并启动

$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

$ systemctl start nginx

$ ss -tunl | grep "443"
tcp    LISTEN     0      128       *:443                   *:* 

5.登陆https://192.168.101.100查看

技术分享图片

五、参考文档

https://wiki.jenkins.io/display/JENKINS/Tomcat

https://wiki.jenkins.io/display/JENKINS/Jenkins+behind+an+NGinX+reverse+proxy

Nginx(TLS) + Tomcat + Jenkins

标签:cer   end   start   nginx配置   参考   xmx   备份   code   apache   

原文地址:http://blog.51cto.com/13501622/2176387

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!