centos java+tomcat environment configuration

centos java+tomcat environment configuration

 

1. Install the java environment

It is relatively simple to install the java environment on centos7. I installed the smallest centos7 through virtualBox. After the installation is completed, I set the IP to be able to access the external network. In my last article, I described in detail how to set the IP to access the external network through centos7. Well, without further ado, let’s go to the command:
yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
The yum command needs to be connected to the Internet. The operation is to download jdk8 from the Internet to your centos7 and install it to the default directory.
We also need to set JAVA_HOME, CLASSPATH, PATH environment variables when developing with eclipse in Windows system. The same is the same in centos7. After installation,
Add the following three lines to /etc/profile:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el7_3.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
After saving and closing, execute: source /etc/profile # Let the settings take effect immediately.
Here is a little explanation that the /etc/profile file is the environment variable configuration file of centos7. This file is the environment variable setting that each user will run when they log in. If it is only modified, it will not take effect immediately. It will take effect when you need to log in again. The command: source /etc/profile can make the previous settings take effect immediately.
At this point, the java environment is installed, the same as under windows, run the execution command: java -version
The following message will appear:
It means that the java environment is installed successfully!

Second, install the tomcat environment

Generally speaking, this is relatively simple to download the compressed package, unzip it, and run it. Same as Windows. Specific steps are as follows:
Download the Tomcat compressed package apache-tomcat-8.5.13.tar.gz under linux
Put it under home (the directory is optional, you can create a new folder yourself) Unzip it
Execute the command: tar -zxvf apache-tomcat-8.5.13.tar.gz
Then there will be an apache-tomcat-8.5.13 folder. In fact, this tomcat is equivalent to a successful installation. Isn't it very simple, but it needs some operations to run it.
1. Start tomcat
Execute the command: /home/apache-tomcat-8.5.13/bin/startup.sh
2. Develop port 8080
firewall-cmd --zone=public --add-port=8080/tcp --permanent
You may encounter: firewalld is not running error message
Check the firewalld status through systemctl status firewalld and find that the current status is dead, that is, the firewall is not turned on.
Open the firewall through systemctl start firewalld, and it is successfully opened without any prompts.
If you want to turn off the firewall settings, you may turn off the function through the command systemctl stop firewalld.
Let's talk about the meaning of this sentence, because centos7 has changed the firewall policy, so use this method to open the port
--zone #scope
--add-port=8080/tcp #Add port, the format is: port/communication protocol
--permanent #Permanent effect, invalid after restart without this parameter
Restart the firewall: firewall-cmd --reload
3. Verify
It can be accessed under Windows by entering the ip address of the virtual machine, for example: 192.168.1.100:8080
The welcome page of tomcat is displayed, indicating that tomcat has run successfully.
Third, deploy the JavaWeb project
The war package is used in linux for deployment, so we need to package the project into a war package
Then copy the generated war package to centos.
The tomcat deployment JavaWeb project is divided into the following steps:
1. Delete all files in the ROOT folder of tomcat according to the directory
2. Copy the war package to the ROOT file and unzip it: jar -xvf xxxx.war;
3. End all java processes: ps -e|grep java|awk '{print "kill -9 "$1}'|sh
4. Start tomcat: sh tomcat directory/bin/startup.sh; or enter the bin directory of tomcat and execute: ./startup.sh

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324687216&siteId=291194637