tomcat连接数据库
这个实验要求要有论坛或者是商城系统
66主机 : nginx 、 tomcat 、 商城系统
67主机:tomcat 、商城系统
~~~~~~~~~~~~~~~~~~~~~
66主机操作:
【1】上传商城系统代码包:SLSaleSystem.tar.gz
[[email protected] ~]# tar xf SLSaleSystem.tar.gz -C /web/webapp/
[[email protected] ~]# ls /web/webapp/
index.jsp SLSaleSystem
[[email protected] ~]# ls /web/webapp/SLSaleSystem/
logs META-INF statics WEB-INF
[[email protected] ~]# vim /usr/local/tomcat8/conf/server.xml //添加路径
150 <Context docBase="/web/webapp/SLSaleSystem " path="" reloadable="flase">
保存退出
[[email protected] ~]# /usr/local/tomcat8/bin/shutdown.s
[[email protected] ~]# /usr/local/tomcat8/bin/startup.sh
[[email protected] ~]# tail -f /usr/local/tomcat8/logs/catalina.2019-11-22.log
67主机操作:
【1】上传商城系统代码包:SLSaleSystem.tar.gz
[[email protected] ~]# tar xf SLSaleSystem.tar.gz -C /web/webapp/
[[email protected] ~]# vim /usr/local/tomcat8/conf/server.xml //添加路径
150 <Context docBase="/web/webapp/SLSaleSystem " path="" reloadable="flase">
保存退出
[[email protected] ~]# /usr/local/tomcat8/bin/shutdown.s
[[email protected] ~]# /usr/local/tomcat8/bin/startup.sh
[[email protected] ~]# tail -f /usr/local/tomcat8/logs/catalina.2019-11-22.log
·····················
在浏览器中进行访问192.168.200.66:8080 192.168.200.67:8080
66主机操作:
[[email protected] ~]# yum -y install mariadb-server mariadb
[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# netstat -lnpt |grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 11512/mysqld
[[email protected] ~]# 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 [email protected]‘%‘ 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
[[email protected] ~]# mysql -uroot < slsaledb-2014-4-10.sql
[[email protected] ~]# 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
保存退出
[[email protected] ~]# /usr/local/tomcat8/bin/shutdown.sh
[[email protected] ~]# /usr/local/tomcat8/bin/startup.sh
[[email protected] ~]# 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主机操作
[[email protected] ~]# 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
保存退出
[[email protected] ~]# /usr/local/tomcat8/bin/shutdown.sh
[[email protected] ~]# /usr/local/tomcat8/bin/startup.sh
[[email protected] ~]# 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主机
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
[[email protected] ~]# nginx -t
[[email protected] ~]# killall -HUP nginx
在浏览器中进行访问192.168.200.66
出现400错误
[[email protected] ~]# 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;
}
结束!!
!
!!!!!!!!!!!!!!!!!!!!!!!!!
原文地址:https://www.cnblogs.com/elin989898/p/11914275.html