preface
To install software on linux, you can use yum, which is very convenient. You don't need to download and decompress. You can use Yum to install java and tomcat environment with one instruction.
The previous article has achieved a small success in building a Zen system website on Alibaba cloud server, but not every website is so simple.
A general development kit is a war files, which requires an intermediate key, such as tomcat. tomcat depends on the java environment, so install the java environment first
Environmental preparation:
1.Linux system server: CentOS 7
2.yum 3.4.3
3.java 1.8
4.tomcat
yum environment
yum (full name: Yellow dog Updater, Modified) is a Shell front-end package manager in Fedora, RedHat and CentOS.
Based on RPM package management, it can automatically download and install RPM packages from the specified server, automatically handle dependencies, and install all dependent software packages at one time without cumbersome downloading and installation at one time.
Due to the need to install the java environment, according to the previous article, download the installation package first, then transfer it to the specified directory on the server through Xftp, and then extract and install it. Of course, it's OK, but the process is too cumbersome.
In order to solve the complex operation of dragging each download, there is a very convenient gadget yum on linux, which can be downloaded and installed directly. It's a bit similar to the pip tool in python. Everyone who has used it knows it!
First, check whether there is any Yum tool in the current system. If so, you don't need to install it. My system shows that there is already this tool yum-3.4.3, so there is no need to install it.
rpm -qa | grep yum
[root@yoyo ~]# rpm -qa | grep yum yum-metadata-parser-1.1.4-10.el7.x86_64 yum-plugin-fastestmirror-1.1.31-42.el7.noarch yum-3.4.3-154.el7.centos.noarch
java environment
First check whether there is a java environment: rpm -qa | grep java
If there is no Java environment, then go to find the installation package available for java-1.8.0: yum list | grep java-1.8.0-openjdk
[root@yoyo ~]# yum list | grep java-1.8.0-openjdk java-1.8.0-openjdk.i686 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk.x86_64 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-accessibility.i686 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-accessibility-debug.i686 java-1.8.0-openjdk-accessibility-debug.x86_64 java-1.8.0-openjdk-debug.i686 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-debug.x86_64 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-demo.i686 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-demo.x86_64 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-demo-debug.i686 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-devel.i686 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-devel.x86_64 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-devel-debug.i686 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-headless.i686 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-headless.x86_64 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-headless-debug.i686 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-javadoc-zip-debug.noarch java-1.8.0-openjdk-src.i686 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-src.x86_64 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-src-debug.i686 1:1.8.0.191.b12-1.el7_6 updates java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.191.b12-1.el7_6 updates
Install all files of java-1.8.0-openjdk
[root@yoyo ~]# yum -y install java-1.8.0-openjdk*
The installation process takes 1-2 minutes. Have a cup of coffee and install it. Check the version number: java -version
[root@yoyo ~]# java -version openjdk version "1.8.0_191" OpenJDK Runtime Environment (build 1.8.0_191-b12) OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode) [root@yoyo ~]#
Then enter javac. If you can see the content output, it means that it has been installed
[root@yoyo ~]# javac Usage: javac <options> <source files> where possible options include: -g Generate all debugging info -g:none Generate no debugging info -g:{lines,vars,source} Generate only some debugging info -nowarn Generate no warnings -verbose Output messages about what the compiler is doing -deprecation Output source locations where deprecated APIs are used -classpath <path> Specify where to find user class files and annotation processors
Small partners who have installed java should know that the environment variables need to be set after the installation is completed. The advantage of installing through yum is that they have automatically set the environment variables for us.
tomcat installation
tomcat installation can download the installation package first and then unzip it. You can also directly use Yum to install online. Here, it is more convenient for us to install online directly using yum
yum install tomcat //perhaps yum -y install tomcat
-Y stands for y when asked, so you don't need to enter y manually during installation
After the installation, the installation directory is "/ usr/share/tomcat". We use the cd command to switch to this directory and use the ls (or ll) command to view the files in this directory
[root@yoyo tomcat]# ls bin conf lib logs temp webapps work [root@yoyo tomcat]# ll total 4 drwxr-xr-x 2 root root 4096 Dec 28 10:41 bin lrwxrwxrwx 1 root tomcat 11 Dec 28 10:41 conf -> /etc/tomcat lrwxrwxrwx 1 root tomcat 22 Dec 28 10:41 lib -> /usr/share/java/tomcat lrwxrwxrwx 1 root tomcat 15 Dec 28 10:41 logs -> /var/log/tomcat lrwxrwxrwx 1 root tomcat 22 Dec 28 10:41 temp -> /var/cache/tomcat/temp lrwxrwxrwx 1 root tomcat 23 Dec 28 10:41 webapps -> /var/lib/tomcat/webapps lrwxrwxrwx 1 root tomcat 22 Dec 28 10:41 work -> /var/cache/tomcat/work [root@yoyo tomcat]#
Start tomcat service
View the status of tomcat: systemctl status tomcat
[root@yoyo tomcat]# systemctl status tomcat ● tomcat.service - Apache Tomcat Web Application Container Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled) Active: inactive (dead) [root@yoyo tomcat]#
Active: inactive (dead) indicates that tomcat is now in the dead state and the service has not run yet.
Start tomcat: systemctl start tomcat (or systemctl start tomcat.service)
[root@yoyo tomcat]# systemctl start tomcat [root@yoyo tomcat]# systemctl status tomcat ● tomcat.service - Apache Tomcat Web Application Container Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2018-12-28 10:48:38 CST; 5s ago Main PID: 5216 (java) CGroup: /system.slice/tomcat.service └─5216 /usr/lib/jvm/jre/bin/java -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin... Dec 28 10:48:38 yoyo server[5216]: Dec 28, 2018 10:48:38 AM org.apache.catalina.core.StandardService startInternal Dec 28 10:48:38 yoyo server[5216]: INFO: Starting service Catalina Dec 28 10:48:38 yoyo server[5216]: Dec 28, 2018 10:48:38 AM org.apache.catalina.core.StandardEngine startInternal Dec 28 10:48:38 yoyo server[5216]: INFO: Starting Servlet Engine: Apache Tomcat/7.0.76 Dec 28 10:48:38 yoyo server[5216]: Dec 28, 2018 10:48:38 AM org.apache.coyote.AbstractProtocol start Dec 28 10:48:38 yoyo server[5216]: INFO: Starting ProtocolHandler ["http-bio-8080"] Dec 28 10:48:38 yoyo server[5216]: Dec 28, 2018 10:48:38 AM org.apache.coyote.AbstractProtocol start Dec 28 10:48:38 yoyo server[5216]: INFO: Starting ProtocolHandler ["ajp-bio-8009"] Dec 28 10:48:38 yoyo server[5216]: Dec 28, 2018 10:48:38 AM org.apache.catalina.startup.Catalina start Dec 28 10:48:38 yoyo server[5216]: INFO: Server startup in 61 ms Hint: Some lines were ellipsized, use -l to show in full. [root@yoyo tomcat]#
You can see that the status is Active: active (running), which means that tomcat has run normally.
You can also check the Main PID: 5216 (java) to know that the PID is 5216
Access tomcat
The default port of tomcat is 8080. Next, browse and enter the address: http: / / server public network ip:8080 /. This page is temporarily inaccessible
Because tomcat's web page needs to install plug-ins, we continue to use tomcat webapps and tomcat admin webapps plug-in packages
yum install tomcat-webapps tomcat-admin-webapps
After installation, port 8080 is still inaccessible. You need to log in to Alibaba cloud ECS background management and open ECS - Security Group - configuration rules
Add security group rules and port 8080 access rights
- Rule direction: in direction
- Protocol type: Custom FTP
- Port range: 8080 / 8080
- Authorization object: 0.0.0.0/0
Then go to the browser to visit http: / / server public network ip:8080, and you can open the address of tomcat
Manager App username and password
If you want to enter the Manager App, click the Manager App on the home page, and a pop-up box will appear, where you can enter your user name and password
Click Cancel directly and the 401 interface will appear
Copy the two lines in the red box and set username = "root" password = "root" directly
<role rolename="manager-gui"/> <user username="tomcat" password="s3cret" roles="manager-gui"/>
Then click xshell, enter the tomcat installation directory (cd /usr/share/tomcat), enter the conf directory, and open tomcat users XML file, under the tag, add the following configuration:
<role rolename="manager-gui"/> <user username="root" password="root" roles="manager-gui"/>
To edit a file, you can click vi or vim to open the file and edit it directly
cd /usr/share/tomcat cd conf vim tomcat-users.xml
After clicking vim, press the i key on the keyboard to enter the editing state. Move the mouse over the last line and paste it directly
After editing, press ESC, enter: wq enter, save and exit
tomcat related commands
Stop tomcat service
systemctl stop tomcat
Restart tomcat
systemctl restart tomcat
Power on
systemctl enable tomcat
View tomcat status
systemctl status tomcat
Start tomcat
systemctl start tomcat
Communication QQ group: 779429633