Tomcat random boot via shell under CENTOS7
What we are introducing today is the introduction of the configuration of Tomcat random boot through the shell under Centos7, and the replacement of the service from the systemd from the CENTOS7, so it is a little different to operate. Specifically not more introduced, to begin our main introduction today,
Our environment; Centos7, then create a separate partition, then place the JDK and Tomcat service under a separate partition, configure the environment variables, and finally boot up Tomcat with the system by editing the shell script.
We first create a Java directory under the separate partition data, which mainly hosts the JDK files.
650) this.width=650; "title=" clip_image001 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ image001 "src=" Http://s3.51cto.com/wyfs02/M01/8A/15/wKioL1gmiIOwkuT2AABOVewiqPk194.png "height=" "/>"
We use the UNAME-A command to see if the current system is x86 x64 bit system, if there is a x86_64 64-bit operating system, if not, it is 32-bit
650) this.width=650; "title=" clip_image001[4] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[4] "src=" http://s3.51cto.com/wyfs02/M02/8A/19/wKiom1gmiISSNjLDAABMoE8IKA4677.png "height="/>
Once the system version is confirmed, we can start downloading the corresponding version of the JDK.
Http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
650) this.width=650; "title=" clip_image001[6] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[6] "src=" http://s3.51cto.com/wyfs02/M00/8A/19/wKiom1gmiIewLV27AAK1ePyB_oU686.png "height=" 396 "/>
Of course we can download it locally, then use WINSCP to upload it, then unzip it, or we'll use the wget to download it locally.
So we first installed the wget service.
Yum install–y wgetwget http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz? authparam=1478338217_f78e439d698b2c8dbf4151e9a1aa8740
Start download
650) this.width=650; "title=" clip_image001[8] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[8] "src=" http://s3.51cto.com/wyfs02/M00/8A/15/wKioL1gmiIiRFN47AACWKJ3V7KI449.png "height=" "/>"
Download complete Let's take a look
Ls
650) this.width=650; "title=" clip_image001[10] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[10] "src=" Http://s3.51cto.com/wyfs02/M00/8A/19/wKiom1gmiIqhkoc0AAEISI2A8as366.png "height=" 134 "/>
We need to move the file to the/data/java directory
MV jdk-* Data/java
650) this.width=650; "title=" clip_image001[12] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[12] "src=" http://s3.51cto.com/wyfs02/M02/8A/19/wKiom1gmiIqQP6pmAABmJd8mOhs216.png "height="/>
And then we need to unzip
TAR-ZXVF jdk .....
650) this.width=650; "title=" clip_image001[14] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[14] "src=" http://s3.51cto.com/wyfs02/M00/8A/15/wKioL1gmiIzBoJ6GAACVj9DYKm0927.png "height=" "/>"
We look at the extracted directory structure, and we have a separate partition attached, so we're going to put the JDK in the/data/java directory.
650) this.width=650; "title=" clip_image001[16] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image001[16]" src= "Http://s3.51cto.com/wyfs02/M01/8A/19/wKiom1gmiIzBXIczAAB10UsuJZM247.png" height= "89"/ >
650) this.width=650; "title=" clip_image002 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ image002 "src=" Http://s3.51cto.com/wyfs02/M01/8A/15/wKioL1gmiI3BQBm9AACuogdLaUw919.png "height=" 103 "/>
The next step is to configure the JDK environment variables.
Vim/etc/profile
650) this.width=650; "title=" clip_image001[18] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[18] "src=" http://s3.51cto.com/wyfs02/M01/8A/15/wKioL1gmiI6hGXJFAADqCfdSBQA101.png "height=" 359 "/>
Add variable information to the last surface--JDK environment variables
Cannot have spaces, there can be no spaces between rows and rows
Export Java_home=/data/jdk1.8.0_111export path= $JAVA _home/bin: $PATHexport classpath= $JAVA _home/lib/dt.jar: $JAVA _ Home/lib/tools.jar
After adding
650) this.width=650; "title=" clip_image001[20] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[20] "src=" http://s3.51cto.com/wyfs02/M02/8A/15/wKioL1gmiI6Anv3cAAE33mt6aQ8976.png "height=" 417 "/>
[[email protected] ~]# source/etc/profile//Make changes effective immediately [[email protected] ~]# echo $PATH//view PATH value
650) this.width=650; "title=" clip_image001[22] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[22] "src=" http://s3.51cto.com/wyfs02/M00/8A/19/wKiom1gmiJDSARn0AABXn9GS30A228.png "height="/>
We run the Java test
650) this.width=650; "title=" clip_image001[24] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[24] "src=" Http://s3.51cto.com/wyfs02/M00/8A/19/wKiom1gmiJKST41hAAIebM4RK7w160.png "height=" 484 "/>
Next, we need to install Tomcat.
The first is to download
650) this.width=650; "title=" clip_image001[26] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[26] "src=" Http://s3.51cto.com/wyfs02/M00/8A/15/wKioL1gmiJPC7NxIAAFPfn9XAVU686.png "height=" 331 "/>
We also use wget to download wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.6/bin/ Apache-tomcat-8.5.6.tar.gz then unzip TAR–ZXVF apache-tomcat-8.5.6.tar.gz
650) this.width=650; "title=" clip_image001[28] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[28] "src=" http://s3.51cto.com/wyfs02/M01/8A/19/wKiom1gmiJTCfI2YAABXCa5sH9A561.png "height="/>
Then we go into the Apache-tomcat directory to start the service
650) this.width=650; "title=" clip_image001[30] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[30] "src=" http://s3.51cto.com/wyfs02/M02/8A/19/wKiom1gmiJiC6eZHAAFa1EP73YY711.png "height=" 187 "/>
Then visit
650) this.width=650; "title=" clip_image001[32] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[32] "src=" http://s3.51cto.com/wyfs02/M02/8A/19/wKiom1gmiJvDlYUHAAIC9tfAsuI042.png "height=" 337 "/>
Next set up auto start, we configure the startup script
Before we configure, we add the Tomcat environment variable,
Vim/etc/profile Add the following export Catalina_home=/data/apache-tomcat-8.5.6export path= $CATALINA _home/bin: $PATH
650) this.width=650; "title=" clip_image001[34] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[34] "src=" Http://s3.51cto.com/wyfs02/M00/8A/19/wKiom1gmiJzjiOeaAADZdP4G_PU572.png "height=" 166 "/>
Save exit
[[email protected] ~]# source/etc/profile//Make changes effective immediately [[email protected] ~]# echo $PATH//view PATH value
650) this.width=650; "title=" clip_image001[36] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[36] "src=" http://s3.51cto.com/wyfs02/M00/8A/19/wKiom1gmiJ3wLi_RAAA4dbd4eWo896.png "height="/>
We create a shell directory under the data directory, and then build a new shell script inside
Next we create a shell script to start Tomcat
650) this.width=650; "title=" clip_image001[38] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image001[38]" src= "Http://s3.51cto.com/wyfs02/M00/8A/15/wKioL1gmiJ7QfvgpAAD0qQgVRWU943.png" height= "218"/ >
Give Execute permission
650) this.width=650; "title=" clip_image002[4] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE002[4] "src=" Http://s3.51cto.com/wyfs02/M01/8A/15/wKioL1gmiKGyHPKwAAB6VKL2xGE818.png "height=" 109 "/>
Then configure the Tomcat startup script content
Vim tomcat.sh#!/bin/bash## Tomcat startup script for the Tomcat server## chkconfig:345 20# Description:start the TOMC At deamon## Source function library. /etc/rc.d/init.d/functionsprog=tomcatjava_home=/data/java/jdk1.8.0_111/export JAVA_HOMECATALANA_HOME=/DATA/ Apache-tomcat-8.5.6export catalina_homecase "$" instart) echo "Starting tomcat ..." $CATALANA _home/bin/startup.sh;; Stop) echo "Stopping Tomcat ..." $CATALANA _home/bin/shutdown.sh;; Restart) echo "stopping tomcat ..." $CATALANA _home/bin/shutdown.shsleep 2echo-n "starting tomcat ..." $CATALANA _home/bin /startup.sh;; *) echo "Usage: $prog {start|stop|restart}";; Esacexit 0
Save exit
Before we execute, we will first stop the Tomcat service
To see if Tomcat is up and running
650) this.width=650; "title=" clip_image001[40] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image001[40]" src= "Http://s3.51cto.com/wyfs02/M01/8A/19/wKiom1gmiKTTqiaxAABFnValksA889.png" height= "57"/ >
Ps-ef | grep java
650) this.width=650; "title=" clip_image002[6] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE002[6] "src=" http://s3.51cto.com/wyfs02/M00/8A/19/wKiom1gmiKeCorMDAACiSn8Yoes734.png "height=" "/>
End Java Process
Killall-9 java or kill-9 process ID
650) this.width=650; "title=" clip_image001[42] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image001[42]" src= "Http://s3.51cto.com/wyfs02/M00/8A/15/wKioL1gmiKiT89tyAADRpi2MCVo997.png" height= "74"/ >
The Java process has been killed.
650) this.width=650; "title=" clip_image002[8] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE002[8] "src=" http://s3.51cto.com/wyfs02/M02/8A/19/wKiom1gmiKiwn4gXAAA64n5tt-o340.png "height=" "/>
Next we use the script to start the following
Tomcat can be manipulated by executing the script plus parameters.
650) this.width=650; "title=" clip_image001[44] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[44] "src=" http://s3.51cto.com/wyfs02/M00/8A/19/wKiom1gmiKmxfH1gAADPoB2Lalo136.png "height=" 155 "/>
650) this.width=650; "title=" clip_image001[46] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[46] "src=" http://s3.51cto.com/wyfs02/M02/8A/19/wKiom1gmiKryGWdVAAA6hv9fs_M192.png "height="/>
Because we don't need to pass in parameters, we can modify the contents of the script directly.
#!/bin/bash## tomcat startup script for the tomcat server## chkconfig: 345 80 20# description: start the tomcat deamon## source function library. /etc/rc.d/init.d/functionsprog= Tomcatjava_home=/data/java/jdk1.8.0_111/export java_homecatalana_home=/data/apache-tomcat-8.5.6export CATALINA_HOMEcase "Start" instart) echo "Starting tomcat ..." $CATALANA _home/bin/ startup.sh;; Stop) echo "Stopping tomcat ..." $CATALANA _home/bin/shutdown.sh;; Restart) echo "Stopping tomcat ..." $CATALANA _home/bin/shutdown.shsleep 2echo -n " Starting tomcat. "$CATALANA _home/bin/startup.sh;; *) echo "usage: $prog {start|stop|restart}";; Esacexit 0
650) this.width=650; "title=" clip_image001[48] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[48] "src=" Http://s3.51cto.com/wyfs02/M00/8A/19/wKiom1gmiKugbpMxAAEzYIMzXIM772.png "height=" 484 "/>
We have copied a copy of the script for ease of administration, a change of incoming parameters, a copy of the parameters not passed in.
Now start configuring the script to add to the startup directory of the system
Put the shell script into the/etc/rc.d/init.d/directory under CP starttomcat.sh/etc/rc.d/init.d/starttomcat give execute permission chmod 777 Starttomcat
650) this.width=650; "title=" clip_image001[50] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[50] "src=" Http://s3.51cto.com/wyfs02/M00/8A/15/wKioL1gmiKzTPWn2AACu6HvGpYU844.png "height=" 98 "/>
Use the Chkconfig command to add a script to the boot startup project
[[email protected] init.d]# chkconfig--add starttomcat[[email protected] init.d]# chkconfig starttomcat on
650) this.width=650; "title=" clip_image001[52] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image001[52]" src= "Http://s3.51cto.com/wyfs02/M01/8A/19/wKiom1gmiK3TJKMqAABSDirTZV4130.png" height= "46"/ >
After execution, you can check to see if there is a corresponding startup link under/ETC/RC.D/RC*.D, point to the script that you just
650) this.width=650; "title=" clip_image002[10] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image002[10]" src= "http://s3.51cto.com/wyfs02/M01/8A/15/wKioL1gmiK7go4MjAAI_X1pBDdw652.png" height= "438"/ >
650) this.width=650; "title=" clip_image003 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ image003 "src=" Http://s3.51cto.com/wyfs02/M02/8A/19/wKiom1gmiK-DqKI4AAI-DEOehG8700.png "height=" 421 "/>
Here we have finished the configuration, and we will introduce another method of automatic start.
This article from "Gao Wenrong" blog, declined reprint!
Tomcat random boot via shell under CENTOS7