Tomcat部署SL商城系统并连接MariaDB数据
这个实验要求要有论坛或者是商城系统
66主机 : nginx 、 tomcat 、 商城系统
67主机:tomcat 、商城系统
~~~~~~~~~~~~~~~~~~~~~
66主机操作:
【1】上传商城系统代码包:SLSaleSystem.tar.gz
[root@localhost ~]# tar xf SLSaleSystem.tar.gz -C /web/webapp/
[root@localhost ~]# ls /web/webapp/
index.jsp SLSaleSystem
[root@localhost ~]# ls /web/webapp/SLSaleSystem/
logs META-INF statics WEB-INF
[root@localhost ~]# vim /usr/local/tomcat8/conf/server.xml //添加路径
150 <Context docBase="/web/webapp/SLSaleSystem " path="" reloadable="flase">
保存退出
[root@localhost ~]# /usr/local/tomcat8/bin/shutdown.s
[root@localhost ~]# /usr/local/tomcat8/bin/startup.sh
[root@localhost ~]# tail -f /usr/local/tomcat8/logs/catalina.2019-11-22.log
【1】上传商城系统代码包:SLSaleSystem.tar.gz
[root@localhost ~]# tar xf SLSaleSystem.tar.gz -C /web/webapp/
[root@localhost ~]# vim /usr/local/tomcat8/conf/server.xml //添加路径
150 <Context docBase="/web/webapp/SLSaleSystem " path="" reloadable="flase">
保存退出
[root@localhost ~]# /usr/local/tomcat8/bin/shutdown.s
[root@localhost ~]# /usr/local/tomcat8/bin/startup.sh
[root@localhost ~]# tail -f /usr/local/tomcat8/logs/catalina.2019-11-22.log
·····················
在浏览器中进行访问192.168.200.66:8080 192.168.200.67:8080
66主机操作:
[root@localhost ~]# yum -y install mariadb-server mariadb
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# netstat -lnpt |grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 11512/mysqld
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database slsaledb;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on slsaledb.* to admin@'%' identified by '123456' ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
导入数据文件 slsaledb-2014-4-10.sql
[root@localhost ~]# mysql -uroot < slsaledb-2014-4-10.sql
[root@localhost ~]# vim /web/webapp/SLSaleSystem/WEB-INF/classes/jdbc.properties
url=jdbc\:mysql\://192.168.200.66\:3306/slsaledb?useUnicode\=true&characterEncoding\=UTF-8
uname=admin
保存退出
[root@localhost ~]# /usr/local/tomcat8/bin/shutdown.sh
[root@localhost ~]# /usr/local/tomcat8/bin/startup.sh
[root@localhost ~]# tail -f /usr/local/tomcat8/logs/catalina.2019-11-23.log
23-Nov-2019 10:57:43.916 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 16125 ms
---------------
--67主机操作
[root@localhost ~]# vim /web/webapp/SLSaleSystem/WEB-INF/classes/jdbc.properties
driverClassName=com.mysql.jdbc.Driver
url=jdbc\:mysql\://192.168.200.66\:3306/slsaledb?useUnicode\=true&characterEncoding\=UTF-8
uname=admin
password=123456
minIdle=10
maxIdle=50
initialSize=5
maxActive=100
maxWait=100
removeAbandonedTimeout=180
removeAbandoned=true
保存退出
[root@localhost ~]# /usr/local/tomcat8/bin/shutdown.sh
[root@localhost ~]# /usr/local/tomcat8/bin/startup.sh
[root@localhost ~]# tail -f /usr/local/tomcat8/logs/catalina.2019-11-23.log
23-Nov-2019 10:55:23.042 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 15720 ms
=====
在浏览器中访问192.168.200.66:8080 登录密码进入
在访问192.168.200.67:8080 登录密码进入
66主机
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
[root@localhost ~]# nginx -t
[root@localhost ~]# killall -HUP nginx
在浏览器中进行访问192.168.200.66
出现400错误
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
在location中添加
location / {
root html;
index index.html index.htm;
proxy_pass http://tomcat_pool;
proxy_set_header Host $http_host; //转向头部
}
在进行访问
另外添加以下内容
upstream tomcat_pool{
ip_hash; //固定IP
server 192.168.200.66:8080 weight=1;
server 192.168.200.67:8080 weight=1;
}
结束!!
!
!!!!!!!!!!!!!!!!!!!!!!!!!