论web架构演变及集群化部署商城系统

关于商城系统的包自取,放在最后

一.Web网站架构演变过程,解析,理解

1.单体架构阶段

架构特点

  1. 所有的业务逻辑,后端部署,前端部署,微服务的部署等功能都集中在一个单一的应用程序里。
  2. 通常是一个简单的基于服务器的渲染应用,可能使用到一个简单的spring框架来处理http的请求和响应 

  3. 优点

  4. 开发比较简单,所有代码都在同一个服务器中,易于理解和开发
  5. 测试和部署相对容易
  6. 缺点

  7. 随着后续业务的继续发展,代码库会变得庞大且复杂化,最后会导致维护成本太高
  8. 可扩展性很差,当面对到大量用户同时访问网站,难以应对高并发的请求,从而导致服务崩溃。

1.分布式集群阶段

架构特点

  1. 将系统的不同组件分布放在不同的服务器上,通过网络进行通信和协作。
  2. 包括分布式数据库,分布式zookeeper和kafka
  1. 优点
  1. 高可用性,当一个节点出现故障时,其他节点可以继续提供服务。
  2. 可扩展性,可以通过增加节点来提高系统的处理能力。
  1. 缺点
  1. 系统的复杂性大大增加,包括网络通信、数据一致性、事务管理等方面的问题。
  2. 调试和维护难度大,需要对分布式系统的原理和技术有深入的了解。

二.集群化部署商城系统

案例规划

IP

主机名

节点

192.168.143.161

db1

主节点

构建读写分离数据库集群

192.168.143.162

db2

从节点

192.168.143.163

mycat

中间件

192.168.143.164

zk1

集群

Zookeeper和Kafka集群部署

192.168.143.165

zk2

集群

192.168.143.166

zk3

集群

192.168.143.167

nginx

Nginx服务器

192.168.143.168

redis

缓存服务节点

192.168.143.169

jar1

用于连接各个服务,并进行挂包

192.168.143.170

jar2

用于连接各个服务,并进行挂包

案例实施

1.构建读写分离数据库集群

(1.1)修改主机名并关闭防火墙、selinux
修改db1主机名并关闭防火墙
[root@localhost ~]# hostnamectl set-hostname db1

[root@localhost ~]# systemctl stop firewalld

开机自动关闭

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# setenforce 0

永久关闭selinux

[root@localhost ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

修改db2主机名并关闭防火墙

[root@localhost ~]# hostnamectl set-hostname db2

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

修改mycat主机名并关闭防火墙

[root@localhost ~]# hostnamectl set-hostname db2

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

(1.2)修改主机映射
[root@mycat ~]# vi /etc/hosts

(1.3)配置yum源

目的在于后续安装包时,不会因为没有包而安装不上

这里以前配过了,只需要有mariadb就行了

三台进行一样的操作

[root@mycat ~]# cat /etc/yum.repos.d/local.repo

[centos]

name=centos

baseurl=file:///opt/centos

gpgcheck=0

enabled=1



[zabbix]

name=zabbix

baseurl=file:///opt/zabbix

gpgcheck=0

enabled=1



[mariadb]

name=mariadb

baseurl=file:///opt/gpmall-repo

gpgcheck=0

enabled=1

清除缓存

[root@mycat ~]# yum clean all

重新建立缓存

[root@mycat ~]# yum makecache

查看yum仓库

[root@mycat ~]# yum repolist
(1.4)配置主从服务
(1.4.1)安装mariadb服务

通过YUM命令在db1和db2虚拟机节点上安装MariaDB服务

# yum install -y mariadb mariadb-server

启动并设置为开机自启

# systemctl start mariadb

# systemctl enable mariadb

(1.4.2)初始化MariaDB数据库

在db1和db2虚拟机节点上初始化MariaDB数据库,并设置MariaDB数据库root访问用户的密码为123456

[root@db1 ~]# mysql_secure_installation

/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current

password for the root user.  If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):    #默认按回车

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

Set root password? [Y/n] y

New password:                               #输入数据库root密码123456

Re-enter new password:                        #重复输入密码123456
production environment.

Remove anonymous users? [Y/n] y

 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n

 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y

 - Dropping test database...

 ... Success!

 - Removing privileges on test database...

 ... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y

 ... Success!
Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

db2同上

(1.4.3)配置数据库集群主节点
[root@db1 ~]# cat /etc/my.cnf

[mysqld]

log_bin = mysql-bin                       #记录操作日志

binlog_ignore_db = mysql                  #不同步MySQL系统数据库

server_id = 61                            #数据库集群中的每个节点id都要不同,一般使用IP地址的最后段的数字,例如172.16.51.18,server_id就写18

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

[mysqld_safe]

log-error=/var/log/mariadb/mariadb.log

pid-file=/var/run/mariadb/mariadb.pid

重启服务

[root@db1 ~]# systemctl restart mariadb

(1.4.4)开放主节点的数据库权限

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

[root@db1 ~]# mysql -uroot -p123456

MariaDB [(none)]> grant all privileges  on *.* to root@'%' identified by "123456";

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

MariaDB [(none)]> grant replication slave on *.* to 'user'@'db2' identified by '123456';

编辑从节点配置文件

[root@db2 ~]# cat /etc/my.cnf

[mysqld]

log_bin = mysql-bin                       #记录操作日志

binlog_ignore_db = mysql                  #不同步MySQL系统数据库

server_id = 62                            #数据库集群中的每个节点id都要不同,一般使用IP地址的最后段的数字,例如172.16.51.18,server_id就写18

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

[mysqld_safe]

log-error=/var/log/mariadb/mariadb.log

pid-file=/var/run/mariadb/mariadb.pid

(1.4.5)配置从节点db2同步主节点db1

配置从节点连接主节点的连接信息。master_host为主节点主机名db1,master_user为在db1授权时创建的用户user

[root@db2 ~]# mysql -uroot -p123456

MariaDB [(none)]>  change master to master_host='db1',master_user='user',master_password='123456';

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

MariaDB [(none)]> start slave;

MariaDB [(none)]> show slave status\G;
(1.4.6)验证主从数据库的同步功能

这里我直接把需要的gpmal.sql表传进来

先在主节点db1的数据库中创建库gpmall,使用库gpmall,再把表导入进来

MariaDB [(none)]> create database gpmall;

Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> use gpmall

Database changed

MariaDB [(none)]> source /root/gpmall.sql

这时从节点db2的数据库就会同步主节点数据库创建的gpmall库,并可以查询到导入的所有表

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| gpmall             |

| information_schema |

| mysql              |

| performance_schema |

+--------------------+

4 rows in set (0.007 sec)



MariaDB [(none)]> use gpmall

MariaDB [gpmall]> show tables;

+--------------------+

| Tables_in_gpmall   |
+--------------------+

| tb_address         |

| tb_base            |

| tb_comment         |

| tb_comment_picture |

| tb_comment_reply   |

| tb_dict            |

| tb_express         |

| tb_item            |

| tb_item_cat        |

| tb_item_desc       |

| tb_log             |

| tb_member          |

| tb_order           |

| tb_order_item      |

| tb_order_shipping  |

| tb_panel           |
| tb_panel_content   |

| tb_payment         |

| tb_refund          |

| tb_stock           |

| tb_user_verify     |

+--------------------+

21 rows in set (0.001 sec)
(1.5).部署Mycat读写分离中间件服务

安装JDK环境

yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
(1.5.1)安装Mycat服务

将mycat压缩包传入root里

进行解压,并将软件包解压到/use/local目录中。赋予解压后的Mycat目录权限。

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

[root@mycat ~]# chown -R 777 /usr/local/mycat/

在/etc/profile系统变量文件中添加Mycat服务的系统变量,并生效变量

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

[root@mycat ~]# source /etc/profile

(1.5.2)编辑Mycat的逻辑库配置文件

在这里定义一个逻辑库schema,name为gpmall;该逻辑库gpmall对应数据库database为gpmall(在部署主从数据库时已安装);设置数据库写入节点为主节点db1;设置数据库读取节点为从节点db2。

[root@mycat ~]#  cat /usr/local/mycat/conf/schema.xml

<?xml version="1.0"?>

<!DOCTYPE mycat:schema SYSTEM "schema.dtd">

<mycat:schema xmlns:mycat="http://io.mycat/">

<schema name="gpmall" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1"></schema>

<dataNode name="dn1" dataHost="localhost1" database="gpmall" /> 

<dataHost name="localhost1" maxCon="1000" minCon="10" balance="3" dbType="mysql" dbDriver="native" writeType="0" switchType="1"  slaveThreshold="100"> 

    <heartbeat>select user()</heartbeat>

    <writeHost host="hostM1" url="192.168.143.161:3306" user="root" password="123456">

        <readHost host="hostS1" url="192.168.143.162:3306" user="root" password="123456" />

    </writeHost>

</dataHost>

</mycat:schema>
(1.5.3)修改配置文件权限并修改schema.xml的用户权限
[root@mycat ~]# chown root:root /usr/local/mycat/conf/schema.xml

在配置文件的最后部分,

<user name="root">

          <property name="password">123456</property>

          <property name="schemas">gpmall</property>

然后删除如下几行:

<user name="user">

          <property name="password">user</property>

          <property name="schemas">TESTDB</property>

          <property name="readOnly">true</property>

</user>
(1.5.4)启动Mycat服务

启动后使用netstat -ntpl命令查看虚拟机端口开放情况,如果有开放8066和9066端口,则表示Mycat服务开启成功。

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

[root@mycat ~]# netstat -ntlp
(1.5.5)验证数据库集群服务读写分离功能

先在Mycat虚拟机上使用Yum安装mariadb-client服务

[root@mycat ~]# yum install -y MariaDB-client

因为Mycat的逻辑库gpmall对应的数据库gpmall(在部署主从数据库时已安装),所以可以看看表中数据

[root@mycat ~]# mysql -h127.0.0.1 -P8066 -uroot -p123456

MySQL [(none)]> show databases;

+----------+

| DATABASE |

+----------+

| gpmall   |

+----------+

1 row in set (0.005 sec)

MySQL [(none)]> use gpmall

MySQL [gpmall]> show tables;

+--------------------+

| Tables_in_gpmall   |

+--------------------+

| tb_address         |

| tb_base            |

| tb_comment         |

| tb_comment_picture |
| tb_comment_reply   |

| tb_dict            |

| tb_express         |

| tb_item            |

| tb_item_cat        |

| tb_item_desc       |

| tb_log             |

| tb_member          |

| tb_order           |

| tb_order_item      |

| tb_order_shipping  |

| tb_panel           |

| tb_panel_content   |

| tb_payment         |

| tb_refund          |

| tb_stock           |

| tb_user_verify     |

+--------------------+
21 rows in set (0.003 sec)

(1.5.6)验证Mycat服务对数据库读写操作分离

在Mycat虚拟机节点使用mysql命令,通过9066端口查询对数据库读写操作的分离信息。

[root@mycat ~]# mysql -h127.0.0.1 -P9066 -uroot -p123456 -e 'show  @@datasource;'
  1. 2.zookeeper集群部署

(2.1)修改主机名并关闭防火墙、selinux

zookeeper1节点:

[root@localhost ~]# hostnamectl set-hostname zk1

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

Zookeeper2节点:

[root@localhost ~]# hostnamectl set-hostname zk2

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

Zookeeper3节点:

[root@localhost ~]# hostnamectl set-hostname zk3

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
(2.2)配置hosts文件

(2.3)配置YUM源
三个节点一样配置 

(2.4)安装JDK环境

给三个节点安装jdk环境

yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
(2.5)解压zookeeper压缩包

将zookeeper-3.4.14.tar.gz软件包上传至3个节点的/root目录下,进行解压操作

tar -zxvf zookeeper-3.4.14.tar.gz

修改3个节点配置文件

给zoo_sample.cfg改名为zoo.cfg

这里之所以要改名,是因为后续启动过程中,执行文件里的脚本已经将名字写为了zoo.cfg

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

编辑该文件

[root@zk1 conf]# vi zoo.cfg

[root@zk1 conf]#  grep -n '^'[a-Z] zoo.cfg

在3台机器dataDir目录(此处为/tmp/zookeeper)下,分别创建一个myid文件,文件内容分别只有一行,其内容为1,2,3。即文件中只有一个数字,这个数字即为上面zoo.cfg配置文件中指定的值。

ZooKeeper是根据该文件来决定ZooKeeper集群各个机器的身份分配。

创建myid文件

Zk1:

[root@zk1 conf]# mkdir /tmp/zookeeper

[root@zk1 conf]# vi /tmp/zookeeper/myid

[root@zk1 conf]# cat /tmp/zookeeper/myid

1

Zk2

[root@zk2 conf]# mkdir /tmp/zookeeper

[root@zk2 conf]# vi /tmp/zookeeper/myid

[root@zk2 conf]# cat /tmp/zookeeper/myid

2

Zk3

[root@zk3 conf]# mkdir /tmp/zookeeper

[root@zk3 conf]# vi /tmp/zookeeper/myid

[root@zk3 conf]# cat /tmp/zookeeper/myid

3
(2.6)启动ZooKeeper服务

在3台机器的zookeeper-3.4.14/bin目录下执行命令如下:

[root@zookeeper1 bin]# ./zkServer.sh start

[root@zookeeper1 bin]# ./zkServer.sh status

(3) 搭建Kafka集群

(3.1)解压Kafka软件包

将提供的kafka_2.11-1.1.1.tgz软件包,上传至3个节点的/root目录下,并执行解压操作

# tar -zxvf kafka_2.11-1.1.1.tgz
(3.2)修改3个节点配置文件

在zookeeper1节点,进入kafka_2.11-1.1.1/config目录下,编辑server.properties文件。

在配置文件中找到以下两行并注释掉(在文本前加#)如下所示:

#broker.id=0

#zookeeper.connect=localhost:2181

然后在配置文件的底部添加如下3个配置。

Zk1:

broker.id=1

zookeeper.connect=192.168.143.164:2181, 192.168.143.165:2181, 192.168.143.166:2181

listeners = PLAINTEXT:// 192.168.143.164:9092

zk2

broker.id=2

zookeeper.connect=192.168.143.164:2181,192.168.143.165:2181,192.168.143.166:2181

listeners = PLAINTEXT://192.168.143.165:9092

zk3

broker.id=3

zookeeper.connect=192.168.143.164:2181,192.168.143.165:2181,192.168.143.166:2181

listeners = PLAINTEXT://192.168.143.166:9092

在3个节点上,进入kafka_2.11-1.1.1/bin目录下,启动服务

Zk1:

[root@zk1 bin]# ./kafka-server-start.sh -daemon  ../config/server.properties

Zk2

[root@zk2 bin]# ./kafka-server-start.sh -daemon ../config/server.properties

Zk3

[root@zk3 bin]# ./kafka-server-start.sh -daemon ../config/server.properties

查看服务是否都启动了

都启动起来,进行测试一下

(3.3)测试服务

在zookeeper1节点,进入kafka_2.11-1.1.1/bin目录下,创建topic

zk1节点:

[root@zookeeper1 bin]# ./kafka-topics.sh --create --zookeeper 192.168.143.164 --replication-factor 1 --partitions 1 --topic test

Zk2

[root@zk2 bin]# ./kafka-topics.sh --list --zookeeper 192.168.143.165:2181

__consumer_offsets

test

user-register-succ-topic

zk3

[root@zk3 bin]# ./kafka-topics.sh --list --zookeeper 192.168.143.165:2181

__consumer_offsets

test

user-register-succ-topic

测试成功。

(4)搭建redis节点

(4.1)登录Redis节点,修改主机名为redis,并关闭防火墙、selinux
[root@redis ~]# hostnamectl set-hostname redis

[root@redis ~]# systemctl stop firewalld

[root@redis ~]#  systemctl disable firewalld

[root@redis ~]#  setenforce 0

setenforce: SELinux is disabled

[root@redis ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
(4.2)修改Yum源
[root@redis ~]# cat /etc/yum.repos.d/local.repo

[centos]

name=centos

baseurl=file:///opt/centos

gpgcheck=0

enabled=1



[zabbix]

name=zabbix

baseurl=file:///opt/zabbix

gpgcheck=0

enabled=1



[mariadb]

name=mariadb

baseurl=file:///opt/gpmall-repo

gpgcheck=0

enabled=1
(4.3)安装Redis服务
[root@redis ~]# yum install redis -y

修改Redis配置文件/etc/redis.conf

将bind 127.0.0.1这一行注释掉,将protected-mode yes改为protected-mode no。
(4.4)启动Redis服务
[root@redis ~]# systemctl start redis

[root@redis ~]# systemctl enable redis

查看端口看看是否有6379

[root@redis ~]# netstat -ntlp

(5)搭建jar1和jar2节点

(5.1)修改主机名和关闭防火墙、selinux

192.168.143.169节点:

[root@localhost ~]# hostnamectl set-hostname jar1

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

192.168.143.170节点:

[root@localhost ~]# hostnamectl set-hostname jar1

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

(5.2)配置Yum源

两个节点进行一样的操作

[root@jar2 ~]# vi /etc/yum.repos.d/local.repo
(5.3)安装Java环境

因为4个jar包在这上面运行,所以它需要有Java的环境才能运行

[root@jar1 ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
(5.4)配置hosts文件

这里添加映射是为了各个节点都能通信

在jar1和jar2节点,编辑/etc/hosts配置文件

[root@jar2 ~]# vi /etc/hosts

(5.5)运行jar包

将提供的4个jar包,上传至jar1、jar2节点的/root目录下,然后运行这4个jar包

Jobs看一下包是否运行

这里包掉了就重新挂

(6)搭建nginx节点

(6.1)修改主机名和关闭防火墙、selinux
[root@nginx ~]# hostnamectl set-hostname nginx

[root@nginx ~]# systemctl stop firewalld

[root@nginx ~]# systemctl disable firewalld

[root@nginx ~]# setenforce 0

setenforce: SELinux is disabled

[root@nginx ~]# sed -i 's/SELINUX=enforcing/SELINUX=enabled/g' /etc/selinux/config

[root@nginx ~]#
(6.2)安装Nginx服务
[root@nginx ~]# yum install nginx -y

将提供的dist文件夹上传至Nginx节点的/root目录下

首先将Nginx默认项目目录的文件删除:

[root@nginx ~]# rm -rf /usr/share/nginx/html/*

然后将dist中的文件复制至/usr/share/nginx/html目录下:

[root@nginx ~]# cp -rvf dist/* /usr/share/nginx/html/*

修改Nginx配置文件/etc/nginx/conf.d/default.conf

IP地址为运行JAR包的2个服务器的IP。

upstream myuser {

            server 192.168.143.169:8082;

            server 192.168.143.170:8082;

            ip_hash;

        }



        upstream myshopping {

            server 192.168.143.169:8081;

            server 192.168.143.170:8081;

            ip_hash;

        }

        upstream mycashier {

            server 192.168.143.169:8083;

            server 192.168.143.170:8083;
            ip_hash;

        }



server {

    listen       80;

    server_name  localhost;



    #charset koi8-r;

    #access_log  /var/log/nginx/host.access.log  main;



    location / {

        root   /usr/share/nginx/html;

        index  index.html index.htm;

    }

    location /user {

            proxy_pass http://myuser;

        }
    location /shopping {

            proxy_pass http://myshopping;

        }



    location /cashier {

            proxy_pass http://mycashier;

        }



    #error_page  404              /404.html;

(6.3)启动nginx服务
[root@nginx ~]# systemctl start nginx

查看Nginx是否启动,看一下有没有80端口

(7)问题解决以及日志查询

一般我们会遇到以下一些情况,我们逐一分析

(7.1)加载中

这个问题呢,应该是redis缓存问题,把redis服务和nginx重启一下,多刷新一下,等待一会就行了

(7.1.1)出现加载中时,nginx输出的错误日志
Nginx错误日志路径:/var/log/nginx/error.log

Nginx正确日志路径:/var/log/nginx/access.log
[root@nginx nginx]# cat error.log

2024/09/14 09:57:38 [error] 1464#1464: *530 open() "/usr/share/nginx/html/static/images/favicon.ico" failed (2: No such file or directory), client: 192.168.143.1, server: localhost, request: "GET /static/images/favicon.ico HTTP/1.1", host: "192.168.143.167", referrer: "http://192.168.143.167/"

# 这里大致意思时我客户机请求服务器时,请求到那个前端下时没有找到那个图片

(7.1.2)正确日志
[root@nginx nginx]# tail -f access.log

192.168.143.1 - - [14/Sep/2024:10:06:31 +0800] "GET /shopping/categories HTTP/1.1" 200 3187 "http://192.168.143.167/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0" "-"

上述大致信息就是客户端请求到了本地的时间戳,使用了http1.1协议,edge浏览器请求到了内容,代表请求成功了

(7.1.3)redis日志
[root@redis redis]# tail -f redis.log

1605:M 14 Sep 09:57:48.564 * 1 changes in 900 seconds. Saving...

1605:M 14 Sep 09:57:48.764 * Background saving started by pid 2496

2496:C 14 Sep 09:57:48.766 * DB saved on disk

2496:C 14 Sep 09:57:48.766 * RDB: 6 MB of memory used by copy-on-write

1605:M 14 Sep 09:57:48.869 * Background saving terminated with success

# 通过日志可以发现,出现加载中时,redis缓存已经建立

所以这里出现加载中应该是一个缓冲网络的过程,重启一下服务就好了

(7.2)白板页面

出现白板页面有很多种情况,只要nginx节点配置正常,其他都错误,也会出现白板页面。

最主要的还是两种状况,jar包挂不上和数据库连不上

这里先分析数据库问题

(7.2.1)数据库问题

这里由于我已经做成功了,我是删掉了jar两个节点里的mysql映射,并关闭redis缓存,使页面出现白板,来测试数据库问题

由于这里的映射是连接的mycat中间件,所以我这里看一下mycat的日志

(7.2.2)mycat日志

建立连接的日志:/usr/local/mycat/logs/mycat.log

启动和运行相关的日志:/usr/local/mycat/logs/wrapper.log

[root@mycat logs]# tail -f mycat.log

2024-09-14 11:10:13.160  INFO [$_NIOREACTOR-1-RW] (io.mycat.backend.mysql.nio.handler.GetConnectionHandler.connectionAcquired(GetConnectionHandler.java:67)) - connected successfuly MySQLConnection [id=9, lastTime=1726283413160, user=root, schema=gpmall, old shema=gpmall, borrowed=true, fromSlaveDB=false, threadId=32, charset=latin1, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=192.168.143.161, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]

#写出了mycat连接从节点和使用逻辑库gpmall的一些详细幸信息

看一下wrapper.log

[root@mycat logs]# tail -f wrapper.log

INFO   | jvm 1    | 2024/09/14 11:10:13 | 2024-09-14 11:10:13,225 [INFO ][WrapperSimpleAppMain] init result :finished 10 success 10 target count:10  (io.mycat.backend.datasource.PhysicalDBPool:PhysicalDBPool.java:319)

# 显示mycat启动的一些操作都成功了,所以mycat没有问题

(7.2.3)jar包日志

一般是用nohup  &,他会生成一个nohup.out文件

查看一下nohup.out文件

ERROR 1585 --- [eate-1103174021] com.alibaba.druid.pool.DruidDataSource   : create connection SQLException, url: jdbc:mysql://mysql.mall:8066/gpmall?useUnicode=true&characterEncoding=utf8&useOldAliasMetadataBehavior=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&serverTimezone=UTC, errorCode 0, state 08S01

通过这个文件终于发现是与mysql出现了问题

我把映射添加回去,网页回来了

再次监控nohp.out文件,错误消失,全是详细信息了

(7.3)jar包挂不上

这里呢我想要还原jar包挂不上的场景

(7.3.1)还原包挂不上的场景

首先我采取了将zookeeper其中一个节点服务关闭,发现kafka并没有因为zookeeper服务的关闭而关闭,尝试挂包发现任然能够挂上。

然后我把该节点的kafka服务关闭,再次尝试挂包任能挂上,这也从侧面反映了集群的高可用性

最后采取删除映射的方式阻断jar节点与zookeeper节点的连接

这里由于删掉了映射,所以出现了掉包,但未什么不全掉就不知道了

然后查看一下nohup.out文件

[root@jar2 ~]# tail -20 nohup.out

2024-09-14 13:28:58.949  INFO 2562 --- [(zk1.mall:2181)] org.apache.zookeeper.ClientCnxn          : Opening socket connection to server zk1.mall:2181. Will not attempt to authenticate using SASL (unknown error)

# 大概意思就是客户端尝试与zookeeper服务器建立连接,进行通讯,发现连不上,出现未知错误。

如果真正遇到问题,挂包挂不上时,可以尝试查一下zookeeper的日志和kafka的日志看看是谁出了问题。

(7.3.2)zookeeper日志

由于zookeeper是外界传进来的压缩包,所以他的日志啥的肯定也放在解压的包里

执行zookeeper服务时重定向输出的一个文本文件zookeeper.out

Zookeeper位置:zookeeper包/bin/zookeeper.out

2024-09-14 12:46:49,764 [myid:1] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1056] - Closed socket connection for client /192.168.143.164:52434 which had sessionid 0x100000a383b0012

# 记录了我关闭zookeeper服务的信息

(7.3.3)kafka日志

Kafka服务是否能够启动成功是在zookeeper服务启动的基础上完成的。

服务日志:kafka包/logs/server.log

           Kafka包/kafkaserver.out

请求日志:kafka包/kafka-request.log

(8)页面访问

登录

通过网盘分享的文件:集群商城系统
链接: https://pan.baidu.com/s/1ZVO2_kEASpMhQx8apscyzw?pwd=1ct2 提取码: 1ct2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值