目录
一、实验拓扑
二、部署mysql
三、部署Tomcat
四、配置NGINX
五、 配置NGINX的双机热备提高可用性
一、实验拓扑
二、部署mysql
官网下载地址https://dev.mysql.com/downloads/mysql/
1、移除mariadb,安装所需应用
mysql-8.1.0 社区版 安装说明官网下载地址https://dev.mysql.com/downloads/mysql/1、yum remove mariadb
2、yum -y install liaio net-tools
3、解压安装包,进入安装包执行以下命令
yum install -y perl-Module-Install.noarch
yum install perl-Test-*.noarch -y
rpm -ivh mysql-community-common-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.1.0-1.el7.x86_64.rpm
yum install -y perl-Module-Install.noarch
rpm -ivh mysql-community-common-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.1.0-1.el7.x86_64.rpm
yum install perl-Test-*.noarch -y
rpm -ivh mysql-community-libs-8.1.0-1.el7.x86_64.rpm
yum remove mariadb-libs.x86_64 -y
rpm -ivh mysql-community-libs-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-debuginfo-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.1.0-1.el7.x86_64.rpm rpm -ivh mysql-community-server-debug-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.1.0-1.el7.x86_64.rpm
yum install -y openssl
rpm -ivh mysql-community-devel-8.1.0-1.el7.x86_64.rpm
yum install -y openssl*
rpm -ivh mysql-community-devel-8.1.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-test-8.1.0-1.el7.x86_64.rpm
yum install -y perl*
rpm -ivh mysql-community-test-8.1.0-1.el7.x86_64.rpm
4、启动MYSQL
systemctl start mysqld
5、查看临时密码
cat /var/log/mysqld.log | grep password
6、登录MYSQL
mysql -u root -p
7、修改密码
alter user 'root'@'localhost' identified by '123456.Com';
flush privileges
创建库jx
create database jx;
8、远程登录用户创建
create user 'hy'@'%' identified by '123456.Com';
grant all privileges on 库名.表明 to 'hy'@'%' with grant options;
flush privileges;
9、命令行操作mysql
mysql -u root -p -e " show databases;"
2、同理在192.168.115.136上安装mysql并验证远程登录账户
mysql -u hy -p'123456.Com' -h 192.168.115.131 -P 3306 -e "show databases;"
三、部署Tomcat
在192.168.115.136/192.168.115.140部署tomcat
java环境Java SE | Oracle Technology Network | Oracle
Tomcat Apache Tomcat® - Welcome!
Java环境部署
1、which Java 查看Java的路径Java -version 查看Java版本如果版本达不到我们的安装要求就使用rm -rf 配合which java 删除现有版本2、直接使用rpm -ivh jdk-20_linux-x64_bin.rpm 安装即可安装完成后查看which JavaJava -versionTomcat部署
Tomcat下载地址 https://tomcat.apache.org/
1、解压tar -xf apache-tomcat-9.0.80.tar.gzmv apache-tomcat-9.0.80 /usr/local/tomcat
2、建立软联建启动命令 ln -s /usr/local/tomcat/bin/startup.sh /usr/bin/catup停止命令 ln -s /usr/local/tomcat/bin/shutdown.sh /usr/bin/catdown
启动 catup
访问测试,ok
四、配置NGINX
192.168.115.141/192.168.115.142安装NGINX配置动静分离,负载均衡
1、安装
yum -y install epel-release.noarch
yum -y install nginx
2、配置
vim /etc/nginx/nginx.conf
##在http字段插入
upstream tomcat {server 192.168.115.136:8080;server 192.168.115.140:8080;}
##在server字段插入
location ~ \.jsp$ { ####这里是jspproxy_pass http://tomcat;proxy_set_header Host $host;}location / {root /usr/share/nginx/html;index index.html;}
###保存退出重启服务
3、测试
分别访问192.168.115.141/192.168.115.142
静态页面
动态页面
五、 配置NGINX的双机热备提高可用性
yum -y install keepalived
vim /etc/keepalived/keepalived.conf
#######################配置####################################
############################################################
! Configuration File for keepalivedglobal_defs {notification_email {acassen@firewall.locfailover@firewall.locsysadmin@firewall.loc}notification_email_from Alexandre.Cassen@firewall.locsmtp_server 192.168.200.1smtp_connect_timeout 30router_id LVS_DEVEL ###从的编号要改动一下 LVS_DEVEL1vrrp_skip_check_adv_addr#vrrp_strictvrrp_garp_interval 0vrrp_gna_interval 0
}vrrp_instance VI_1 {state MASTER ###从改为BACKUPinterface ens33 ###网卡名virtual_router_id 51priority 100 ###从的优先级要比主低advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {192.168.115.200 ###VIP用来访问的虚拟IP}
}
virtual_server 192.168.115.200 8080 { ###vip对应的真是IP 在下面delay_loop 6lb_algo rr persistence_timeout 50protocol TCPreal_server 192.168.115.136 8080 { ###这是Tomcat服务器的IPweight 1HTTP_GET {url { path /testurl/test.jsp}
url { path /testurl2/test.jsp}url { path /testurl3/test.jsp}connect_timeout 3nb_get_retry 3delay_before_retry 3}}real_server 192.168.115.140 8080 { ###这是Tomcat服务器的IPweight 1HTTP_GET {url { path /testurl/test.jsp}url { path /testurl2/test.jsp
}connect_timeout 3nb_get_retry 3delay_before_retry 3}}
}
启动keepalived
systemctl start keepalived.service
看看主调器的IP
现在模拟主机宕机用备调度器访问VIP192.168.115.200
先查看备的IP,keepalived生效
静态页面
动态页面
依旧正常访问,经过简单的测试后我们可以在Tomcat上部署应用了