以下操作所需源码包和安装包(如有需要 自行下载) 链接:https://pan.baidu.com/s/10clk-z_BGrv4oe7LM--Epg?pwd=nkka 提取码:nkka |
拓扑图:
实验步骤:
部署tomcat
查看java的版本
[root@centos01 ~]# java -version
openjdk version "1.8.0_131"
查看Java的绝对路径
[root@centos01 ~]# which java
/usr/bin/java
[root@centos01 ~]# ls
apache-tomcat-8.5.50.tar.gz //需要有源码包
解压安装
[root@centos01 ~]# tar zxf ./apache-tomcat-8.5.50.tar.gz -C /usr/src/
[root@centos01 ~]# mv /usr/src/apache-tomcat-8.5.50/ /usr/local/tomcat
启动tomcat
[root@centos01 ~]# /usr/local/tomcat/bin/startup.sh
[root@centos01 ~]# netstat -utpln |grep java
tcp6 0 0 :::8080 :::* LISTEN 1487/java
win10访问:
http://192.168.100.10:8080 //可以访问
[root@centos01 ~]#
/usr/local/tomcat/bin/shutdown.sh //停止
[root@centos01 ~]# netstat
-utpln |grep java
win10访问:
http://192.168.100.10:8080 //不可以访问
Tomcat发布动态网站
[root@centos01 ~]# cp /usr/local/tomcat/conf/server.xml /usr/local/tomcat/conf/server.xml.bak
[root@centos01 ~]# vim /usr/local/tomcat/conf/server.xml
69 <Connector port="80" protocol="HTTP/1.1"
[root@centos01 ~]# /usr/local/tomcat/bin/startup.sh
[root@centos01 ~]# netstat -utpln |grep java
tcp6 0 0 :::80 :::* LISTEN 1840/java
win10访问:
192.168.100.10
[root@centos01 ~]# cd /usr/local/tomcat/webapps/
[root@centos01 webapps]# rz -E
[root@centos01 webapps]# mv jpress-v5.0.8.war jpress.war //重命名
win10访问
192.168.100.10/jpress
[root@centos01 webapps]# cd
部署数据库
[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos01 ~]# yum -y install mariadb mariadb-server
[root@centos01 ~]# systemctl start mariadb
[root@centos01 ~]# systemctl enable mariadb
[root@centos01 ~]# mysqladmin -uroot password
New password:
Confirm new password:
[root@centos01 ~]# mysql -uroot -ppwd@123
MariaDB [(none)]> create database jpress charset utf8;
MariaDB [(none)]> grant all on jpress.* to 'bbs'@'localhost' identified by 'pwd@123';
MariaDB [(none)]> exit
win10访问:
192.168.100.10/jpress
配置tomcat虚拟主机
创建虚拟主机网站根目录
[root@centos01 ~]# mkdir -p /www/bdqn
[root@centos01 ~]# mkdir -p /www/benet
[root@centos01 ~]# echo "www.bdqn.com" > /www/bdqn/index.jsp
[root@centos01 ~]# echo "www.benet.com" > /www/benet/index.jsp
[root@centos01 ~]# ls -R /www/
编辑host文件
[root@centos01 ~]# vim /etc/hosts
192.168.100.10 www.xsh.com www.bdqn.com www.benet.com
编辑tomcat主配置文件
[root@centos01 ~]# vim /usr/local/tomcat/conf/server.xml
148 <Host name="www.xsh.com" appBase="webapps"
149 unpackWARs="true" autoDeploy="true">
150 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
151 prefix="www.xsh.com_access_log" suffix=".txt"
152 pattern="%h %l %u %t "%r" %s %b" />
153 </Host>
154 <Host name="www.bdqn.com" appBase=""
155 unpackWARs="true" autoDeploy="true">
156 <Context docBase="/www/bdqn/" path="" reloadbable="fale" />
157 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
158 prefix="www.bdqn.com_access_log" suffix=".txt"
159 pattern="%h %l %u %t "%r" %s %b" />
160 </Host>
161 <Host name="www.benet.com" appBase=""
162 unpackWARs="true" autoDeploy="true">
163 <Context docBase="/www/benet/" path="" reloadbable="fale" />
164 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
165 prefix="www.benet.com_access_log" suffix=".txt"
166 pattern="%h %l %u %t "%r" %s %b" />
167 </Host>
[root@centos01 ~]# /usr/local/tomcat/bin/shutdown.sh //停止
[root@centos01 ~]# /usr/local/tomcat/bin/startup.sh //启动
[root@centos01 ~]# netstat -utpln |grep java
tcp6 0 0 :::80 :::* LISTEN 2195/java
tcp6 0 0 :::8009 :::* LISTEN 2195/java
win10修改hosts文件
192.168.100.10 www.xsh.com www.bdqn.com www.benet.com
客户端访问
配置tomcat管理控制台监控线程和tomcat的工作模式
修改访问tomcat管理控制台
切换云计算光盘
[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos01 ~]# tar zxf /mnt/apache-tomcat-7.0.54.tar.gz -C /usr/src/
[root@centos01 ~]# mv /usr/src/apache-tomcat-7.0.54/ /usr/local/tomcat
[root@centos01 ~]# /usr/local/tomcat/bin/startup.sh //启动
客户端访问
[root@centos01 ~]# /usr/local/tomcat/bin/shutdown.sh
[root@centos01 ~]# vim /usr/local/tomcat/conf/tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="admin" password="pwd@123" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>
</tomcat-users>
启动服务
[root@centos01 ~]# /usr/local/tomcat/bin/startup.sh
[root@centos01 ~]# netstat -utpln |grep java
tcp6 0 0 :::8080 :::* LISTEN 1445/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 1445/java
tcp6 0 0 :::8009 :::* LISTEN 1445/java
客户端访问
修改访问控制
[root@centos01 ~]# vim /usr/local/tomcat/webapps/manager/META-INF/context.xml
24 allow="192\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
[root@centos01 ~]# /usr/local/tomcat/bin/shutdown.sh //停止
[root@centos01 ~]# /usr/local/tomcat/bin/startup.sh //启动
Jmeter压力测试
Win10客户端必须安装jdk
运行jemter(bin下)
jemter.bat
优化tomcat线程
修改主配置文件
[root@centos01 ~]# vim /usr/local/tomcat/conf/server.xml
70 <Connector port="8080" protocol="HTTP/1.1"
71 cnotallow="20000"
72 redirectPort="8443"
73 maxTheads="9000"
74 minspareTheads="2000"
75 acceptCount="2000"
76 />
启动服务
[root@centos01 ~]# /usr/local/tomcat/bin/startup.sh
JVM性能调优
修改最大内存
关机
[root@centos01 ~]# init 0
内存调到4GB
修改配置文件
[root@centos01 ~]# vim /usr/local/tomcat/bin/catalina.sh
235 JAVA_OPTS="-server -Xms1024m -Xmx4096m -XX:NewSize=50m -XX:MaxNewSize=100m"
[root@centos01 ~]# /usr/local/tomcat/bin/startup.sh
[root@centos01 ~]# netstat -utpln |grep java
tcp6 0 0 :::8080 :::* LISTEN 1377/java
tcp6 0 0 :::8009 :::* LISTEN 1377/java
win10 验证
压力测试