当前位置:网站首页>CentOS MySQL multi instance deployment

CentOS MySQL multi instance deployment

2022-04-23 16:48:00 A coir boat in the broken white clouds

One . Clear the original environment mysql、mariadb

# Check to see if there is mysql Of rpm package 
rpm -qa|grep mysql
 Delete the queried package ( Delete... According to the actual situation )
rpm -e  name 

Two . Install multiple instances

# Enter the temporary folder 
cd /tmp
ls
# decompression mysql Compressed package 
tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
ls
# Move to installation directory 
mv mysql-5.7.30-linux-glibc2.12-x86_64/ /usr/local/mysql
# Enter the installation directory 
cd /usr/local/mysql
ls

# Create... In the system mysql account number 
groupadd -g 1002 mysql
useradd -u 1002 -g 1002 -M -s /sbin/nologin mysql
# verification mysql account number 
id mysql

# Add environment variables 
echo 'export PATH=$PATH:/usr/local/mysql/bin' >>  /etc/profile
source /etc/profile
# establish data Storage directory 
mkdir /data/mysql_platform/data
mkdir /data/mysql_storage/data
mkdir /data/mysql_production/data
mkdir /data/mysql_sale/data
mkdir /data/mysql_aggregate/data

#my.cnf Storage address ( Customize
 Insert picture description here
#my.cnf To configure

[mysql]
#  Set up mysql Client default character set 
default-character-set=utf8
[mysqld]
# Port number ( Can't repeat , Distinguish multiple instances by port number 
port=3302                       
#  Set up mysql Installation directory 
basedir=/usr/local/mysql
#  Set up mysql Database data storage directory 
datadir=/data/mysql_storage/data
# Server's id( Can't repeat 
server-id=102
# Multiple instances start at this address 
socket=/data/mysql_storage/mysql.sock
#  Error log storage directory 
log_error=/data/mysql_storage/logs/mysql.log
#  Binary log storage directory 
log_bin=/data/mysql_storage/logs/mysql-bin
# Binary file format 
binlog-format=MIXED     
#  Maximum connections allowed 
max_connections=200
#  The character set used by the server defaults to 8 Bit coded latin1 Character set 
character-set-server=utf8
#  The default storage engine that will be used when creating a new table 
default-storage-engine=INNODB
# The name of the synchronized database 
replicate-do-db=storage_release
# establish slave_master_info Table of 
master-info-repository = table  
# establish mysql.slave_relay_info Table to record the location information of synchronization 
relay-log-info-repository = table

# Of other instances my.cnf The configuration is the same as above

# Will all .service The documents are stored in /etc/systemd/system Under the table of contents
 Insert picture description here
# modify defaults-file For its counterpart my.cnf The configuration file
 Insert picture description here

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
#defaults-file my.cnf Storage path 
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql_storage/my.cnf

# Of other instances .servicef The configuration is the same as above

# Initialization file 
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql_platform/data --basedir=/usr/local/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql_storage/data --basedir=/usr/local/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql_production/data --basedir=/usr/local/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql_sale/data --basedir=/usr/local/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql_aggregate/data --basedir=/usr/local/mysql

# Modify the permissions  -R Whole folder   Give permission to the owner of the entire folder mysql Under group mysql user 
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/mysql_*

# start-up mysql-- Check the status of each database 
systemctl status mysql_platform.service
systemctl status mysql_storage.service
systemctl status mysql_production.service
systemctl status mysql_sale.service
systemctl status mysql_aggregate.service

# Start the database in turn 
systemctl start mysql_platform.service
systemctl status mysql_platform.service

systemctl start mysql_storage.service
systemctl status mysql_storage.service

systemctl start mysql_production.service
systemctl status mysql_production.service

systemctl start mysql_sale.service
systemctl status mysql_sale.service

systemctl start mysql_aggregate.service
systemctl status mysql_aggregate.service

# Verify startup 
netstat -lnp|grep 33
# Connection database verification and modification root The connection permission of the account .
# No password to use  mysql -S /data/mysql_platform/mysql.sock
# With password  mysql -u user name  -p -S /data/mysql_platform/mysql.sock
mysql -S /data/mysql_platform/mysql.sock
	# Check account information 
	select user,host from mysql.user;
	# Set up root account number IP Address permissions for all IP
	update mysql.user set host='%' where user='root';
	# Refresh the permissions 
	flush privileges;
	# sign out 
	quit;
# Several other databases operate the same as above .
mysql -S /data/mysql_storage/mysql.sock
mysql -S /data/mysql_sale/mysql.sock
mysql -S /data/mysql_production/mysql.sock
mysql -S /data/mysql_aggregate/mysql.sock

# Set boot up 
systemctl enable mysql_platform.service
systemctl enable mysql_storage.service
systemctl enable mysql_sale.service
systemctl enable mysql_production.service
systemctl enable mysql_aggregate.service

# close selinux
vim /etc/sysconfig/selinux  ( After entering  i-> edit ->esc->:wq)
 take SELINUX It is amended as follows DISABLED, namely SELINUX=DISABLED

# Firewall open port 
firewall-cmd --zone=public --add-port=3301/tcp --permanent
firewall-cmd --zone=public --add-port=3302/tcp --permanent
firewall-cmd --zone=public --add-port=3303/tcp --permanent
firewall-cmd --zone=public --add-port=3304/tcp --permanent
firewall-cmd --zone=public --add-port=3305/tcp --permanent
# service iptables restart 
firewall-cmd --reload

# Restart the computer to test self startup 
reboot

The end! ~
 The end! ~

版权声明
本文为[A coir boat in the broken white clouds]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231400068336.html