Tomcat是一款轻量级应用服务器。
JDK官方下载地址
[root@localhost ~]# tar xf jdk-8u261-linux-x64.tar.gz -C /usr/src/
[root@localhost ~]# ln -s /usr/src/jdk1.8.0_261/ /usr/local/sbin/jdk
[root@localhost ~]# sed -i.ori '$a export JAVA_HOME=/usr/local/sbin/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar' /etc/profile
[root@localhost ~]# source /etc/profile
[root@localhost ~]# java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)
[root@localhost ~]# wget http://apache.otenet.gr/dist/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz
[root@localhost ~]# tar xf apache-tomcat-9.0.37.tar.gz -C /usr/src/
[root@localhost ~]# ln -s /usr/src/apache-tomcat-9.0.37/ /usr/local/bin/tomcat
[root@localhost ~]# echo 'export TOMCAT_HOME=/usr/local/bin/tomcat' >>/etc/profile
[root@localhost ~]# source /etc/profile
[root@localhost ~]# chown -R root.root /usr/local/sbin/jdk/ /usr/local/bin/tomcat/ //可更改为低权限用户
[root@localhost ~]# tail -4 /etc/profile
export JAVA_HOME=/usr/local/bin/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
export TOMCAT_HOME=/usr/local/bin/tomcat
[root@localhost ~]# cd /usr/local/bin/tomcat/
[root@localhost tomcat]# ls
bin CONTRIBUTING.md logs RELEASE-NOTES webapps
BUILDING.txt lib NOTICE RUNNING.txt work
conf LICENSE README.md temp
[root@localhost tomcat]# ll conf/
总用量 232
-rw------- 1 root root 12873 7月 1 04:14 catalina.policy
-rw------- 1 root root 7262 7月 1 04:14 catalina.properties
-rw------- 1 root root 1400 7月 1 04:14 context.xml
-rw------- 1 root root 1149 7月 1 04:14 jaspic-providers.xml
-rw------- 1 root root 2313 7月 1 04:14 jaspic-providers.xsd
-rw------- 1 root root 4144 7月 1 04:14 logging.properties
-rw------- 1 root root 7588 7月 1 04:14 server.xml
-rw------- 1 root root 2164 7月 1 04:14 tomcat-users.xml
-rw------- 1 root root 2558 7月 1 04:14 tomcat-users.xsd
-rw------- 1 root root 172359 7月 1 04:14 web.xml
[root@localhost ~]# ls /usr/local/bin/tomcat/webapps/ROOT/
asf-logo-wide.svg bg-upper.png tomcat.css tomcat.svg
bg-button.png favicon.ico tomcat.gif WEB-INF
bg-middle.png index.jsp tomcat.png
bg-nav.png RELEASE-NOTES.txt tomcat-power.gif
[root@localhost ~]# /usr/local/bin/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/bin/tomcat
Using CATALINA_HOME: /usr/local/bin/tomcat
Using CATALINA_TMPDIR: /usr/local/bin/tomcat/temp
Using JRE_HOME: /usr/local/sbin/jdk
Using CLASSPATH: /usr/local/bin/tomcat/bin/bootstrap.jar:/usr/local/bin/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@localhost ~]# netstat -anpt | grep 8080
tcp6 0 0 :::8080 :::* LISTEN 4006/java
[root@localhost ~]# /usr/local/bin/tomcat/bin/shutdown.sh
配置文件 | 说明 |
---|---|
catalina.policy | 权限控制配置文件 |
catalina.properties | Tomcat 属性配置文件 |
context.xml | 上下文配置文件 |
logging.properties | 日志log相关配置文件 |
server.xml | 主配置文件 |
tomcat-users.xml | manager-gui管理用户配置文件 |
web.xml | Tomcat 的servlet、servlet—mappingx filter, MIME等相关配置 |
[root@localhost ~]# cd /usr/local/bin/tomcat/webapps/ROOT/
[root@localhost ROOT]# vim test.jsp
<%@ page language= "java" import= "java.util.*" pageEncoding= "UTF-8"%>
<html>
<head>
<title>JSP test1 page</title>
</head>
<body>
<% out.println("www.tomcat-test1.com");%>
</body>
[root@localhost ~]# cd /usr/local/bin/tomcat/work/Catalina/localhost/ROOT/
[root@localhost ROOT]# cd org/apache/jsp/
[root@localhost jsp]# ls
index_jsp.class index_jsp.java test_jsp.class test_jsp.java
[root@localhost jsp]# cat test_jsp.java //查看转换后的文件
......
out.write("\n");
out.write("\n");
out.write(" \n");
out.write(" JSP test1 page \n");
out.write(" \n");
out.write("\n");
out.write(" ");
out.println("www.tomcat-test1.com");
out.write("\n");
out.write("\n");
out.write("\n");
......
[root@localhost ~]# mkdir -p /web/webapps/myapp
[root@localhost ~]# vim /web/webapps/myapp/index.jsp
<%@ page language= "java" import= "java.util.*" pageEncoding= "UTF-8"%>
<html>
<head>
<title>JSP test2 page</title>
</head>
<body>
<% out.println("www.tomcat-test2.com");%>
</body>
[root@localhost ~]# cp -r /web/webapps/myapp/ /usr/local/bin/tomcat/webapps/
定义一个虚拟主机,在Tomcat配置文件Host段下方进行添加context段,将网站文件路径指向已经建立的/web/webapp1/
[root@localhost ~]# mkdir /web/webapps/Root
[root@localhost ~]# vim /web/webapps/Root/test.jsp
<%@ page language= "java" import= "java.util.*" pageEncoding= "UTF-8"%>
<html>
<head>
<title>JSP test3 page</title>
</head>
<body>
<% out.println("www.tomcat-test3.com");%>
</body>
</html>
[root@localhost ~]# vim /usr/local/bin/tomcat/conf/server.xml
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/web/webapp1" path="" reloadable="false">
</Context>
[root@localhost ~]# /usr/local/bin/tomcat/bin/shutdown.sh
[root@localhost ~]# /usr/local/bin/tomcat/bin/startup.sh
参数 | 说明 |
---|---|
docBase | web应用的文档基准目录 |
reloadable | 设置监视“类” 是否变化 |
path=“” | 设置默认"类“ |
[root@localhost ~]# vim /usr/local/bin/tomcat/conf/server.xml
<Server port="8005" shutdown="8371728193424254">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
[root@localhost ~]# vim /usr/local/bin/tomcat/conf/tomcat-users.xml
......
-->
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="lisi" password="123456" roles="manager-gui,admin-gui"/>
</tomcat-users>
[root@localhost ~]# vim /usr/local/bin/tomcat/webapps/manager/META-INF/context.xml
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.*" />
......
[root@localhost ~]# vim /usr/local/bin/tomcat/webapps/host-manager/META-INF/context.xml
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.*" />
[root@localhost ~]# /usr/local/bin/tomcat/bin/shutdown.sh
[root@localhost ~]# /usr/local/bin/tomcat/bin/startup.sh
[root@web ~]# wget https://gitee.com/JPressProjects/jpress/attach_files/489467/download/jpress-v3.3.0.war
[root@web ~]# mv jpress-v3.3.0.war /usr/local/bin/tomcat/webapps/jpress.war
[root@web ~]# ls /usr/local/bin/tomcat/webapps/
docs examples host-manager jpress jpress.war manager ROOT
[root@web ~]# mkdir -p /server/soft
[root@web ~]# mv mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz /server/soft/
[root@web ~]# yum -y remove mariadb-libs.x86_64
[root@web ~]# yum -y install libaio-devel
[root@web ~]# cd /server/soft/
[root@web soft]# tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@web soft]# ln -s /server/soft/mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
[root@web soft]# useradd -s /sbin/nologin mysql
[root@web soft]# echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
[root@web soft]# source /etc/profile
[root@web soft]# mysql -V
mysql Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using EditLine wrapper
[root@web soft]# mkdir -p /data/mysql/data
[root@web soft]# chown -R mysql.mysql /usr/local/mysql/
[root@web soft]# chown -R mysql.mysql /data
[root@web soft]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
[root@web soft]# cat >/etc/my.cnf <
> [mysqld]
> user=mysql
> basedir=/usr/local/mysql
> datadir=/data/mysql/data
> socket=/tmp/mysql.sock
> server_id=6
> port=3306
> [mysql]
> socket=/tmp/mysql.sock
> EOF
[root@web soft]# cat >/etc/systemd/system/mysqld.service <
> [Unit]
> Description=MySQL Server
> Documentation=man:mysqld(8)
> Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
> After=network.target
> After=syslog.target
> [Install]
> WantedBy=multi-user.target
> [Service]
> User=mysql
> Group=mysql
> ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
> LimitNOFILE = 5000
> EOF
[root@web soft]# systemctl start mysqld
[root@web soft]# netstat -anpt | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 31753/mysqld
[root@web ~]# mysql
mysql> create database jpress DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on jpress.* to jpress@'192.168.1.%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@sweb01 ~]# cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
[root@sweb01 ~]# yum -y install nginx
[root@sweb01 ~]# vim /etc/nginx/conf.d/proxy.conf
upstream java {
server 192.168.1.10:8081 weight=1;
server 192.168.1.10:8082 weight=1;
}
server {
listen 80;
server_name www.study.com;
root html;
index index.html index.htm;
location / {
proxy_pass http://java;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[root@sweb01 /etc/nginx/conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@sweb01 ~]# systemctl start nginx
[root@web ~]# vim /usr/local/bin/tomcat/conf/server.xml
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="6000" enableLookups="false" acceptCount="800"
redirectPort="8443" />
[root@web ~]# find / -name "java.security"
/usr/src/jdk1.8.0_261/jre/lib/security/java.security
[root@web ~]# vim /usr/src/jdk1.8.0_261/jre/lib/security/java.security
securerandom.source=file:/dev/urandom
[root@web ~]# mkdir /jpress
[root@web ~]# mv /jpress.war /jpress
[root@web ~]# cd /jpress/
[root@web jpress]# /usr/src/jdk1.8.0_261/bin/jar -xf jpress.war
[root@web jpress]# ls
jpress.war META-INF robots.txt static templates WEB-INF
[root@web jpress]# /usr/src/jdk1.8.0_261/bin/jar -cfM0 jpress.war ./
[root@web jpress]# ls
jpress.war META-INF robots.txt static templates WEB-INF