The first step installs the JDK1. Download the JDK installation file
Download JDK to Oracle website
I am here to download the jdk1.8.91 version
and copy the downloaded good compressed file jdk-8u91-linux-x64.tar.gz to the root user folder.
2. Installing the JDK
Log on to Linux as the root user
echo " Go to install directory " CD /usr/localecho "new Java folder" mkdir javaecho "Enter Java folder" CD javaecho " Copy the installation file to the current directory " cp/root/jdk-8 u91-linux-x64.tar.gz. echo "unzip" tar zxvf jdk-8 U91-linux-x64.tar.gzecho "Delete installation files, or keep" rm - F jdk-8 u91-linux-x64.tar.gzecho vi/etc/profile
Add the following to the end of the file
export JAVA_HOME=/usr/local/java/jdk1.8.0_91export JRE_HOME=${JAVA_HOME}export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}export PATH=${JAVA_HOME}/bin:$PATH
Save File and exit (: Wq)
Update the environment variable file to take effect immediately
source /etc/profileecho"测试JDK是否安装成功"java -version
The following appears to indicate a successful configuration:
"1.8.0_91"1.8.0_91-b1464-Bit25.91-b14, mixed mode)
Step two install TOMCAT1. Download the Tomcat installation file
Download Tomcat to Apache Tomcat official website
I am here to download the Tomcat 9.0.0.M4 version
and copy the downloaded good compressed file apache-tomcat-9.0.0.m4.tar.gz to the root user folder.
2. Install Tomcat
Log on to Linux as the root user
Echo"Go to installation directory"Cd/usr/localecho"New Tomcat folder"mkdir Tomcatecho"Go to the Tomcat folder"CD Tomcatecho"Copy installation files to current directory"CP/root/apache-tomcat-9.0. 0. M4. Tar. GZ. Echo"Unzip"Tar zxvf apache-tomcat-9.0. 0. M4. Tar. GZEcho"Delete the installation files, or you can keep"Rm-f apache-tomcat-9.0. 0. M4. Tar. GZEcho"Start Tomcat"apache-tomcat-9.0. 0. M4/bin/startup. SH
If Tomcat prints the following to indicate a successful start
org.apache.catalina.startup.Catalina.startin692 ms
Step three install Maven1. Download maven installation files
Download maven on the Apache Maven website
I am here to download the apache-maven-3.3.9 version
and copy the downloaded good compressed file apache-maven-3.3.9-bin.tar.gz to the root user folder.
2. Install Maven
Log on to Linux as the root user
Echo "Go to installation directory"CD/usr/localEcho "New maven folder"mkdir mavenEcho "Go to maven folder"CDMavenEcho "Copy installation files to current directory"cp/root/apache-maven-3.3.9-bin.tar.gz.Echo "Unzip"Tar zxvf apache-maven-3.3.9-bin.tar.gzEcho "Delete the installation files, or you can keep"Rm- Fapache-maven-3.3.9-bin.tar.gzEcho "Add environment variables"Vi/etc/profile
Add the following to the end of the file
export MAVEN_HOME=/usr/local/maven/apache-maven-3.3.9export PATH=${MAVEN_HOME}/bin:${PATH}
Save File and exit (: Wq)
Update the environment variable file to take effect immediately
source /etc/profileecho"测试maven是否安装成功"mvn -v
The following appears to indicate a successful configuration:
Apache Maven3.3. 9(BB52D8502B132EC0A5A3F4C09453C07478323DC5; -- One-TenT08: A: -- ,:xx) Maven Home:/usr/Local/maven/apache-maven-3.3. 9Javaversion:1.8. 0_91, Vendor:oracle Corporationjava home:/usr/Local/java/jdk1. 8. 0_91/jredefault Locale:en_us,Platformencoding:utf-8OS Name:"Linux",version:"2.6.32-573.18.1.el6.x86_64", Arch:"AMD64", Family:"UNIX"
Fourth Step installation Jenkins1 online installation Jenkins (recommended)
Log on to Linux as the root user
"导入Jenkins Key,并下载安装文件"wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.reporpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key"安装Jenkins"yum install jenkins
After the installation is complete we need to do some basic configuration:
Configuring the Jenkins Port
Echo"Configure the Jenkins port to open the Jenkins configuration file"Vi/etc/sysconfig/jenkinsecho"Modify jenkins_port=8888 to avoid conflicts with Tomcat"Echo"Modify jenkins_ajp_port=8099 to avoid conflicts with Tomcat"Echo"Modify Jenkins_user=root to avoid running out of shell script permissions in the job"Echo"Save and Exit (: Wq)"Echo"Configure access to Jenkins for root user to avoid running out of shell script permissions in Job"Chown- RRoot/var/Log/jenkins CHGRP- RRoot/var/Log/jenkinschown- RRoot/var/lib/jenkins CHGRP- RRoot/var/lib/jenkinschown- RRoot/var/Cache/jenkins CHGRP- RRoot/var/Cache/jenkins
Configuring the Jenkins JDK to open the Jenkins configuration file
vi /etc/init.d/jenkins
Find the following code:
candidates="/etc/alternatives/java/usr/lib/jvm/java-1.6.0/bin/java/usr/lib/jvm/jre-1.6.0/bin/java/usr/lib/jvm/java-1.7.0/bin/java/usr/lib/jvm/jre-1.7.0/bin/java/usr/lib/jvm/java-1.8.0/bin/java/usr/lib/jvm/jre-1.8.0/bin/java/usr/bin/java"
Add the Java environment you just installed:
candidates="/etc/alternatives/java/usr/lib/jvm/java-1.6.0/bin/java/usr/lib/jvm/jre-1.6.0/bin/java/usr/lib/jvm/java-1.7.0/bin/java/usr/lib/jvm/jre-1.7.0/bin/java/usr/lib/jvm/java-1.8.0/bin/java/usr/lib/jvm/jre-1.8.0/bin/java/usr/local/jdk1.8.0_91/bin/java/usr/bin/java"
Save and exit (: Wq)
Start Jenkins
echo"启动Jenkins服务"service jenkins start
Log on to http://Linux server ip:8888/ Access Jenkins when the boot is complete
Fifth step configuration Jenkins1. Initializing configuration
The first login to Jenkins2.0 will require a security token to be entered
Click the not sure in the figure where to find the logs? It shows how security tokens are obtained.
It's like opening a file in a Linux system.
When you are finished, you will be prompted to install a custom plug-in or a recommended plugin, where we choose the recommended plugin:
Then enter the default administrator default user name and password
After the configuration is complete, you can go to the Jenkins homepage.
2. Installing plugins
Go to the Jenkins menu system Management-Admin Plugin
Click the Optional plugin Tab
Search for and install the following plugins:
-Subversion Plug-in
-Maven Integration Plugin
-Email Extension Plugin
3. Configuring the Environment
Go to Jenkins Menu System Management , Global Tool Configuration
Configuring the JDK
Configure Maven
Click Save when the configuration is complete
Go to the Jenkins menu System Management , management node
New Environment variables
Note: The role of this environment variable is to change the Jenkins original environment variable build_id when the job executes, to avoid Jenkins detecting that the child process created during job execution is forced to close when job execution is completed.
(for example, when you execute a job, Tomcat is started, and if you do not add this variable, the job executes and Tomcat closes)
Click Save when Setup is complete
Sixth step Create Job
1. Go to the Jenkins homepage
2. Click New
3. Click to build a MAVEN project
4. Type the project name and click OK
5. Source Control
5.1 Enter SVN project address
5.2 Adding a user password
6. Build triggers
7.Maven Build
8. Post-build actions
Deploy a well-fought war package into Tomcat
Automatic deployment Script code:
#Tomcat根目录Tomcat_home="/USR/LOCAL/TOMCAT/APACHE-TOMCAT-9.0.0.M4"#端口tomcat_port=8080#TOMCAT_PID用于检测Tomcat是否在运行Tomcat_pid= ' Lsof-n-p-t-I:${tomcat_port}`#如果Tomcat还在运行if[-N"${tomcat_pid}"]; Then #关闭Tomcat ${tomcat_home}/bin/shutdown.sh#循环检查Tomcat是否关闭完成 while[-N"${tomcat_pid}"] Do #等待1秒Sleep1 #获取8080端口运行进程PID, if the PID is empty, Tomcat is turned offTomcat_pid= ' Lsof-n-p-t-I:${tomcat_port}`Echo "shutting down tomcat["${tomcat_port}"]..." Done Echo "successfully closed tomcat."fiWarpath="${tomcat_home}/webapps/war Package name/"warfile="${tomcat_home}/webapps/war package name. War"#如果文件或者文件夹存在则删除deletewhenexist(){if[- e $]; ThenRm-rf $ fi}deletewhenexist${warpath}Deletewhenexist${warfile}#拷贝新编译的包到TomcatCP Project name/target/war package name. War${tomcat_home}/webapps/${tomcat_home}/bin/startup.shEcho "Starting tomcat["${tomcat_port}"]..."#检测Tomcat是否启动完成 while[-Z"${tomcat_pid}"] DoSleep1 #echo "tomcat_pid[" ${tomcat_pid} "]"Tomcat_pid= ' Lsof-n-p-t-I:${tomcat_port}`Echo "Starting tomcat["${tomcat_port}"]..." DoneEcho "started Tomcat successfully."
9.Job configuration End, click Save
Seventh Step Build Job
Go to the MAVEN project you just created
Click Build Now
viewing console output
If the console finally displays the following information, it indicates that the build succeeded
[vcat_2.8] $/bin/sh-xe/tmp/hudson6570402632722344885.sh+' ['-e/root/auto-deploy-vcat.sh'] '+/root/auto-deploy-vcat.sh is shutting down tomcat[8080]...Shutting down tomcat[8080]...Shutting down tomcat[8080]...Shutting down tomcat[8080]...Shutting down tomcat[8080]...Successfully closed Tomcat.tomcat started. Starting tomcat[8080]...Starting tomcat[8080]...Starting tomcat[8080]...Starting tomcat[8080]...Successfully started Tomcat.Finished:SUCCESS
Linux configuration Jenkins builds maven job for continuous release project to Tomcat