CentOS7.0 部署Tomcat+jenkins+git+maven+ant

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7.0 部署Tomcat+jenkins+git+maven+ant相关的知识,希望对你有一定的参考价值。

此篇献给初学者

一、环境介绍:

    1、操作系统:CentOS 7.0  IP:192.168.137.128

    2、JDK版本:jdk1.8.0_101

    3、Tomcat版本:tomcat-9.0.0.M21

    4、jenkins版本: Jenkins ver. 2.46.3

    5、git版本:git version 2.9.4

    6、maven版本:3.5.0

    7、ant版本:version 1.10.1

二、环境部署

    1、下载所需软件包

        # mkdir /tmp/soft ; cd /tmp/soft

        ##### tomcat

        # wget http://apache.communilink.net/tomcat/tomcat-9/v9.0.0.M21/bin/apache-tomcat-9.0.0.M21.tar.gz

        ##### 下载git

        # wget https://www.kernel.org/pub/software/scm/git/git-2.9.4.tar.gz

        ##### 下载jdk

        # 下载地址:http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz

        ##### 下载maven

        # wget http://ftp.cuhk.edu.hk/pub/packages/apache.org/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz

        ##### 下载jenkins

        # wget http://mirrors.jenkins.io/war/latest/jenkins.war

        ##### 下载ant

        # wget http://apache.communilink.net//ant/binaries/apache-ant-1.10.1-bin.tar.gz

    2、安装部署jdk

        ### 为了以后方便管理,将所有软件安装至/export/servers目录下

        a、解压jdk

        # tar -xf jdk-8u131-linux-x64.tar.gz -C /export/servers

        b、配置环境变量

        ### 编辑/etc/profile文件,添加以下信息:

        # vim /etc/profile

export JAVA_HOME=/export/servers/jdk1.8.0_131

export JAVA_BIN=$JAVA_HOME/bin

export PATH=$JAVA_HOME/bin:$PATH

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export JAVA_OPTS="-Djava.library.path=/usr/local/lib -server -Xms1024m -Xmx2048m -XX:MaxPermSize=256m -Djava.awt.headless=true -Dsun.net.client.defaultReadTimeout=60000 -Djmagick.systemclassloader=no -Dnetworkaddress.cache.ttl=300 -Dsun.net.inetaddr.ttl=300"

export JAVA_HOME JAVA_BIN PATH CLASSPATH JAVA_OPTS

        c、测试安装是否成功

        # java -version

        java version "1.8.0_131"

        Java(TM) SE Runtime Environment (build 1.8.0_131-b11)

Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

    3、安装Tomcat

        a、解压Tomcat

        # tar xf apache-tomcat-9.0.0.M21.tar.gz -C /export/servers

        # mv /export/servers/apache-tomcat-9.0.0.M21 /export/servers/tomcat-9.0.0.M21

        b、配置tomcat

        ###修改Tomcat字符集为UTF-8

        # vim /export/servers/apache-tomcat-9.0.0.M21/conf/server.xml

        # 修改为以下内容,添加URIEncoding:

        <Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" URIEncoding="UTF-8" />

    4、安装jenkins

        a、清理tomcat工作目录

        # cd /export/servers/tomcat-9.0.0.M21/webapps/ROOT/

        # rm -rf *

        b、解压jenkins

        # cp /tmp/soft/jenkins.war ./

        # java -jar jenkins.war

    5、安装git

        a、安装依赖包

        # cd /tmp/soft

        # yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

        b、安装git

        # mkdir -p /export/servers/git-2.9.4

        # tar -xf git-2.9.4.tar.gz 

        # make -j 20 prefix=/export/servers/git-2.9.4 all

        # make prefix=/export/servers/git-2.9.4 install

        c、配置git环境变量

        ### 在/etc/profile最后添加以下信息:

        # vim /etc/profile

export GIT_HOME=/export/servers/git-2.9.4

export PATH=$GIT_HOME/bin:$PATH

    6、安装Maven

        a、解压及安装

        # cd /tmp/soft

        # tar -xf apache-maven-3.5.0-bin.tar.gz

        # mv apache-maven-3.5.0 maven-3.5.0

        # mv maven-3.5.0 /export/servers/

        b、配置环境变量

        ### 在/etc/profile中添加以下信息

        # vim /etc/profile

export MAVEN_HOME=/export/servers/maven-3.5.0

export PATH=$PATH:$MAVEN_HOME/bin

    7、安装Ant

        a、解压及安装

        # tar xf apache-ant-1.10.1-bin.tar.gz

        # mv apache-ant-1.10.1 ant-1.10.1

        # mv ant-1.10.1 /export/servers/

        b、配置环境变量

        ###在/etc/profile中添加以下信息

        # vim /etc/profile

export ANT_HOME=/export/servers/ant-1.10.1

export PATH=$PATH:/export/servers/ant-1.10.1/bin

三、测试及启动服务

    1、测试JDK

        # java -version

        java version "1.8.0_131"

        Java(TM) SE Runtime Environment (build 1.8.0_131-b11)

        Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

    2、测试git

        # git version

        git version 2.9.4

    3、测试maven

        # mvn -v

        Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00)

        Maven home: /export/servers/maven-3.5.0

        Java version: 1.8.0_101, vendor: Oracle Corporation

        Java home: /export/servers/jdk1.8.0_131/jre

        Default locale: en_US, platform encoding: UTF-8

        OS name: "linux", version: "2.6.32-642.el6.x86_64", arch: "amd64", family: "unix"

    4、测试Tomcat和Jenkins

        # cd /export/servers/tomcat-9.0.0.M21/bin

        # /bin/sh startup.sh

        # tailf ../logs/catalina.out

        ### 可以查看下日志,看是否有Error的错误

    5、添加开机自启Tomcat

        # echo "/bin/sh /export/servers/tomcat-9.0.0.M21/bin/startup.sh" >> /etc/rc.d/rc.local


四、Web登录测试

    1、先查看下Jenkins初始密码

        # cat /root/.jenkins/secret.key

4417e1e77b13aa560cfc05aaeb474cbf70f89fd9bc558e4963110c80d0a34d97

      ##### 复制此密码,此密码会在第一次打开Web页面时使用,可能会遇到复制此密码打不开,下面有解决方法

    2、登录Jenkins

        打开浏览器----->在地址栏输入:http://192.168.137.128:8080


    此时,客户端访问页面会提示404,看启动日志也是没问题的,重新启动Jenkins出现的问题如下:

Jun 21, 2017 2:17:44 PM hudson.model.UpdateCenter$DownloadJob run

SEVERE: Failed to install GitHub plugin

hudson.util.IOException2: Failed to download from http://updates.jenkins-ci.org/download/plugins/github/1.27.0/github.hpi (redirected to: http://mirrors.tuna.tsinghua.edu.cn/jenkins/plugins/github/1.27.0/github.hpi)

at hudson.model.UpdateCenter$UpdateCenterConfiguration.download(UpdateCenter.java:1172)

at hudson.model.UpdateCenter$DownloadJob._run(UpdateCenter.java:1677)

at hudson.model.UpdateCenter$InstallationJob._run(UpdateCenter.java:1874)

at hudson.model.UpdateCenter$DownloadJob.run(UpdateCenter.java:1651)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at hudson.remoting.AtmostOneThreadExecutor$Worker.run(AtmostOneThreadExecutor.java:110)

at java.lang.Thread.run(Thread.java:745)

Caused by: java.io.IOException: Failed to load http://updates.jenkins-ci.org/download/plugins/github/1.27.0/github.hpi to /root/.jenkins/plugins/github.jpi.tmp

at hudson.model.UpdateCenter$UpdateCenterConfiguration.download(UpdateCenter.java:1146)

... 7 more

Caused by: java.net.SocketTimeoutException: Read timed out

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:422)

at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1890)

at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1885)

at java.security.AccessController.doPrivileged(Native Method)

at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1884)

at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1457)

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)

at hudson.model.UpdateCenter$UpdateCenterConfiguration.download(UpdateCenter.java:1139)

... 7 more


###解决方法

此错误是由于8080端口被占用,

    改变端口再次执行,

    java -jar jenkins.war --httpPort=$HTTP_PORT, 例如java -jar jenkins.war --httpPort=1088

    启动成功;

    后打开浏览器,输入http://192.168.137.128:1088,即可看到jenkins的页面

###接下来还会出现Jenkins初始密码不能使用,修改初始密码为111111

建议备份在修改此文件

[[email protected] ~]# cd /root/.jenkins/users/admin/

[[email protected] admin]# ls

config.xml  config.xml.ori

<hudson.security.HudsonPrivateSecurityRealm_-Details>    <passwordHash>#jbcrypt:$2a$10$IVgY3xyUJajuUKp5wHWOUeoXxmDHk52.wYKZ4wz9Mt44O3i.V81Ry</passwordHash>

<passwordHash>节点的内容(图中红色的那一串)换成#jbcrypt:$2a$10$DdaWzN64JgUtLdvxWIflcuQu2fgrrMSAMabF5TSrGK5nXitqK9ZMS

(注意前后有木有空格)

保存,重启Jenkins程序。

然后输入用户名默认admin,密码111111

到这进入Jenkins部署界面

至此,Jenkins的部署就已经完成,如有任何问题可以发邮件至:[email protected]


本文出自 “Arthur” 博客,转载请与作者联系!

以上是关于CentOS7.0 部署Tomcat+jenkins+git+maven+ant的主要内容,如果未能解决你的问题,请参考以下文章

请教tomcat和jenkins部署的一个问题

linux12Devops -->06Jenkins部署tomcat

Jenkins自动部署Tomcat项目

jenkins自动部署tomcat

02-Jenkins-Jenkins服务部署在Tomcat下

Jenkins+tomcat从编译到部署