[Linux]javaEE articles: Installing Tomcat

javaEE install Tomcat

Skill: In linux, the source installation, the default installation path is: /usr/local. After the installation is completed, a soft link of the software is generally created, and another alias is used, ignoring the version number; the advantage of this is that after the version is updated, the configuration of the environment variable can ignore the file name, reducing the configuration file path because each update is changed. Transform.

Commands used:

tar -zxvf apache-tomcat-7.0.70.tar.gz: Unzip apache-tomcat-7.0.70.tar.gz in the current directory

ln -s ./apache-tomcat-7.0.70 tomcat: Create a soft link of apache-tomcat-7.0.70 as tomcat

vim tomcatd.service: Enter the tomcatd service; note that it is in the /lib/systemd/systemdirectory

systemctl daemon-reload: service reload

systemctl status iptablesOr systemctl status firewalld: View Firewall Status

systemctl status tomcatd: View tomcat service status
systemctl stop tomcatd: stop tomcat service

vim /etc/sysconfig/iptables: Enter the firewall configuration file

systemctl restart iptables: restart the firewall

iptables -nL: View the information status of the chain in the firewall

./startup.sh &: run tomcat in the background; note that the & behind it stands for running in the background. Will not be stopped with the ctrl+C shortcut

source /etc/profileOr ./etc/profile: reload the /etc/profile file

The principle of firewall iptables under linux platform (transfer)

Basic application tutorial of iptables firewall on Linux


installation steps
1. Upload the local installation package to the linux system

Note: We put the installation package /usr/localunder the path

write picture description here

2. Unzip tomcat

[root@localhost local]# tar -zxvf apache-tomcat-7.0.70.tar.gz

Confirm whether the decompression is successful

[root@localhost local]# ll
total 193796
drwxr-xr-x. 9 root root       160 May  4 18:34 apache-tomcat-7.0.70
-rw-r--r--. 1 root root   8924465 May  3 14:08 apache-tomcat-7.0.70.tar.gz
3. Create soft links

[root@localhost local]# ln -s /usr/local/apache-tomcat-7.0.70 tomcat

Confirm whether the creation is successful:

[root@localhost local]# ll
total 193796
drwxr-xr-x. 9 root root       187 May  4 18:37 apache-tomcat-7.0.70
-rw-r--r--. 1 root root   8924465 May  3 14:08 apache-tomcat-7.0.70.tar.gz
lrwxrwxrwx. 1 root root        31 May  4 18:38 tomcat -> /usr/local/apache-tomcat-7.0.70
4. Enter /lib/systemd/system to configure the tomcat service.

[root@wcl system]# cd /lib/systemd/system: Enter the system configuration service; note that if there is no tomcatd.service, then you need to manually create this file, if there is, modify the [Service] file directly;

All in tomcatd.service:

[Unit]  
Description=Tomcat7  
After=syslog.target network.target remote-fs.target nss-lookup.target  

[Service]  
Type=forking  
Environment='JAVA_HOME=/opt/java/jdk1.7.0_79'  
Environment='CATALINA_PID=/opt/tomcat/bin/tomcat.pid'  
Environment='CATALINA_HOME=/opt/tomcat/'  
Environment='CATALINA_BASE=/opt/tomcat/'  
#Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'  

WorkingDirectory=/opt/tomcat/ 

ExecStart=/opt/tomcat/bin/startup.sh  
ExecReload=/bin/kill -s HUP $MAINPID  
ExecStop=/bin/kill -s QUIT $MAINPID  
PrivateTmp=true  

[Install]  
WantedBy=multi-user.target 

Note that this file must be executable

chmod 755 tomcatd.service

Note: tomcat only needs to configure the tomcatd.service file in this /lib/systemd/system folder; it is not necessary to configure the /etc/profile and catalina.sh files under tomcat as mentioned on the Internet;

/lib/systemd/system: The main startup script settings for each service, somewhat similar to the previous files under /etc/init.d;

Brother Bird's Linux Private Kitchen

5. Start tomcat

systemctl status tomcatd: View tomcat service status;

systemctl start tomcatd: start the tomcat service

[root@localhost ~]# systemctl status tomcatd
● tomcatd.service - Tomcat7
   Loaded: loaded (/usr/lib/systemd/system/tomcatd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@localhost ~]# systemctl start tomcatd
[root@localhost ~]# systemctl status tomcatd
● tomcatd.service - Tomcat7
   Loaded: loaded (/usr/lib/systemd/system/tomcatd.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2018-05-04 20:52:25 CST; 2s ago
  Process: 4935 ExecStart=/usr/local/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
 Main PID: 4942 (java)
   CGroup: /system.slice/tomcatd.service
           └─4942 /usr/local/java//bin/java -Djava.util.logging.config.file=/usr/local/tomcat/
           /conf/logging.properties -Djava.util.loggin...

May 04 20:52:25 localhost.localdomain systemd[1]: Starting Tomcat7...
May 04 20:52:25 localhost.localdomain startup.sh[4935]: Tomcat started.
May 04 20:52:25 localhost.localdomain systemd[1]: Started Tomcat7.

At this time our tomcat has been started;

Open a browser at the command line

[root@localhost ~]# curl 'localhost:8080' 

<!DOCTYPE html>
<html lang="en">
    <head>
//... ...省略剩余内容   

or

Access tomcat on the virtual machine on the computer; at this time we need to check whether the firewall is open to port 8080;

We enter the firewall configuration file

vim /etc/sysconfig/iptables

Write the following content to the "/etc/sysconfig/iptables"` file.

*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -p tcp -m tcp --dport 80 -m connlimit --connlimit-above 51200 --connlimit-mask 32 -j DROP
-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 11 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT       ##将8080端口开放

-A INPUT -j REJECT --reject-with icmp-port-unreachable
-A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
COMMIT 

Note: If you have this file on another server, you can copy it directly with the command: scp /etc/sysconfig/iptables 192.168.0.84:/etc/sysconfig/==> scp 本机路径文件 目标IP:目标路径;
if you copy this file manually, it may cause tomcat to report an error later because of spaces. Be careful, delete the extra spaces after! ! !

Then save and exit, and reload the service: systemctl daemon-reload;

6. Start the firewall

[root@localhost ~]# systemctl status iptables: View firewall status

[root@localhost ~]# systemctl restart iptables: restart firewall

7. The native browser accesses tomcat on the linux system

http://192.168.0.84:8080/

write picture description here


Finally successfully installed! ! !
During the installation process, you may encounter various problems that will catch you off guard. In order to install successfully, you must calm down and overcome them one by one.
Remember to ask Google if you don't understand!!!

Guess you like

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