准备环境
三台虚拟机
192.168.1.120
192.168.1.122
192.168.1.131
三台虚拟机关闭防火墙 、查看光盘 、检测yun创库
查看JDK是否安装
[root@localhost ~]# java -version
openjdk version "1.8.0_161" //这是系统自带的rpm方式安装
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
卸载rpm方式安装的jdk
方法一:
[root@localhost ~]# which java
/usr/bin/java
[root@localhost ~]# rm -rf /usr/bin/java
方法二:
[root@localhost ~]# rpm -qa | grep -i openjdk
java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.2.el7.x86_64
java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
[root@localhost ~]# rpm -e java-1.7.0-openjdk
[root@localhost ~]# rpm -e java-1.7.0-openjdk-headless
[root@localhost ~]# rpm -e java-1.8.0-openjdk --nodeps
[root@localhost ~]# rpm -e java-1.8.0-openjdk-headless
[root@localhost ~]# rpm -qa | grep -i openjdk
JDK安装
[root@localhost ~]# tar xf jdk-8u191-linux-x64.tar.gz
[root@localhost ~]# mv jdk1.8.0_191/ /usr/local/java
[root@localhost ~]# vim /etc/profile
export JAVA_HOME=/usr/local/java #设置java跟目录
export PATH=$PATH:$JAVA_HOME/bin #在PATH环境变量中添加java跟目录的bin子目录
[root@localhost ~]# source /etc/profile
[root@localhost ~]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
第一台安装tomcat (192.168.1.123)
先将apache tomcat 的源码包拖入虚拟机
解压
[root@localhost ~]# tar xf apache-tomcat-8.5.40.tar.gz
解压后生成apache-tomcat-8.5.16文件夹,将该文件夹移动到/usr/local下,并改名为tomcat
[root@localhost ~]# mv apache-tomcat-8.5.40 /usr/local/tomcal
启动
[root@localhost ~]# /usr/local/tomcal/bin/startup.sh
查看端口
[root@localhost ~]# netstat -lnpt | grep 8080
浏览器访问测试 http://192.168.1.120:8080
修改主配置文件
[root@localhost ~]# cd /usr/local/tomcal//conf/
server.xml 主配置文件
修改配置文件
[root@bogon conf]# vim server.xml
加入以下红色内容表示自定义主页 /web/webapp 是路径
unpackWARs="true" autoDeploy="true">
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
创建自定义路径
[root@localhost conf]# mkdir -p /web/webapp
编写首页文件
[root@localhost conf]# vim /web/webapp/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
JSP test page <% out.println("Welcome to test site,http://www.test1.com");%> #(首页内容)
做完配置文件先关闭服务
[root@bogon conf]# /usr/local/tomcal//bin/shutdown.sh
再开启服务
[root@bogon conf]# /usr/local/tomcal//bin/startup.sh
再去浏览器访问测试 http://192.168.1.120:8080
就会变成我们写入的首页文件
查看测试页面(生产环境当中建议删除)
[root@bogon conf]# ls ../webapps/ROOT/
备份时间戳命令 【由于配置文件我们已经进行过修改这一步不需要在做】
[root@localhost ~]# cp /usr/local/tomcal/conf/server.xml{,.-$(date +%F)}
[root@localhost ~]# vim /usr/local/tomcat8/conf/server.xml
148
149 unpackWARs="true" autoDeploy="true">
150
151
第二台安装tomcat (192.168.1.120)
【步骤通第一台安装一样在此不做过多演示】
第三台安装nginx
[root@nginx ~]# yum -y install pcre-devel zlib-devel openssl-devel lrzsz
创建 nginx 管理用户
[root@nginx ~]# useradd -M -s /sbin/nologin nginx
将nginx源码包拖进虚拟机
解压
[root@nginx ~]# tar xf nginx-1.16.0.tar.gz
[root@nginx ~]# cd nginx-1.16.0/
[root@nginx nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-file-aio --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module && make && make install
--prefix=/usr/local/nginx //指定安装目录
--user=nginx --group=nginx //指定运行的用户和组
--with-file-aio //启用文件修改支持
--with-http_stub_status_module //启用状态统计
--with-http_ssl_module //启用ssl模块
--with-http_flv_module //启用flv模块,提供寻求内存使用基于时间的偏移量文件
--with-http_gzip_static_module //启用gzip静态压缩
如果安装过程中还需要其它依赖可自行选择安装
yum -y install gcc-c++
yum -y install pcre-devel
yum -y install zlib-devel
配置nginx.conf
[root@bogon nginx-1.16.0]# cp /usr/local/nginx/conf/nginx.conf{,.bak}
[root@bogon nginx-1.16.0]# vim /usr/local/nginx/conf/nginx.conf
在第一行写入 nginx
user nginx;
worker_processes 1;
为了nginx调动tomcat写入
upstream tomcat {
server 192.168.1.120:8080 weight=1;
server 192.168.1.122:8080 weight=1;
}
location ~ \.jsp$ {
proxy_pass http://tomcat;
}
查看配置文件配置是否出错
[root@bogon nginx-1.16.0]# /usr/local/nginx/sbin/nginx -t
启动nginx
[root@bogon nginx-1.16.0]# /usr/local/nginx/sbin/nginx
退出后重启nginx
killall -HUP nginx
查看80端口启动情况
netstat -anpt |grep :80
ps aux | grep nginx | grep -v grep
浏览器访问ip进行查看 192.168.1.131
浏览器访问验证 http://192.168.1.131/index.jsp
点击刷新回来回轮训
在第一台虚拟机配置
解压
tar xf SLSaleSystem.tar.gz -C /web/webapp/
ls /web/webapp/SLSaleSystem/
vim /usr/local/tomcal/conf/server.xml
添加红色字样
SLSaleSystem" path="" reloadable="flase" >
/usr/local/tomcal/bin/shutdown.sh
/usr/local/tomcal/bin/startup.sh
浏览器访问第一台机ip 192.168.1.120:8080
在第二台机上配置
[root@localhost ~]# yum -y install mariadb-server mariadb
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysql
MariaDB [(none)]> create database slsaledb;
MariaDB [(none)]> grant all on slsaledb.* to admin@'%' identified by '123456';
MariaDB [(none)]> flush privileges;
上传文件
[root@localhost ~]# mysql -uroot < slsaledb-2014-4-10.sql
安装SLSaleSystem
解压 连接
[root@elk-node1 ~]# tar xf SLSaleSystem.tar.gz -C /web/webapp/
[root@elk-node1 ~]# ls /web/webapp/SLSaleSystem/
[root@localhost ~]# vim /web/webapp/SLSaleSystem/WEB-INF/classes/jdbc.properties
修改红色字样内容
driverClassName=com.mysql.jdbc.Driver
url=jdbc\:mysql\://192.168.1.122\: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
用户密码admin、123456