Ctenos7安装mysql-8.1.0/tomcat-9.0.80/LNMT部署

目录

一、实验拓扑

二、部署mysql

 三、部署Tomcat

 四、配置NGINX

五、 配置NGINX的双机热备提高可用性



一、实验拓扑

Ctenos7安装mysql-8.1.0/tomcat-9.0.80/LNMT部署_第1张图片

二、部署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;"

Ctenos7安装mysql-8.1.0/tomcat-9.0.80/LNMT部署_第2张图片

 三、部署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 Java
                   Java -version
          

                                                Tomcat部署
Tomcat下载地址 https://tomcat.apache.org/
1、解压
    tar -xf apache-tomcat-9.0.80.tar.gz
    mv 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

访问测试,okCtenos7安装mysql-8.1.0/tomcat-9.0.80/LNMT部署_第3张图片

Ctenos7安装mysql-8.1.0/tomcat-9.0.80/LNMT部署_第4张图片

 四、配置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$ {                                ####这里是jsp
                proxy_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

静态页面Ctenos7安装mysql-8.1.0/tomcat-9.0.80/LNMT部署_第5张图片

Ctenos7安装mysql-8.1.0/tomcat-9.0.80/LNMT部署_第6张图片

动态页面

Ctenos7安装mysql-8.1.0/tomcat-9.0.80/LNMT部署_第7张图片

Ctenos7安装mysql-8.1.0/tomcat-9.0.80/LNMT部署_第8张图片

五、 配置NGINX的双机热备提高可用性

yum -y install keepalived
vim /etc/keepalived/keepalived.conf
#######################配置####################################
############################################################
! Configuration File for keepalived
 
global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL            ###从的编号要改动一下 LVS_DEVEL1
   vrrp_skip_check_adv_addr
   #vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}
 
vrrp_instance VI_1 {
    state MASTER                  ###从改为BACKUP
    interface ens33               ###网卡名
    virtual_router_id 51
    priority 100                  ###从的优先级要比主低
    advert_int 1
   authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.115.200          ###VIP用来访问的虚拟IP
    }
}
virtual_server 192.168.115.200 8080 {       ###vip对应的真是IP 在下面
    delay_loop 6
    lb_algo rr 
    persistence_timeout 50
    protocol TCP
 
    real_server 192.168.115.136 8080 {        ###这是Tomcat服务器的IP
        weight 1
        HTTP_GET {
            url { 
              path /testurl/test.jsp
            }
url { 
              path /testurl2/test.jsp
            }
            url { 
              path /testurl3/test.jsp
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
 
    real_server 192.168.115.140 8080 {       ###这是Tomcat服务器的IP
        weight 1
        HTTP_GET {
            url { 
              path /testurl/test.jsp
            }
            url { 
              path /testurl2/test.jsp
}
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

启动keepalived

systemctl start keepalived.service 

看看主调器的IP

 现在模拟主机宕机用备调度器访问VIP192.168.115.200

先查看备的IP,keepalived生效

静态页面Ctenos7安装mysql-8.1.0/tomcat-9.0.80/LNMT部署_第9张图片

动态页面

Ctenos7安装mysql-8.1.0/tomcat-9.0.80/LNMT部署_第10张图片

 依旧正常访问,经过简单的测试后我们可以在Tomcat上部署应用了

你可能感兴趣的:(mysql,数据库)