gpmall商城搭建
1 环境配置
-
gpmall-repo文件夹
-
Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
-
gpmall.sql
-
kafka_2.11-1.1.1.tgz
-
zookeeper-3.4.14.tar.gz
-
dist文件夹
-
gpmall-shopping-0.0.1-SNAPSHOT.jar
-
gpmall-user-0.0.1-SNAPSHOT.jar
-
shopping-provider-0.0.1-SNAPSHOT.jar
-
user-provider-0.0.1-SNAPSHOT.jar
-
关闭防火墙<每个机器节点>
-
配置yum源
2 . Mycat数据库分离(主从与读写分离)
可参考添加链接描述
2.1 主机规划
IP | 主机名 | 节点 |
---|---|---|
192.168.237.132 | db1 | Mariadb数据库集群主节点 |
192.168.237.133 | db2 | Mariadb数据库集群主节点 |
192.168.237.131 | mycat | Mycat中间件服务节点 |
2.2配置mycat 三个节点
# hostnamectl set-hostname mycat
# hostnamectl set-hostname db1
# hostnamectl set-hostname db2
cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.131 mycat
192.168.200.132 db1
192.168.200.133 db2
2.3 3个节点配置 yum 源并安装java
# mv /etc/yum.repos.d/* /media/
# cat /etc/yum.repos.d/local.repo
[mariadb]
name=mariadb
baseurl=file:///opt/gpmall-repo
gpgcheck=0
enabled=1
yum clean all
yum repolist
#yum install -y java-1.8.0-openjdk java-1.8.0 openjdk-devel
java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
2.4 在db1节点和db2 节点安装mariadb并初始数据库# yum install -y mariadb mariadb-server
# systemctl start mariadb
# systemctl enable mariadb
#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
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!
2.6 配置db1与db2节点的 my.cnf文件
# cat /etc/my.cnf
[mysqld]
log_bin=mysql-bin
binlog_ignore_db=mysql
server_id=132 #和节点ip一致,db2为133
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
2.7 登录数据库,db1配置权限,db2连接
以下在db1节点操作
# systemctl restart mariadb
# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 137
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";
#在主节点db1数据库上创建一个user用户让从节点db2连接,并赋予从节点同步主节点数据库的权限,命令如下。
MariaDB [(none)]> grant replication slave on *.* to 'user'@'db2' identified by '123456';
以下操作在db2上操作
# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 88
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)]> change master to master_host='db1',master_user='user',master_password='123456';
MariaDB [(none)]> start slave;
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.000009
Read_Master_Log_Pos: 527
Relay_Log_File: mariadb-relay-bin.000019
Relay_Log_Pos: 811
Relay_Master_Log_File: mysql-bin.000009
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: 527
Relay_Log_Space: 1391
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