应用商城案例发布项目
实验需求
搭建一个gpmall应用商城系统,所使用的技术有:数据库主从+书写分离、zookeeper+Kafka、redis、
nginx部署负载均衡
| 主机 | ip地址 | 服务部署 |
|---|---|---|
| node1 | 192.168.100.10 | zookeeper、Kafka、部署mycat |
| node2/db1 | 192.168.100.20 | zookeeper、Kafka、数据库主库 |
| node3/db2 | 192.168.100.30 | zookeeper、Kafka、数据库从库 |
| node4 | 192.168.100.40 | httpd |
Kafka+zookeeper之前已部署
配置环境具体示例:
四台主机已关闭防火墙与selinux
4台主机设置时钟同步:
[root@node1 ~]# systemctl restart chronyd
[root@node1 ~]# systemctl enable chronyd
Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.
[root@node1 ~]# hwclock -w
[root@db1 ~]# systemctl restart chronyd
[root@db1 ~]# systemctl enable chronyd
Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.
[root@db1 ~]# hwclock -w
[root@db2 ~]# systemctl restart chronyd
[root@db2 ~]# systemctl enable chronyd
Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.
[root@db2 ~]# hwclock -w
[root@node4 ~]# systemctl restart chronyd
[root@node4 ~]# systemctl enable chronyd
Created symlink from /etc/systemd/system/multi-user.target.wants/chronyd.service to /usr/lib/systemd/system/chronyd.service.
[root@node4 ~]# hwclock -w
node4主机配置yum仓库:
[root@node4 ~]# cd /etc/yum.repos.d/
[root@node4 yum.repos.d]# ls
CentOS-Base.repo epel.repo epel-testing.repo
[root@node4 yum.repos.d]# rm -rf *
[root@node4 yum.repos.d]# vim server.repo
[aa]
name=aa1
baseurl=file:///mnt
enabled=1
gpgcheck=0
~
[root@node4 yum.repos.d]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
安装httpd:
[root@node4 ~]# yum -y install httpd
传输需要的文件:

[root@node4 ~]# cd /var/www/html/
[root@node4 html]# ls
project4
[root@node4 html]# cd project4/
[root@node4 project4]# ls
gpmall-cluster Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
gpmall-cluster.tar.gz zabbix
gpmall-repo zookeeper-3.4.14.tar.gz
kafka_2.11-1.1.1.tgz
[root@node4 project4]# cd ..
[root@node4 html]# systemctl restart httpd
[root@node4 html]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
配置db1、db2的/etc/hosts解析文件:
[root@db1 ~]# vim /etc/hosts
192.168.100.20 db1
192.168.100.30 db2
~
[root@db2 ~]# vim /etc/hosts
192.168.100.20 db1
192.168.100.30 db2
~
db1、db2配置 yum 仓库:
db1:
[root@db1 ~]# cd /etc/yum.repos.d/
[root@db1 yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@db1 yum.repos.d]# rm -rf *
[root@db1 yum.repos.d]# vim server.repo
[mariadb]
name=mariadb1
baseurl=http://192.168.100.40/project4/gpmall-repo
enabled=1
gpgcheck=0
~
db2:
[root@db2 ~]# cd /etc/yum.repos.d/
[root@db2 yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@db2 yum.repos.d]# rm -rf *
db1:
[root@db1 yum.repos.d]# scp server.repo root@db2:/etc/yum.repos.d/
The authenticity of host 'db2 (192.168.100.30)' can't be established.
ECDSA key fingerprint is SHA256:UN0UZbtBfFQeLR3836aFd9k4cm9na95JOPqBnPk05VU.
ECDSA key fingerprint is MD5:20:05:39:25:84:f6:1b:bb:8b:b3:ed:b9:bf:96:99:ba.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'db2' (ECDSA) to the list of known hosts.
server.repo 100% 96 22.9KB/s 00:00
db2:
[root@db2 yum.repos.d]# cat server.repo
[mariadb]
name=mariadb1
baseurl=http://192.168.100.40/project4/gpmall-repo
enabled=1
gpgcheck=0
db1、db2安装mariadb mariadb-server软件包:
[root@db1 ~]# yum -y install mariadb-server mariadb
.....
[root@db1 ~]# systemctl restart mariadb
[root@db1 ~]# systemctl enable mariadb
[root@db2 ~]# yum -y install mariadb-server mariadb
.....
[root@db2 ~]# systemctl restart mariadb
[root@db2 ~]# systemctl enable mariadb
初始化数据库:
db1:
[root@db1 ~]# mysql_secure_installation
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:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
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:
[root@db2 ~]# mysql_secure_installation
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:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
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!
db1:
[root@db1 ~]# vim /etc/my.cnf
...
[mysqld]
log_bin=mysql-bin
server_id=20
...
[root@db1 ~]# systemctl restart mariadb
db2:
[root@db2 ~]# vim /etc/my.cnf
...
[mysqld]
log_bin=mysql-bin
server_id=30
...
[root@db2 ~]# systemctl restart mariadb
db1、db2数据库权限设置,允许远程登录:
db1:
[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 *.* to root@'%' identified by '123456';
Query OK, 0 rows affected (0.001 sec)
db2:
[root@db2 ~]# 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 *.* to root@'%' identified by '123456';
Query OK, 0 rows affected (0.001 sec)
db1、db2数据库主从:
db1:
MariaDB [(none)]> grant replication slave on *.* to 'luoqi'@'192.168.100.30' identified by '123456';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
db2:
MariaDB [(none)]> change master to
-> master_host='192.168.100.20',
-> master_user='luoqi',
-> master_password='123456';
Query OK, 0 rows affected (0.008 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.001 sec)
.....
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
.....
ERROR: No query specified
测试效果:
db1:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)
MariaDB [(none)]> create database test;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> use test;
Database changed
MariaDB [test]> create table company(id int not null primary key,name varchar(50),addr varchar(255));
Query OK, 0 rows affected (0.008 sec)
MariaDB [test]> insert into company values(1,'redhat','usa');
Query OK, 1 row affected (0.003 sec)
db2(查看):
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.001 sec)
MariaDB [(none)]> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| company |
+----------------+
1 row in set (0.000 sec)
MariaDB [test]> select * from company;
+----+--------+------+
| id | name | addr |
+----+--------+------+
| 1 | redhat | usa |
+----+--------+------+
1 row in set (0.000 sec)
mycat 做数据库读写分离:
[root@node1 ~]# vim /etc/hosts
....
192.168.100.10 mycat
192.168.100.20 db1
192.168.100.30 db2
~
[root@node1 ~]# scp /etc/hosts root@db1:/etc/hosts
The authenticity of host 'db1 (192.168.100.20)' can't be established.
ECDSA key fingerprint is SHA256:UN0UZbtBfFQeLR3836aFd9k4cm9na95JOPqBnPk05VU.
ECDSA key fingerprint is MD5:20:05:39:25:84:f6:1b:bb:8b:b3:ed:b9:bf:96:99:ba.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'db1' (ECDSA) to the list of known hosts.
hosts 100% 217 59.3KB/s 00:00
[root@node1 ~]# scp /etc/hosts root@db2:/etc/hosts
The authenticity of host 'db2 (192.168.100.30)' can't be established.
ECDSA key fingerprint is SHA256:UN0UZbtBfFQeLR3836aFd9k4cm9na95JOPqBnPk05VU.
ECDSA key fingerprint is MD5:20:05:39:25:84:f6:1b:bb:8b:b3:ed:b9:bf:96:99:ba.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'db2' (ECDSA) to the list of known hosts.
hosts 100% 217 132.3KB/s 00:00
在mycat节点安装java环境------mycat是基于java的:
[root@node1 ~]# rpm -qa | grep java
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2018e-3.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
上传压缩包:
[root@node1 ~]# rz -E
rz waiting to receive.
[root@node1 ~]# tar -zxvf jdk-8u181-linux-x64.tar.gz -C /usr/local/
.....
[root@node1 ~]# cd /usr/local/
[root@node1 local]# ls
bin etc games include jdk1.8.0_181 lib lib64 libexec sbin share src
[root@node1 local]# vim /etc/profile
....
export JAVA_HOME=/usr/local/jdk1.8.0_181
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
~
[root@node1 local]# source /etc/profile
[root@node1 local]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
部署mycat服务,将Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz上传到mycat的/root目录下,并解压到/use/local:
[root@node1 ~]# rz -E
rz waiting to receive.
[root@node1 ~]# tar -xzvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local/
.....
[root@node1 ~]# cd /usr/local/
[root@node1 local]# ls
bin etc games include jdk1.8.0_181 lib lib64 libexec mycat sbin share src
定义环境变量:
[root@node1 local]# vim /etc/profile
....
export MYCAT_HOME=/usr/local/mycat
~
[root@node1 local]# source /etc/profile
编辑mycat服务读写分离的schema.xml,设置数据库写入节点为db1,读取节点db2,注意IP要修改:
[root@node1 local]# cd mycat/conf/
[root@node1 conf]# ls
autopartition-long.txt rule.xml
auto-sharding-long.txt schema.xml
auto-sharding-rang-mod.txt sequence_conf.properties
cacheservice.properties sequence_db_conf.properties
ehcache.xml sequence_distributed_conf.properties
index_to_charset.properties sequence_time_conf.properties
log4j2.xml server.xml
migrateTables.properties sharding-by-enum.txt
myid.properties wrapper.conf
partition-hash-int.txt zkconf
partition-range-mod.txt zkdownload
[root@node1 conf]# vim schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="USERDB" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn1"></schema>
<dataNode name="dn1" dataHost="localhost1" database="test" />
<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.100.20:3306" user="root" password="123456">
<readHost host="hostS1" url="192.168.100.30:3306" user="root" password="123456" />
</writeHost></dataHost>
</mycat:schema>
~
编辑mycat用户的/usr/local/mycat/conf/目录下的server.xml,修改root用户的密码123456,访问mycat的逻辑库为USERDB,注意删除后几行
[root@node1 conf]# vim server.xml
删除如下5行,在文件最末尾处
<user name="user">
<property name="password">user</property>
<property name="schemas">TESTDB</property>
<property name="readOnly">true</property>
</user>
然后需要修改一出地方-----改成USERDB:
<user name="root">
<property name="password">123456</property>
<property name="schemas">USERDB</property>
启动mycat服务:
[root@node1 conf]# cd ..
[root@node1 mycat]# ls
bin catlet conf lib logs version.txt
[root@node1 mycat]# cd bin/
[root@node1 bin]# ls
dataMigrate.sh mycat startup_nowrap.sh wrapper-linux-x86-32
init_zk_data.sh rehash.sh wrapper-linux-ppc-64 wrapper-linux-x86-64
[root@node1 bin]# ./mycat start
Starting Mycat-server...
(查看8066、9066端口是否开启,如果有开放8066和9066端口,则表示mycat服务开启成功 mycat服务默认的数据端口是8066,而9066端口则是mycat管理端口,用于管理mycat的整个集群状态)
[root@node1 bin]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:6000 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 1 127.0.0.1:32000 *:*
LISTEN 0 100 :::9066 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 50 ::ffff:192.168.100.10:3888 :::*
LISTEN 0 128 :::6000 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 50 :::39607 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 50 :::45849 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 50 :::42427 :::*
LISTEN 0 50 :::1984 :::*
LISTEN 0 100 :::8066 :::*
LISTEN 0 50 ::ffff:192.168.100.10:9092 :::*
LISTEN 0 50 :::38852 :::*
LISTEN 0 50 :::2181
[root@node1 bin]# cd /etc/yum.repos.d/
[root@node1 yum.repos.d]# rm -rf *
[root@node1 yum.repos.d]# scp root@192.168.100.20:/etc/yum.repos.d/server.repo .
server.repo 100% 96 30.7KB/s 00:00
[root@node1 yum.repos.d]# cat server.repo
[mariadb]
name=mariadb1
baseurl=http://192.168.100.40/project4/gpmall-repo
enabled=1
gpgcheck=0
在mycat节点验证
安装MariaDB-client客户端:
mycat:
[root@node1 ~]# yum -y install MariaDB-client
在本地使用数据端口登录到mysql数据中,查询和插入数据,然后使用管理端口查看读写分离效果:
[root@node1 ~]# mysql -h127.0.0.1 -P8066 -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+----------+
| DATABASE |
+----------+
| USERDB |
+----------+
1 row in set (0.003 sec)
MySQL [(none)]> use USERDB;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [USERDB]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| company |
+----------------+
1 row in set (0.002 sec)
MySQL [USERDB]> select * from company;
+----+--------+------+
| id | name | addr |
+----+--------+------+
| 1 | redhat | usa |
+----+--------+------+
1 row in set (0.057 sec)
MySQL [USERDB]> insert into company values(2,'AWS','usa');
Query OK, 1 row affected (0.020 sec)
MySQL [USERDB]> select * from company;
+----+--------+------+
| id | name | addr |
+----+--------+------+
| 1 | redhat | usa |
| 2 | AWS | usa |
+----+--------+------+
2 rows in set (0.002 sec)
db1:
MariaDB [test]> select * from company;
+----+--------+------+
| id | name | addr |
+----+--------+------+
| 1 | redhat | usa |
| 2 | AWS | usa |
+----+--------+------+
2 rows in set (0.002 sec)
验证mycat服务对数据库读写操作分离:
[root@node1 ~]# 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.100.20 | 3306 | W | 0 | 10 | 1000 | 75 | 0 | 1 |
| dn1 | hostS1 | mysql | 192.168.100.30 | 3306 | R | 0 | 7 | 1000 | 73 | 4 | 0 |
+----------+--------+-------+----------------+------+------+--------+------+------+---------+-----------+------------+
db1:
[root@db1 ~]# rpm -qa | grep java
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2018e-3.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
db2:
[root@db2 ~]# rpm -qa | grep java
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2018e-3.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
mycat:
[root@node1 ~]# cd /usr/local/
[root@node1 local]# ls
bin etc games include jdk1.8.0_181 lib lib64 libexec mycat sbin share src
[root@node1 local]# scp -r jdk1.8.0_181/ root@192.168.100.20:/usr/local/
[root@node1 local]# scp -r jdk1.8.0_181/ root@192.168.100.30:/usr/local/
[root@node1 local]# scp /etc/profile root@192.168.100.20:/etc/profile
profile 100% 1994 365.0KB/s 00:00
[root@node1 local]# scp /etc/profile root@192.168.100.30:/etc/profile
profile 100% 1994 608.4KB/s 00:00
db1:
[root@db1 ~]# vim /etc/profile
//删除最后一行
[root@db1 ~]# source /etc/profile
[root@db1 ~]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
db2:
[root@db2 ~]# vim /etc/profile
//删除最后一行
[root@db2 ~]# source /etc/profile
[root@db2 ~]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
gpmall集群:
mycat:
[root@node1 ~]# vim /etc/hosts
....
192.168.100.10 zookeeper1
192.168.100.20 zookeeper2
192.168.100.30 zookeeper3
~
[root@node1 ~]# scp /etc/hosts root@192.168.100.20:/etc/hosts
hosts 100% 295 220.6KB/s 00:00
[root@node1 ~]# scp /etc/hosts root@192.168.100.30:/etc/hosts
hosts
scp拷贝到另外两台计算机:
上传压缩包并解压:
[root@node1 ~]# rz -E
rz waiting to receive.
[root@node1 ~]# tar -zxvf zookeeper-3.4.8.tar.gz
....
[root@node1 ~]# mv zookeeper-3.4.8 zookeeper
[root@node1 ~]# cd zookeeper/
[root@node1 zookeeper]# ls
bin contrib ivy.xml README_packaging.txt zookeeper-3.4.8.jar
build.xml dist-maven lib README.txt zookeeper-3.4.8.jar.asc
CHANGES.txt docs LICENSE.txt recipes zookeeper-3.4.8.jar.md5
conf ivysettings.xml NOTICE.txt src zookeeper-3.4.8.jar.sha1
[root@node1 zookeeper]# cd conf/
[root@node1 conf]# ls
configuration.xsl log4j.properties zoo_sample.cfg
[root@node1 conf]# cp zoo_sample.cfg zoo.cfg
[root@node1 conf]# ll
total 16
-rw-rw-r-- 1 shenyifeng shenyifeng 535 Feb 6 2016 configuration.xsl
-rw-rw-r-- 1 shenyifeng shenyifeng 2161 Feb 6 2016 log4j.properties
-rw-r--r-- 1 root root 922 Oct 27 20:55 zoo.cfg
-rw-rw-r-- 1 shenyifeng shenyifeng 922 Feb 6 2016 zoo_sample.cfg
[root@node1 conf]# cd
[root@node1 ~]# ll
total 286788
-rw-------. 1 root root 2028 Jul 23 11:40 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Desktop
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Documents
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Downloads
-rw-r--r--. 1 root root 2076 Jul 23 11:42 initial-setup-ks.cfg
-rw-r--r-- 1 root root 185646832 Oct 9 2022 jdk-8u181-linux-x64.tar.gz
drwxr-xr-x 7 root root 101 Oct 27 16:31 kafka_2.11-2.4.0
-rw-r--r-- 1 root root 70057083 Oct 9 2022 kafka_2.11-2.4.0.tgz
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Music
-rw-r--r-- 1 root root 15662280 Jan 13 2020 Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Pictures
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Public
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Templates
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Videos
drwxr-xr-x 10 shenyifeng shenyifeng 4096 Feb 6 2016 zookeeper
-rw-r--r-- 1 root root 22261552 Aug 8 2022 zookeeper-3.4.8.tar.gz
-rw-r--r-- 1 root root 27838 Oct 27 16:37 zookeeper.out
[root@node1 ~]# chown -R root.root zookeeper
[root@node1 ~]# ll
total 286788
-rw-------. 1 root root 2028 Jul 23 11:40 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Desktop
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Documents
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Downloads
-rw-r--r--. 1 root root 2076 Jul 23 11:42 initial-setup-ks.cfg
-rw-r--r-- 1 root root 185646832 Oct 9 2022 jdk-8u181-linux-x64.tar.gz
drwxr-xr-x 7 root root 101 Oct 27 16:31 kafka_2.11-2.4.0
-rw-r--r-- 1 root root 70057083 Oct 9 2022 kafka_2.11-2.4.0.tgz
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Music
-rw-r--r-- 1 root root 15662280 Jan 13 2020 Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Pictures
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Public
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Templates
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Videos
drwxr-xr-x 10 root root 4096 Feb 6 2016 zookeeper
-rw-r--r-- 1 root root 22261552 Aug 8 2022 zookeeper-3.4.8.tar.gz
-rw-r--r-- 1 root root 27838 Oct 27 16:37 zookeeper.out
[root@node1 ~]# cd zookeeper/
[root@node1 zookeeper]# cd conf/
[root@node1 conf]# ll
total 16
-rw-rw-r-- 1 root root 535 Feb 6 2016 configuration.xsl
-rw-rw-r-- 1 root root 2161 Feb 6 2016 log4j.properties
-rw-r--r-- 1 root root 922 Oct 27 20:55 zoo.cfg
-rw-rw-r-- 1 root root 922 Feb 6 2016 zoo_sample.cfg
scp -r 同步到三台机器上:
mycat:
[root@node1 conf]# mkdir /tmp/zookeeper
[root@node1 conf]# ll /tmp/
total 0
drwxr-xr-x 2 root root 6 Oct 27 20:59 hsperfdata_root
drwxr-xr-x 3 root root 230 Oct 27 20:59 kafka-logs
drwx------ 3 root root 17 Oct 29 10:18 systemd-private-b292bd7d937e42f6b53bd69dee1bb580-bolt.service-ou8MXz
drwx------ 3 root root 17 Oct 29 10:18 systemd-private-b292bd7d937e42f6b53bd69dee1bb580-chronyd.service-be3JcF
drwx------ 3 root root 17 Oct 29 10:18 systemd-private-b292bd7d937e42f6b53bd69dee1bb580-colord.service-TlcAsF
drwx------ 3 root root 17 Oct 29 10:18 systemd-private-b292bd7d937e42f6b53bd69dee1bb580-cups.service-r3cEEC
drwx------ 3 root root 17 Oct 29 10:18 systemd-private-b292bd7d937e42f6b53bd69dee1bb580-rtkit-daemon.service-JQbalc
drwx------ 2 root root 6 Oct 27 10:35 vmware-root_8711-3853422910
drwx------ 2 root root 6 Oct 29 10:18 vmware-root_8721-3886323497
drwxr-xr-x 2 root root 6 Oct 29 10:32 zookeeper
[root@node1 conf]# vim zoo.cfg
....
server.1=192.168.100.10:2888:3888
server.2=192.168.100.20:2888:3888
server.3=192.168.100.30:2888:3888
~
[root@node1 conf]# echo 1 > /tmp/zookeeper/myid
[root@node1 ~]# scp -r zookeeper root@192.168.100.20:/root/
....
[root@node1 ~]# scp -r zookeeper root@192.168.100.30:/root/
....
db1:
[root@db1 ~]# mkdir /tmp/zookeeper
[root@db1 ~]# ll
total 40
-rw-------. 1 root root 2028 Jul 23 11:40 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Desktop
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Documents
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Downloads
-rw-r--r--. 1 root root 2076 Jul 23 11:42 initial-setup-ks.cfg
drwxr-xr-x 7 root root 101 Oct 27 16:32 kafka_2.11-2.4.0
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Music
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Pictures
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Public
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Templates
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Videos
drwxr-xr-x 10 root root 4096 Oct 29 10:40 zookeeper
-rw-r--r-- 1 root root 25733 Oct 27 20:59 zookeeper.out
[root@db1 ~]# cd zookeeper/
[root@db1 zookeeper]# ll
total 1556
drwxr-xr-x 2 root root 149 Oct 29 10:40 bin
-rw-r--r-- 1 root root 83235 Oct 29 10:40 build.xml
-rw-r--r-- 1 root root 88625 Oct 29 10:40 CHANGES.txt
drwxr-xr-x 2 root root 92 Oct 29 10:40 conf
drwxr-xr-x 10 root root 130 Oct 29 10:40 contrib
drwxr-xr-x 2 root root 4096 Oct 29 10:40 dist-maven
drwxr-xr-x 6 root root 4096 Oct 29 10:40 docs
-rw-r--r-- 1 root root 1953 Oct 29 10:40 ivysettings.xml
-rw-r--r-- 1 root root 3498 Oct 29 10:40 ivy.xml
drwxr-xr-x 4 root root 266 Oct 29 10:40 lib
-rw-r--r-- 1 root root 11938 Oct 29 10:40 LICENSE.txt
-rw-r--r-- 1 root root 171 Oct 29 10:40 NOTICE.txt
-rw-r--r-- 1 root root 1770 Oct 29 10:40 README_packaging.txt
-rw-r--r-- 1 root root 1585 Oct 29 10:40 README.txt
drwxr-xr-x 5 root root 47 Oct 29 10:40 recipes
drwxr-xr-x 8 root root 191 Oct 29 10:40 src
-rw-r--r-- 1 root root 1360961 Oct 29 10:40 zookeeper-3.4.8.jar
-rw-r--r-- 1 root root 819 Oct 29 10:40 zookeeper-3.4.8.jar.asc
-rw-r--r-- 1 root root 33 Oct 29 10:40 zookeeper-3.4.8.jar.md5
-rw-r--r-- 1 root root 41 Oct 29 10:40 zookeeper-3.4.8.jar.sha1
[root@db1 ~]# echo 2 > /tmp/zookeeper/myid
db2:
[root@db2 ~]# mkdir /tmp/zookeeper
[root@db2 ~]# ll
total 28
-rw-------. 1 root root 2028 Jul 23 11:40 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Desktop
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Documents
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Downloads
-rw-r--r--. 1 root root 2076 Jul 23 11:42 initial-setup-ks.cfg
drwxr-xr-x 7 root root 101 Oct 27 16:32 kafka_2.11-2.4.0
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Music
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Pictures
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Public
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Templates
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Videos
drwxr-xr-x 10 root root 4096 Oct 29 10:41 zookeeper
-rw-r--r-- 1 root root 16170 Oct 27 20:59 zookeeper.out
[root@db2 ~]# echo 3 > /tmp/zookeeper/myid
mycat:
[root@node1 ~]# vim /etc/profile
...
export ZOOKEEPER_HOME=/root/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
~
[root@node1 ~]# source /etc/profile
db1:
[root@db1 ~]# vim /etc/profile
...
export ZOOKEEPER_HOME=/root/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
~
[root@db1 ~]# source /etc/profile
db2:
[root@db2 ~]# vim /etc/profile
...
export ZOOKEEPER_HOME=/root/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
~
[root@db2 ~]# source /etc/profile
mycat:
[root@node1 ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@node1 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@node1 ~]# jps
10401 QuorumPeerMain
10674 Jps
10598 WrapperSimpleApp
db1:
[root@db1 ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@db1 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[root@db1 ~]# jps
10518 Jps
10439 QuorumPeerMain
db2:
[root@db2 ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@db2 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@db2 ~]# jps
10518 Jps
10439 QuorumPeerMain
Kafka集群部署:
mycat:
[root@node1 ~]# ls
anaconda-ks.cfg kafka_2.11-2.4.0 Templates
Desktop kafka_2.11-2.4.0.tgz Videos
Documents Music zookeeper
Downloads Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz zookeeper-3.4.8.tar.gz
initial-setup-ks.cfg Pictures zookeeper.out
jdk-8u181-linux-x64.tar.gz Public
[root@node1 ~]# mv kafka_2.11-2.4.0 kafka
[root@node1 ~]# vim /etc/profile
... //添加两行
export KAFKA_HOME=/root/kafka
export PATH=$PATH:$KAFKA_HOME/bin
~
[root@node1 ~]# source /etc/profile
db1:
[root@db1 ~]# vim /etc/profile
... //添加两行
export KAFKA_HOME=/root/kafka
export PATH=$PATH:$KAFKA_HOME/bin
~
[root@db1 ~]# source /etc/profile
db2:
[root@db2 ~]# vim /etc/profile
... //添加两行
export KAFKA_HOME=/root/kafka
export PATH=$PATH:$KAFKA_HOME/bin
~
[root@db2 ~]# source /etc/profile
mycat:
[root@node1 ~]# kafka-server-start.sh -daemon ./kafka/config/server.properties
[root@node1 ~]# jps
10401 QuorumPeerMain
10598 WrapperSimpleApp
16873 Kafka
16969 Jps
db1:
[root@db1 ~]# kafka-server-start.sh -daemon ./kafka/config/server.properties
[root@db1 ~]# jps
13651 Kafka
13720 Jps
10447 QuorumPeerMain
db2:
[root@db2 ~]# kafka-server-start.sh -daemon ./kafka/config/server.properties
[root@db2 ~]# jps
10439 QuorumPeerMain
13207 Jps
13135 Kafka
jps
测试服务
mycat节点:
[root@node1 ~]# kafka-topics.sh --create --zookeeper 192.168.100.10:2181 --replication-factor 1 --partitions 1 --topic test
Created topic test.
db1:
[root@db1 ~]# kafka-topics.sh --list --zookeeper 192.168.100.20:2181
test
[root@db1 ~]# kafka-topics.sh --list --zookeeper 192.168.100.30:2181
test
db2:
[root@db2 ~]# kafka-topics.sh --list --zookeeper 192.168.100.20:2181
test
[root@db2 ~]# kafka-topics.sh --list --zookeeper 192.168.100.30:2181
test
应用集群nginx,java(tomcat)
数据库的导入:
db1:
[root@db1 ~]# rz -E
rz waiting to receive.
[root@db1 ~]# ll
total 168
-rw-------. 1 root root 2028 Jul 23 11:40 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Desktop
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Documents
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Downloads
-rw-r--r-- 1 root root 59239 Jan 13 2020 gpmall.sql
-rw-r--r--. 1 root root 2076 Jul 23 11:42 initial-setup-ks.cfg
drwxr-xr-x 7 root root 101 Oct 27 16:32 kafka
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Music
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Pictures
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Public
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Templates
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Videos
drwxr-xr-x 10 root root 4096 Oct 29 10:40 zookeeper
-rw-r--r-- 1 root root 96151 Oct 29 16:22 zookeeper.out
[root@db1 ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 20
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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.002 sec)
MariaDB [(none)]> create database gpmall;
Query OK, 1 row affected (0.006 sec)
MariaDB [(none)]> use gpmall;
Database changed
MariaDB [gpmall]> source /root/gpmall.sql;
.....
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.000 sec)
mycat:(修改表名gpmall,gpmall)
[root@node1 ~]# cd /usr/local/mycat/
[root@node1 mycat]# ls
bin catlet conf lib logs version.txt
[root@node1 mycat]# cd conf/
[root@node1 conf]# ls
autopartition-long.txt migrateTables.properties sequence_distributed_conf.properties
auto-sharding-long.txt myid.properties sequence_time_conf.properties
auto-sharding-rang-mod.txt partition-hash-int.txt server.xml
cacheservice.properties partition-range-mod.txt sharding-by-enum.txt
dnindex.properties rule.xml wrapper.conf
ehcache.xml schema.xml zkconf
index_to_charset.properties sequence_conf.properties zkdownload
log4j2.xml sequence_db_conf.properties
[root@node1 conf]# vim schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="gpmall" checkSQLschema="true" 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.100.20:3306" user="root" password="123456">
<readHost host="hostS1" url="192.168.100.30:3306" user="root" password="123456" />
</writeHost>
</dataHost>
</mycat:schema>
~
[root@node1 conf]# vim server.xml
....
<property name="schemas">gpmall</property>
....
[root@node1 conf]# cd ..
[root@node1 mycat]# cd bin/
[root@node1 bin]# ./mycat restart
Stopping Mycat-server...
Stopped Mycat-server.
Starting Mycat-server...
查看Mycat服务是否启动,命令如下:(看到8066端口说明Mycat服务启动)
[root@node1 bin]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:6000 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 1 127.0.0.1:32000 *:*
LISTEN 0 100 :::9066 :::*
LISTEN 0 50 :::45674 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 50 ::ffff:192.168.100.10:3888 :::*
LISTEN 0 128 :::6000 :::*
LISTEN 0 50 :::33842 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 50 :::33853 :::*
LISTEN 0 50 :::1984 :::*
LISTEN 0 100 :::8066 :::*
LISTEN 0 50 ::ffff:192.168.100.10:9092 :::*
LISTEN 0 50 :::2181 :::*
LISTEN 0 50 :::44326 :::*
缓存服务器redis:
mycat:
[root@node1 bin]# vim /etc/hosts
.....
192.168.100.10 mycat
192.168.100.20 db1
192.168.100.30 db2
192.168.100.10 zookeeper1
192.168.100.20 zookeeper2
192.168.100.30 zookeeper3
192.168.100.10 redis
~
db1:
[root@db1 ~]# vim /etc/hosts
....
192.168.100.10 mycat
192.168.100.20 db1
192.168.100.30 db2
192.168.100.10 zookeeper1
192.168.100.20 zookeeper2
192.168.100.30 zookeeper3
192.168.100.10 redis
~
db2:
[root@db2 ~]# vim /etc/hosts
.....
192.168.100.10 mycat
192.168.100.20 db1
192.168.100.30 db2
192.168.100.10 zookeeper1
192.168.100.20 zookeeper2
192.168.100.30 zookeeper3
192.168.100.10 redis
~
mycat:
[root@node1 ~]# ls /etc/yum.repos.d/
server.repo
[root@node1 ~]# yum -y install redis
....
[root@node1 ~]# vim /etc/redis.conf
....
#bind 127.0.0.1
....
protected-mode no //yes改为no
....
[root@node1 ~]# systemctl restart redis
[root@node1 ~]# systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
检查Redis服务启动,命令如下:(检查到6379端口即证明Redis服务运行)
[root@node1 ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:6379 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:6000 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 1 127.0.0.1:32000 *:*
LISTEN 0 100 :::9066 :::*
LISTEN 0 50 :::45674 :::*
LISTEN 0 128 :::6379 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 50 ::ffff:192.168.100.10:3888 :::*
LISTEN 0 128 :::6000 :::*
LISTEN 0 50 :::33842 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 50 :::33853 :::*
LISTEN 0 50 :::1984 :::*
LISTEN 0 100 :::8066 :::*
LISTEN 0 50 ::ffff:192.168.100.10:9092 :::*
LISTEN 0 50 :::2181 :::*
LISTEN 0 50 :::44326 :::*
部署集群应用系统:
mycat:
[root@node1 ~]# vim /etc/hosts
.....
192.168.100.10 mysql.mall
192.168.100.10 zk1.mall
192.168.100.20 zk2.mall
192.168.100.30 zk3.mall
192.168.100.10 kafka1.mall
192.168.100.20 kafka2.mall
192.168.100.30 kafka3.mall
192.168.100.10 redis.mall
~
[root@node1 ~]# scp /etc/hosts root@192.168.100.20:/etc/hosts
hosts 100% 521 277.0KB/s 00:00
[root@node1 ~]# scp /etc/hosts root@192.168.100.30:/etc/hosts
hosts 100% 521 415.4KB/s 00:00
上传所需文件:
db1:
[root@db1 ~]# rz -E
rz waiting to receive.
[root@db1 ~]# ll
total 196928
-rw-------. 1 root root 2028 Jul 23 11:40 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Desktop
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Documents
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Downloads
-rw-r--r-- 1 root root 47765234 Jan 13 2020 gpmall-shopping-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 root root 59239 Jan 13 2020 gpmall.sql
-rw-r--r-- 1 root root 39005479 Jan 13 2020 gpmall-user-0.0.1-SNAPSHOT.jar
-rw-r--r--. 1 root root 2076 Jul 23 11:42 initial-setup-ks.cfg
drwxr-xr-x 7 root root 101 Oct 27 16:32 kafka
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Music
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Pictures
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Public
-rw-r--r-- 1 root root 53627038 Jan 13 2020 shopping-provider-0.0.1-SNAPSHOT.jar
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Templates
-rw-r--r-- 1 root root 61077919 Jan 13 2020 user-provider-0.0.1-SNAPSHOT.jar
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Videos
drwxr-xr-x 10 root root 4096 Oct 29 10:40 zookeeper
-rw-r--r-- 1 root root 96151 Oct 29 16:22 zookeeper.out
[root@db1 ~]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[1] 17361
[root@db1 ~]# nohup: ignoring input and appending output to 'nohup.out'
[root@db1 ~]# jps
17392 Jps
17361 jar
13651 Kafka
10447 QuorumPeerMain
[root@db1 ~]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[2] 17471
[root@db1 ~]# nohup: ignoring input and appending output to 'nohup.out'
[root@db1 ~]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[3] 17546
[root@db1 ~]# nohup: ignoring input and appending output to 'nohup.out'
[root@db1 ~]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[4] 17609
[root@db1 ~]# nohup: ignoring input and appending output to 'nohup.out'
[root@db1 ~]# jobs -l
[1] 17361 Running nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[2] 17471 Running nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[3]- 17546 Running nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[4]+ 17609 Running nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
db2:
[root@db2 ~]# rz -E
rz waiting to receive.
[root@db2 ~]# ll
total 196788
-rw-------. 1 root root 2028 Jul 23 11:40 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Desktop
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Documents
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Downloads
-rw-r--r-- 1 root root 47765234 Jan 13 2020 gpmall-shopping-0.0.1-SNAPSHOT.jar
-rw-r--r-- 1 root root 39005479 Jan 13 2020 gpmall-user-0.0.1-SNAPSHOT.jar
-rw-r--r--. 1 root root 2076 Jul 23 11:42 initial-setup-ks.cfg
drwxr-xr-x 7 root root 101 Oct 27 16:32 kafka
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Music
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Pictures
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Public
-rw-r--r-- 1 root root 53627038 Jan 13 2020 shopping-provider-0.0.1-SNAPSHOT.jar
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Templates
-rw-r--r-- 1 root root 61077919 Jan 13 2020 user-provider-0.0.1-SNAPSHOT.jar
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Videos
drwxr-xr-x 10 root root 4096 Oct 29 10:41 zookeeper
-rw-r--r-- 1 root root 15641 Oct 29 16:22 zookeeper.out
[root@db2 ~]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[1] 16944
[root@db2 ~]# nohup: ignoring input and appending output to 'nohup.out'
[root@db2 ~]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[2] 16995
[root@db2 ~]# nohup: ignoring input and appending output to 'nohup.out'
[root@db2 ~]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[3] 17052
[root@db2 ~]# nohup: ignoring input and appending output to 'nohup.out'
[root@db2 ~]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[4] 17107
[root@db2 ~]# nohup: ignoring input and appending output to 'nohup.out'
[root@db2 ~]# jobs -l
[1] 16944 Running nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[2] 16995 Running nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[3]- 17052 Running nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[4]+ 17107 Running nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
网站前端:
[root@node1 ~]# yum -y install nginx
.....
[root@node1 ~]# cd /usr/share/nginx/html/
[root@node1 html]# ls
50x.html index.html
[root@node1 html]# rm -rf *

[root@node1 ~]# ls
anaconda-ks.cfg jdk-8u181-linux-x64.tar.gz Public
Desktop kafka Templates
dist kafka_2.11-2.4.0.tgz Videos
Documents Music zookeeper
Downloads Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz zookeeper-3.4.8.tar.gz
initial-setup-ks.cfg Pictures zookeeper.out
[root@node1 ~]# ll
total 286800
-rw-------. 1 root root 2028 Jul 23 11:40 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Desktop
drwxr-xr-x 3 root root 38 Oct 29 19:23 dist
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Documents
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Downloads
-rw-r--r--. 1 root root 2076 Jul 23 11:42 initial-setup-ks.cfg
-rw-r--r-- 1 root root 185646832 Oct 9 2022 jdk-8u181-linux-x64.tar.gz
drwxr-xr-x 7 root root 101 Oct 27 16:31 kafka
-rw-r--r-- 1 root root 70057083 Oct 9 2022 kafka_2.11-2.4.0.tgz
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Music
-rw-r--r-- 1 root root 15662280 Jan 13 2020 Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Pictures
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Public
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Templates
drwxr-xr-x. 2 root root 6 Jul 23 11:43 Videos
drwxr-xr-x 10 root root 4096 Feb 6 2016 zookeeper
-rw-r--r-- 1 root root 22261552 Aug 8 2022 zookeeper-3.4.8.tar.gz
-rw-r--r-- 1 root root 40561 Oct 29 17:05 zookeeper.out
[root@node1 ~]# cd dist/
[root@node1 dist]# ls
index.html static
[root@node1 dist]# ll
total 4
-rw-r--r-- 1 root root 727 Oct 29 19:23 index.html
drwxr-xr-x 10 root root 101 Oct 29 19:23 static
[root@node1 ~]# cp -rvf dist/* /usr/share/nginx/html/
....
[root@node1 ~]# cd /usr/share/nginx/html/
[root@node1 html]# ls
index.html static
[root@node1 html]# ll
total 4
-rw-r--r-- 1 root root 727 Oct 29 19:29 index.html
drwxr-xr-x 10 root root 101 Oct 29 19:29 static
[root@node1 html]# cd /etc/nginx/
[root@node1 nginx]# ls
conf.d koi-utf mime.types nginx.conf uwsgi_params
fastcgi_params koi-win modules scgi_params win-utf
[root@node1 nginx]# cd conf.d/
[root@node1 conf.d]# ls
default.conf
[root@node1 conf.d]# cp default.conf default.conf.bak
[root@node1 conf.d]# vim default.conf
upstream myuser {
server 192.168.100.20:8082;
server 192.168.100.30:8082;
ip_hash;
}
upstream myshopping {
server 192.168.100.20:8081;
server 192.168.100.30:8081;
ip_hash;
}
upstream mycashier {
server 192.168.100.20:8083;
server 192.168.100.30: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;
......
[root@node1 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@node1 conf.d]# systemctl restart nginx
[root@node1 conf.d]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
浏览器访问:http://192.168.100.10
