栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

1+X 云计算运维与开发(中级)案例实战——分布式部署集群应用商城系统

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

1+X 云计算运维与开发(中级)案例实战——分布式部署集群应用商城系统

1+X 云计算运维与开发(级)案例实战——分布式部署集群应用商城系统

前言思路实操

1.修改主机名,配置主机映射,配置yum源(ftp)

1.1 修改主机名1.2 配置主机映射1.3 配置yum源(ftp) 2.搭建主从数据库集群

2.1 配置db12.2 配置db22.3 配置mycat 3.搭建zookeeper集群和kafka集群

3.1 搭建zookeeper集群3.2 搭建kafka集群 4. 搭建redis服务器5.配置前端服务器nginx6.启动后端服务7.最后 总结

前言

学而不思则罔,思而不学则殆。

IP主机名节点
192.168.200.10mycatMycat 中间件服务节点
192.168.200.20db1MariaDB 数据库集群主节点
192.168.200.30db2MariaDB 数据库集群从节点
192.168.200.40zookeeper1集群节点
192.168.200.50zookeeper2集群节点
192.168.200.60zookeeper3集群节点
192.168.200.70redis消息队列服务节点
192.168.200.80nginxNginx 服务器
192.168.200.90jar1Tomcat1 节点
192.168.200.100jar2Tomcat2 节点

思路

总的来说,机子很多,操作却十分简单,思路与单节点部署应用商城系统差不了多少,只不过多了对zookeeper,kafka,mycat 分离主从读写数据库的操作。所以我们只要一步一步的操作,将大的拆解成小的,再加以练习,很快就能掌握。

1.修改主机名,配置主机映射,配置 yum源(ftp)
2.基于 mycat中间件 构建读写分离的主从数据库集群,可参考我的另一篇文章:https://blog.csdn.net/famudd/article/details/123687877?spm=1001.2014.3001.5501
3.部署 zookeeper集群 和 kafka集群(最好了解一下kafka和zookeeper之间的关系)
4.配置消息队列 redis服务
5.配置前端服务 nginx
6.开启后端服务,也就是4个jar包

注意:10台虚拟机要注意自己的磁盘空间是否充足,另外,如果虚拟内存不够用的话,咱们大可以把每台虚拟的内存调小一点


实操 1.修改主机名,配置主机映射,配置yum源(ftp) 1.1 修改主机名

修改主机名这里只列举一台机子的配法,其他类似,代码如下:

[root@xnode1 ~]# hostnamectl set-hostname mycat
[root@xnode1 ~]# bash
[root@mycat ~]# 
1.2 配置主机映射

[mycat、db1、db2]:
在 /etc/hosts文件中添加以下内容:

192.168.200.10 mycat 
192.168.200.20 db1
192.168.200.30 db2

[zookeeper1,zookeeper2,zookeeper3]:
在 /etc/hosts文件中添加以下内容:

192.168.200.40 zookeeper1
192.168.200.50 zookeeper2
192.168.200.60 zookeeper3

[jar1、jar2]:
在 /etc/hosts文件中添加以下内容:

192.168.200.10 mysql.mall
192.168.200.40 zk1.mall
192.168.200.50 zk1.mall
192.168.200.60 zk1.mall
192.168.200.40 kafka1.mall
192.168.200.50 kafka1.mall
192.168.200.60 kafka.mall
192.168.200.70 redis.mall
192.168.200.80 nginx.mall
192.168.200.90 jar1
192.168.200.100 jar2

看到这里不要觉得乱,其实很简单,接下来我来讲解一下。

先来看一下单节点部署应用商城系统中我们主机映射的配置:

192.168.200.11 mall     				--这一行将决定你的kafka进程是否会正常运行
192.168.200.11 kafka.mall
192.168.200.11 mysql.mall
192.168.200.11 redis.mall
192.168.200.11 zookeeper.mall
————————————————
版权声明:本文为CSDN博主「famudd」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/famudd/article/details/123559715
(这是我的文章>o<)

1.这里之所以 ip地址只有 192.168.200.11,是因为我们之前做单节点的时候所有服务和集群都在同一台机子上,所以当我们把它们拆分的时候,自然要给不同的服务和集群赋予不同的IP地址
2.我们把拆分看成树状拆分,并且拆的层级为 2
(咱也是灵魂画师)


对应关系:

单节点多节点
mysql.mallmycat
zookeeper.mall三个zk1.mall
kafka.mall三个kafka.mall
malljar1、jar2
redis.mallredis.mall
nginx.mallnginx.mall

小疑惑:

同样是后端包中,似乎对kafka和zookeeper的id不做要求,因为我讲zk1改为zk1,zk2,zk3或者zookeeper1,zookeeper2,zookeeper3仍然正常运行

1.3 配置yum源(ftp)

用到的gpmall-repo和CentOS-7-x86_64-DVD-1511.iso需要自行准备

随便选中一位幸运虚拟机(我的选择是 mycat,就决定是你了)作为我们的源yum节点,配置本地yum源,然后安装ftp,作为ftp服务器,将 /opt 作为共享文件夹
代码如下:

[root@mycat ~]# rm -rf /etc/yum.repos.d/*
[root@mycat ~]# cat /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///opt/cdrom
gpgcheck=0
[gpmall]
name=gpmall
baseurl=file:///opt/gpmall-repo
gpgcheck=0
[root@mycat ~]# yum repolist
Loaded plugins: fastestmirror
centos                                                                          | 3.6 kB  00:00:00     
gpmall                                                                          | 2.9 kB  00:00:00     
(1/3): centos/group_gz                                                          | 155 kB  00:00:00     
(2/3): centos/primary_db                                                        | 2.8 MB  00:00:00     
(3/3): gpmall/primary_db                                                        | 144 kB  00:00:00     
Determining fastest mirrors
repo id                                          repo name                                       status
centos                                           centos                                          3,723
gpmall                                           gpmall                                            165
repolist: 3,888

使用配置好的本地yum源安装ftp服务,配置并启动

[root@mycat ~]# yum -y install vsftpd
[root@mycat ~]# vi /etc/vsftpd/vsftpd.conf
##我们的包在这个路径下
## 在vsftpd.conf文件开头添加共享文件路径信息:
anon_root=/opt
[root@mycat ~]# systemctl restart vsftpd   ## 重启生效

注意! 每台机子都要关闭防火墙!

10台机子固然很麻烦,也有简单的方法,但是这里我们就一个一个的弄,毕竟初学。

关闭防火墙,关闭防火墙,关闭防火墙:

[root@mycat ~]# systemctl stop firewalld
[root@mycat ~]# setenforce 0

以上是对源yum源的配置(防火墙每台机子都要配),接下来我们配置其余机器的yum源,其余的操作一致(所以可以复制粘贴)
代码如下:

[root@db1 ~]# rm -rf /etc/yum.repos.d/*
[root@db1 ~]# cat /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=ftp://192.168.200.10/cdrom
gpgcheck=0
enabled=1
[gpmall]
name=gpmall
baseurl=ftp://192.168.200.10/gpmall-repo
gpgcheck=0
enabled=1
[root@db1 ~]# yum repolist
Loaded plugins: fastestmirror
centos                                                                          | 3.6 kB  00:00:00     
gpmall                                                                          | 2.9 kB  00:00:00     
(1/3): centos/group_gz                                                          | 155 kB  00:00:00     
(2/3): centos/primary_db                                                        | 2.8 MB  00:00:00     
(3/3): gpmall/primary_db                                                        | 144 kB  00:00:00     
Determining fastest mirrors
repo id                                          repo name                                       status
centos                                           centos                                          3,723
gpmall                                           gpmall                                            165
repolist: 3,888

2.搭建主从数据库集群

写到这里的时候很想直接把我的另外一篇文章放到这里TAT
这里我就略写,详细的你们去看我那篇文章吧
https://blog.csdn.net/famudd/article/details/123687877?spm=1001.2014.3001.5501

2.1 配置db1

安装mysql

[root@db1 ~]# yum -y install mariadb mariadb-server

启动mariadb,这一步关乎它让不让你初始化mysql

[root@db1 ~]# systemctl start mariadb

初始化mysql

[root@db1 ~]# mysql_secure_installation
[root@db1 ~]# mysql_secure_installation

Enter current password for root (enter for none): #直接回车
OK, successfully used password, moving on...

Set root password? [Y/n] #输入y或者直接回车
New password: #密码必须123456,后面的mycat配置文件硬性需要
Re-enter new password: #在输入一遍123456
Password updated successfully!
Reloading privilege tables..
 ... Success!
 
Remove anonymous users? [Y/n] #输入y或者直接回车
。。。
Disallow root login remotely? [Y/n] #输入n
。。。
Remove test database and access to it? [Y/n] #输入y或者直接回车
。。。
Reload privilege tables now? [Y/n] #输入y或者直接回车


修改 /etc/my.cnf文件
添加以下内容并重启服务:

[mysqld]
log-bin = mysql-bin
binlog-ignore-db = mysql
server-id = 20

datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
symbolic-links = 0

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

[root@db1 ~]# systemctl restart mariadb

如果出现重启失败,那十有八九就是你输入了错误的信息,这时候你可以查日志

在主节点 db1 虚拟机上使用 mysql 命令登录 MariaDB 数据库,授权在任何客户端机器上可以以 root 用户登录到数据库

[root@db1 ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 9
Server version: 10.3.18-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> grant all privileges on *.* root@'%' identified by '123456';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'root@'%' identified by '123456'' at line 1
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '123456';
Query OK, 0 rows affected (0.000 sec)

在主节点 db1 数据库上创建一个 user 用户让从节点 db2 连接,并赋予从节点同步主节点数据库的权限

MariaDB [(none)]> grant replication slave on *.* to 'user'@'db2' identified by '123456';
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)
2.2 配置db2

db2的前置操作请同步db1到初始化mysql
不用修改配置文件
这里就当你们初始化完了

在从节点 db2 虚拟机上使用 mysql 命令登录 MariaDB 数据库,配置从节点连接主节点的连接信息。master_host 为主节点主机名 db1,master_user 为在配置db1中创建的用户 user

[root@db2 ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 15
Server version: 10.3.18-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> change master to master_host='db1',master_user='user',master_password='123456';
Query OK, 0 rows affected (0.004 sec)

配置完毕主从数据库之间的连接信息之后,开启从节点服务。使用 **show slave statusG;**命令并查看从节点服务状态,如果 Slave_IO_Running 和 Slave_SQL_Running 的状态都为 YES,则从节点服务开启成功。

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> show slave status G
*************************** 1. row ***************************
                Slave_IO_State: Waiting for master to send event
                   Master_Host: db1
                   Master_User: user
                   Master_Port: 3306
                 Connect_Retry: 60
               Master_Log_File: mysql-bin.000001
           Read_Master_Log_Pos: 822
                Relay_Log_File: db2-relay-bin.000002
                 Relay_Log_Pos: 1121
         Relay_Master_Log_File: mysql-bin.000001
              Slave_IO_Running: Yes
             Slave_SQL_Running: Yes
               Replicate_Do_DB: 
           Replicate_Ignore_DB: 
            Replicate_Do_Table: 
        Replicate_Ignore_Table: 
       Replicate_Wild_Do_Table: 
   Replicate_Wild_Ignore_Table: 
                    Last_Errno: 0
                    Last_Error: 
                  Skip_Counter: 0
           Exec_Master_Log_Pos: 822
               Relay_Log_Space: 1428
               Until_Condition: None
                Until_Log_File: 
                 Until_Log_Pos: 0
            Master_SSL_Allowed: No
            Master_SSL_CA_File: 
            Master_SSL_CA_Path: 
               Master_SSL_Cert: 
             Master_SSL_Cipher: 
                Master_SSL_Key: 
         Seconds_Behind_Master: 0
 Master_SSL_Verify_Server_Cert: No
                 Last_IO_Errno: 0
                 Last_IO_Error: 
                Last_SQL_Errno: 0
                Last_SQL_Error: 
   Replicate_Ignore_Server_Ids: 
              Master_Server_Id: 20
                Master_SSL_Crl: 
            Master_SSL_Crlpath: 
                    Using_Gtid: No
                   Gtid_IO_Pos: 
       Replicate_Do_Domain_Ids: 
   Replicate_Ignore_Domain_Ids: 
                 Parallel_Mode: conservative
                     SQL_Delay: 0
           SQL_Remaining_Delay: NULL
       Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
              Slave_DDL_Groups: 3
Slave_Non_Transactional_Groups: 0
    Slave_Transactional_Groups: 0
1 row in set (0.000 sec)

2.3 配置mycat

自行准备 Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

解压

[root@mycat ~]# tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local/

赋权限,配系统变量,并使其生效

[root@mycat ~]# chmod 777 /usr/local/mycat/
[root@mycat ~]# echo export MYCAT_HOME=/usr/local/mycat/ >> /etc/profile
[root@mycat ~]# source /etc/profile

修改配置文件 schema.xml:

这里的修改思路在我的另一篇文章里https://blog.csdn.net/famudd/article/details/123687877?spm=1001.2014.3001.5501

注意:另一篇文章里用的数据库是test,这里数据库名是gpmall,注意区分




        
        
        
        
                select user()
                
                
                        
                        
                
        

这里给出需要注意的地方:

接下来配置 server.xml文件

[root@mycat ~]# chown root:root /usr/local/mycat/conf/server.xml
## 配置文件末尾
        
                123456
                gpmall     ##这里改为gpmall

                
                
        
        ##这里原先有几行代码,要删除

启动 mycat:

[root@mycat ~]# /bin/bash /usr/local/mycat/bin/mycat start

检查是否成功启动

[root@mycat ~]# netstat -ntpl | grep 8066
##netstat如果不能使用,就用yum下载net-tools

出现报错看日志,发现是java没安装

[root@mycat ~]# cat /usr/local/mycat/logs/wrapper.log 
STATUS | wrapper  | 2022/03/25 18:22:01 | --> Wrapper Started as Daemon
STATUS | wrapper  | 2022/03/25 18:22:01 | Launching a JVM...
ERROR  | wrapper  | 2022/03/25 18:22:01 | Unable to start JVM: No such file or directory (2)
ERROR  | wrapper  | 2022/03/25 18:22:01 | JVM exited while loading the application.
STATUS | wrapper  | 2022/03/25 18:22:06 | Launching a JVM...
ERROR  | wrapper  | 2022/03/25 18:22:06 | Unable to start JVM: No such file or directory (2)
ERROR  | wrapper  | 2022/03/25 18:22:06 | JVM exited while loading the application.
STATUS | wrapper  | 2022/03/25 18:22:10 | Launching a JVM...
ERROR  | wrapper  | 2022/03/25 18:22:10 | Unable to start JVM: No such file or directory (2)
ERROR  | wrapper  | 2022/03/25 18:22:10 | JVM exited while loading the application.
STATUS | wrapper  | 2022/03/25 18:22:14 | Launching a JVM...
ERROR  | wrapper  | 2022/03/25 18:22:14 | Unable to start JVM: No such file or directory (2)
ERROR  | wrapper  | 2022/03/25 18:22:14 | JVM exited while loading the application.
STATUS | wrapper  | 2022/03/25 18:22:18 | Launching a JVM...
ERROR  | wrapper  | 2022/03/25 18:22:18 | Unable to start JVM: No such file or directory (2)
ERROR  | wrapper  | 2022/03/25 18:22:18 | JVM exited while loading the application.
FATAL  | wrapper  | 2022/03/25 18:22:18 | There were 5 failed launches in a row, each lasting less than 300 seconds.  Giving up.
FATAL  | wrapper  | 2022/03/25 18:22:18 |   There may be a configuration problem: please check the logs.
STATUS | wrapper  | 2022/03/25 18:22:19 | <-- Wrapper Stopped

安装 java

[root@mycat ~]# yum -y install java1.8.0-openjdk java-1.8.0-openjdk-devel

再次启动,此次成功:

[root@mycat ~]# /bin/bash /usr/local/mycat/bin/mycat start
Starting Mycat-server...
[root@mycat ~]# netstat -ntpl | grep 8066
tcp6       0      0 :::8066                 :::*                    LISTEN      3879/java 
[root@mycat ~]# netstat -ntpl | grep 9066
tcp6       0      0 :::9066                 :::*                    LISTEN      3879/java

还需要在主数据库创建 gpmall 数据库,并且导入 gpmall.sql (自行准备)

MariaDB [(none)]> create database gpmall;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> use gpmall;
Database changed
MariaDB [gpmall]> source /root/gpmall-cluster/gpmall.sql
Query OK, 0 rows affected (0.000 sec)

Query OK, 0 rows affected (0.000 sec)

Query OK, 0 rows affected, 1 warning (0.001 sec)
...
Query OK, 0 rows affected (0.000 sec)

检查读写分离命令

[root@mycat ~]# yum -y install MariaDB-client
[root@mycat ~]# mysql -h127.0.0.1 -P9066 -uroot -p123456 -e 'show @@datasource;'
+----------+--------+-------+----------------+------+------+--------+------+------+---------+-----------+------------+
| DATANODE | NAME   | TYPE  | HOST           | PORT | W/R  | ACTIVE | IDLE | SIZE | EXECUTE | READ_LOAD | WRITE_LOAD |
+----------+--------+-------+----------------+------+------+--------+------+------+---------+-----------+------------+
| dn1      | hostM1 | mysql | 192.168.200.20 | 3306 | W    |      0 |    4 | 1000 |      16 |         0 |          0 |
| dn1      | hostS1 | mysql | 192.168.200.30 | 3306 | R    |      0 |    4 | 1000 |      16 |         0 |          0 |
+----------+--------+-------+----------------+------+------+--------+------+------+---------+-----------+------------+

至此,分离读写主从数据库集群搭建完成


3.搭建zookeeper集群和kafka集群

自行准备 zookeeper-3.4.14.tar.gz 和 kafka_2.11-1.1.1.tgz

如果没有说明,那么三台机子zookeeper1、zookeeper2、zookeeper3都将进行相同操作

解压两个压缩包:

[root@zookeeper1 ~]# tar -zxvf zookeeper-3.4.14.tar.gz
[root@zookeeper1 ~]# tar -zxvf kafka_2.11-1.1.1.tgz
3.1 搭建zookeeper集群

重命名 /root/zookeeper-3.4.14/conf/路径下的zoo_sample.cfg 为 zoo.cfg

重命名的原因是 zkEnv.sh 里需要,具体自行查看( /root/zookeeper-3.4.14/bin )

[root@zookeeper1 ~]# cd zookeeper-3.4.14/conf/
[root@zookeeper1 conf]# mv zoo_sample.cfg zoo.cfg

编辑 zoo.cfg
在文件末尾添加以下内容:

server.1=192.168.200.40:2888:3888
server.2=192.168.200.50:2888:3888
server.3=192.168.200.60:2888:3888

注意:这里开始3台机子开始不同
创建 /tmp 目录下的 zookeeper 目录,在该目录下创建 myid 文件,文件里分别输入 1,2,3 ,对应他们机子的编号,以下用zookeeper1做示范:

[root@zookeeper1 ~]# mkdir /tmp/zookeeper
[root@zookeeper1 ~]# vi /tmp/zookeeper/myid
1

简单来说就是 myid里的内容不同,分别为 1,2,3

注意:这里开始3台机子开始相同
启动 zookeeper

[root@zookeeper2 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

至此,zookeeper集群搭建完成

3.2 搭建kafka集群

修改配置文件

[root@zookeeper2 ~]# vi kafka_2.11-1.1.1/config/server.properties

第 21 行:将 0 改为 123

意思是服务器id号,每台都不一样

     21 broker.id=1

第 31 行:去掉注释,在 // 后面添加IP地址(例如zookeeper1,则添加 192.168.200.40)

意思是开启监听端口

     31 listeners=PLAINTEXT://192.168.200.40:9092

第 123 行:添加三台机子的IP地址加上 zookeeper 服务的端口号

kafka依赖于zookeeper,所以这里要与zookeepr关联,就需要添加3台机子的IP地址和zookeeper服务的端口号

    123 zookeeper.connect=192.168.200.40:2181,192.168.200.50:2181,192.168.200.60:2181

进入 kafka 的 bin 目录,启动 kafka服务

[root@zookeeper1 bin]# ./kafka-server-start.sh -daemon ../config/server.properties
[root@zookeeper1 bin]# jps
3592 QuorumPeerMain
4216 Kafka
5418 Jps

测试 kafka

[root@zookeeper1 bin]# ./kafka-topics.sh --create --zookeeper 192.168.200.40:2181 --replication-factor 1 --partitions 1 --topic test
Created topic "test".
[root@zookeeper2 bin]# ./kafka-topics.sh --list -zookeeper 192.168.200.40:2181
test

至此,kafka集群搭建完成


4. 搭建redis服务器

在 redis机 上安装 redis服务
代码如下:

[root@redis ~]# yum -y install redis

修改 redis服务 的配置文件 /etc/redis.conf

[root@redis ~]# vi /etc/redis.conf

第61行:将该行注释

     61 #bind 127.0.0.1

第80行:讲该行的 yes 改为 no

     80 protected-mode no

使配置生效

[root@redis ~]# systemctl restart redis

至此,消息队列服务redis配置完成

配置文件详解具体请看这篇文章,转载自:https://www.cnblogs.com/Draymonder/p/11938114.html


5.配置前端服务器nginx

在 nginx机 上安装 nginx服务

[root@nginx ~]# yum -y install nginx

修改配置文件 ( /etc/nginx/conf.d/default.conf)
在文件开头添加以下内容:

upstream myuser{
                server 192.168.200.90:8082;
                server 192.168.200.100:8082;
                ip_hash;
                }
upstream myshopping{
                server 192.168.200.90:8081;
                server 192.168.200.100:8081;
                ip_hash;
                }
upstream mycashier{
                server 192.168.200.90:8083;
                server 192.168.200.100:8083;
                ip_hash;
                }

在 " #error_page 404 "上一行添加以下内容:

     24     location / {
     25         root   /usr/share/nginx/html;
     26         index  index.html index.htm;
     27     }
     28     location /user{
     29                 proxy_pass http://myuser;
     30                 }
     31     location /shopping{
     32                 proxy_pass http://myshopping;
     33                 }
     34     location /cashier{
     35                 proxy_pass http://mycashier;
     36                 }

最终的结果为(截至38行):

      1 upstream myuser{
     2                 server 192.168.200.90:8082;
     3                 server 192.168.200.100:8082;
     4                 ip_hash;
     5                 }
     6 upstream myshopping{
     7                 server 192.168.200.90:8081;
     8                 server 192.168.200.100:8081;
     9                 ip_hash;
    10                 }
    11 upstream mycashier{
    12                 server 192.168.200.90:8083;
    13                 server 192.168.200.100:8083;
    14                 ip_hash;
    15                 }
    16 
    17 server {
    18     listen       80;
    19     server_name  localhost;
    20 
    21     #charset koi8-r;
    22     #access_log  /var/log/nginx/host.access.log  main;
    23 
    24     location / {
    25         root   /usr/share/nginx/html;
    26         index  index.html index.htm;
    27     }
    28     location /user{
    29                 proxy_pass http://myuser;
    30                 }
    31     location /shopping{
    32                 proxy_pass http://myshopping;
    33                 }
    34     location /cashier{
    35                 proxy_pass http://mycashier;
    36                 }
    37 
    38     #error_page  404              /404.html;

将前端文件从 /etc/gpmall-cluster/dist 中移至 /usr/share/nginx/html/

[root@nginx ~]# rm -rf /usr/share/nginx/html/*
[root@nginx ~]# cp -R /root/gpmall-cluster/dist/* /usr/share/nginx/html/

前端文件需要自行准备

启动 nginx服务

[root@nginx ~]# systemctl start nginx

至此nginx的配置结束


6.启动后端服务

接下来对 jar1 和 jar2 机子进行相同操作

安装 java

[root@jar1 ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

一定要按照顺序启动4个.jar包,jar1、jar2操作相同

[root@jar1 gpmall-cluster]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[1] 3583
[root@jar1 gpmall-cluster]# nohup: ignoring input and appending output to ‘nohup.out’

[root@jar1 gpmall-cluster]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[2] 3624
[root@jar1 gpmall-cluster]# nohup: ignoring input and appending output to ‘nohup.out’

[root@jar1 gpmall-cluster]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[3] 3654
[root@jar1 gpmall-cluster]# nohup: ignoring input and appending output to ‘nohup.out’

[root@jar1 gpmall-cluster]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[4] 3685
[root@jar1 gpmall-cluster]# nohup: ignoring input and appending output to ‘nohup.out’

-------------------------------------------------------------------------------------
[root@jar1 gpmall-cluster]# jobs
[1]   Running                 nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[2]   Running                 nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[3]-  Running                 nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[4]+  Running                 nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &

说明:每输入一遍 nohup命令之后,它会自动弹出一个提示,所以一共输入了 四次nohup,如果输入的结果 不正常(正不正常看[1]这样的提示,一般来讲[1],[2],[3],[4]),请 kill进程然后排错后重新按照顺序启动,最后,请 关闭防火墙

附:
查看进程(安装完java后):jps、jobs
强制杀进程:kill -9 <进程号>


7.最后

浏览器中输入nginx机子的IP地址(前端):

界面显示出来和单节点不一样,因为我们这里用的gpmall.sql 和单节点部署的时候导入的gpmall.sql不一样


该界面如有报错或者错误显示,请参考这篇文章,转载自:
https://www.cnblogs.com/sh1ny2/p/13976801.html


总结

理解和练习是最好的学习

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/781698.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号