当前位置:网站首页>1 + X cloud computing intermediate -- script construction, read-write separation
1 + X cloud computing intermediate -- script construction, read-write separation
2022-04-23 09:20:00 【King_ nul】
Script build database read-write separation (3 Taiwan machine )
I spent a few hours writing a little script today , The content is not very beautiful , Novice script , Posted for reference only , If the gods have any suggestions , Private chat or comment , thank you !
Prepare before use :
① Configure the of three hosts IP
② Upload scripts and Mycat Install the package and gpmall-repo package ( Put in root Under the table of contents )
③ Upload read_write.sh Script
④ chmod +x read_write.sh
⑤ ./read_write.sh Run the script and wait for the installationOptimization welcome !!!
#!/bin/bash
#Author: willian_1999y@163
#date: 2021-7-17
#version: 1.0
# Database read / write separation cluster script ( Three clusters )
# environment variable
#ip Variable , Please modify IP
NODE1_IP=192.168.17.21
NODE2_IP=192.168.17.22
NODE3_IP=192.168.17.23
HOST_ONE='db1'
HOST_TWO='db2'
HOST_THREE='mycat'
# Configure the host name and turn off the firewall 、selinux、 Host name mapping
change_host(){
hostnamectl set-hostname $HOST_ONE
setenforce 0
getenforce
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
systemctl stop firewalld;systemctl disable firewalld &> /dev/null
iptables -F;iptables -X;iptables -Z;iptables-save &>/dev/null;iptables -L &> /root/installlog.log
cat >/etc/hosts<<EOF
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
$NODE1_IP $HOST_ONE
$NODE2_IP $HOST_TWO
$NODE3_IP $HOST_THREE
EOF
ssh root@192.168.17.22 " hostnamectl set-hostname $HOST_TWO setenforce 0 getenforce sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config systemctl stop firewalld;systemctl disable firewalld &> /dev/null iptables -F;iptables -X;iptables -Z;iptables-save &> /root/installlog.log;iptables -L &> /root/installlog.log mv /etc/yum.repos.d/* /media "
ssh root@192.168.17.23 " hostnamectl set-hostname $HOST_THREE setenforce 0 getenforce sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config systemctl stop firewalld;systemctl disable firewalld &> /dev/null iptables -F;iptables -X;iptables -Z;iptables-save &> /root/installlog.log;iptables -L &> /root/installlog.log mv /etc/yum.repos.d/* /media "
scp /etc/hosts @$NODE2_IP:/etc/hosts &>/dev/null;scp /etc/hosts @$NODE3_IP:/etc/hosts &>/dev/null
}
yum_install(){
mv -f /etc/yum.repos.d/* /media
mkdir -p /mnt/centos
cp -rf /root/gpmall-repo /mnt
mount /dev/sr0 /mnt/centos &> /dev/null
cat >/etc/yum.repos.d/local.repo<<EOF
[base]
name=centos
baseurl=file:///mnt/centos
gpgcheck=0
enabled=1
[gpmall]
name=gpmall
baseurl=file:///mnt/gpmall-repo
gpgcheck=0
enabled=1
EOF
# install vsftpd, To configure ftp Source
yum clean all &>/dev/null;yum install -y vsftpd &> /root/installlog.log
echo "anon_root=/mnt" >> /etc/vsftpd/vsftpd.conf
systemctl start vsftpd;systemctl enable vsftpd &> /root/installlog.log
sed -i 's#file:///mnt#ftp://192.168.17.21#g' /etc/yum.repos.d/local.repo
yum clean all &>/dev/null
repolist=`yum repolist | grep repolist | awk '{print $2}'`
if [ $? -eq 0 ];then
echo -e "\033[32m ######### yum Warehouse complete , There are installation packages in total :$repolist individual ######### \033[0m"
sleep 2
else
echo -e "\033[31m ######### yum Warehouse setup failed , Please check ... ######### \033[0m"
exit 1
fi
scp /etc/yum.repos.d/local.repo $NODE2_IP:/etc/yum.repos.d/ &>/dev/null
scp /etc/yum.repos.d/local.repo $NODE3_IP:/etc/yum.repos.d/ &>/dev/null
scp /root/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz 192.168.17.23:/root/ &>/dev/null
ssh root@$NODE2_IP " yum clean all &>/dev/null;yum repolist &>/dev/null "
ssh root@$NODE3_IP ' yum clean all &>/dev/null;yum repolist &>/dev/null yum install -y MariaDB-client &>/dev/null yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel &>/dev/null yum install -y net-tools &>/dev/null echo -e "\033[32m ###########+ already installed mariadb client +########### \033[0m" '
}
# The primary server installs the database
install_mariadb(){
sleep 2
echo -e "\033[034m ######### Installing MariaDB service , One moment please ... ######### \033[0m"
sleep 1
yum install -y mariadb-server mariadb &>/dev/null
sleep 1
systemctl start mariadb
cat >>/etc/my.cnf<<EOF
[mysqld]
log_bin = mysql-bin
binlog_ignore_db = mysql
server_id = 21
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
EOF
sleep 1
systemctl restart mariadb;systemctl enable mariadb &>/dev/null
mysqladmin -uroot password '123456'
if [ $? -eq 0 ];then
echo -e "\033[37m ++ Restart the main server database ++++++++++++++++++++++++++\033[0m\033[32mOK \033[0m"
sleep 2
else
echo -e "\033[37m ++ Restart the main server database ++++++++++++++++++++++++++\033[0m\033[31mNO \033[0m"
exit 1
fi
echo -e "\033[35m ######### Configuring master server, please wait .... ######### \033[0m"
sleep 2
mysql -uroot -p123456<<EOF
grant all privileges on *.* to root@'%' identified by "123456";
grant replication slave on *.* to 'user'@'db2' identified by '123456';
FLUSH PRIVILEGES;
CREATE DATABASE IF NOT EXISTS test;
use test;
CREATE TABLE IF NOT EXISTS company(id int not null primary key,name varchar(50),addr varchar(255));
insert into company values(3,"facebook","usa");
exit
EOF
if [ $? -eq 0 ];then
echo -e "\033[32m ######### Master server configuration succeeded ######### \033[0m"
sleep 2
else
echo -e "\033[31m ######### Master server configuration error ######### \033[0m"
exit 1
fi
sleep 3
# Configure the database from the server
echo -e "\033[35m ######### Configuring slave server , One moment please ... ######### \033[0m"
sleep 2
ssh root@$NODE2_IP " yum install mariadb-server mariadb -y &>/dev/null systemctl start mariadb mysqladmin -uroot password '123456' cat >>/etc/my.cnf<<EOF [mysqld] server_id = 22 EOF mysql -uroot -p123456<<EOF change master to master_host='$NODE1_IP',master_user='user',master_password='123456'; FLUSH PRIVILEGES; start slave; show slave status\G; exit clear systemctl restart mariadb;systemctl enable mariadb &>/dev/null EOF "
if [ $? -eq 0 ];then
sleep 2
echo -e "\033[32m ######### Configuration from the server is complete ######### \033[0m"
sleep 1
echo -e "\033[33m ######### View the database from the server ######### \033[0m"
ssh root@$NODE2_IP "mysql -uroot -p123456 -e 'show databases;'"
else
echo -e "\033[31m ######### Slave server configuration error ######### \033[0m"
exit 1
fi
}
# install mycat Middleware services
install_mycat(){
echo -e "\033[33m ######### Installing Mycat service ... ######### \033[0m"
sleep 2
# modify Mycat Service profile
ssh root@$NODE3_IP " tar zxf /root/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local chmod -R 777 /usr/local/mycat/ echo export MYCAY_HOME=/usr/local/mycat/ >> /etc/profile source /etc/profile cat >/usr/local/mycat/conf/schema.xml<<EOF <?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.17.21:3306' user='root' password='123456'> <readHost host='hostS1' url='192.168.17.22:3306' user='root' password='123456' /> </writeHost> </dataHost> </mycat:schema> EOF chown root:root /usr/local/mycat/conf/schema.xml cat >/usr/local/mycat/conf/server.xml<<EOF <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE mycat:server SYSTEM 'server.dtd'> <mycat:server xmlns:mycat='http://io.mycat/'> <system> <property name='useSqlStat'>0</property> <property name='useGlobleTableCheck'>0</property> <property name='sequnceHandlerType'>2</property> <property name='processorBufferPoolType'>0</property> <property name='handleDistributedTransactions'>0</property> <property name='useOffHeapForMerge'>1</property> <property name='memoryPageSize'>1m</property> <property name='spillsFileBufferSize'>1k</property> <property name='useStreamOutput'>0</property> <property name='systemReserveMemorySize'>384m</property> <property name='useZKSwitch'>true</property> </system> <user name='root'> <property name='password'>123456</property> <property name='schemas'>USERDB</property> </user> </mycat:server> EOF bash /usr/local/mycat/bin/mycat start bash /usr/local/mycat/bin/mycat status &>/dev/null clear netstat -tnlp | grep 9066;netstat -tnlp | grep 8066 "
# Validation phase
sleep 1
echo -e "\033[33m ######### Validating Mycat Whether the service is normal ... ######### \033[0m"
sleep 2
ssh root@$NODE3_IP "mysql -h127.0.0.1 -P9066 -uroot -p123456 -e 'show @@datasource;'"
if [ $? -eq 0 ];then
echo -e "\033[32m ######### mycat The service is running normally ######### \033[0m"
sleep 2
else
echo -e "\033[31m ######### mycat The service is not running properly ######### \033[0m"
exit 1
fi
}
# Main running program
echo -e "\033[35m ######### Configuring database read / write separation , One moment please ....( Probably need 3 minute ) ######### \033[0m"
sleep 1
change_host
yum_install
install_mariadb
install_mycat
sleep 2
if [ $? -eq 0 ];then
echo -e "\033[32m ######### Read write separation configuration is complete , Please check again ... ######### \033[0m"
exit 0
else
echo -e "\033[31m ######### Error in read / write separation configuration ######### \033[0m"
exit 1
fi
B The station has uploaded the operation process video , Please watch step by step ( I think it's good to see here. Remember the third company )
版权声明
本文为[King_ nul]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230629527510.html
边栏推荐
- Brief steps to build a website / application using flash and H5
- Go language self-study series | golang structure pointer
- Canary publishing using ingress
- ASUS laptop can't read USB and surf the Internet after reinstalling the system
- tsdf +mvs
- Matlab draw five-star red flag
- Is Zhongyan futures safe and reliable?
- Flink reads MySQL and PgSQL at the same time, and the program will get stuck without logs
- Go language self-study series | golang method
- Applet error: cannot read property'currenttarget'of undefined
猜你喜欢
搞不懂时间、时间戳、时区,快来看这篇
LeetCode_ DFS_ Medium_ 1254. Count the number of closed islands
[in-depth good article] detailed explanation of Flink SQL streaming batch integration technology (I)
Pctp test experience sharing
Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
[SQL Server fast track] view and cursor of database
Redis Desktop Manager for Mac
Go language learning notes - exception handling | go language from scratch
Leetcode-199 - right view of binary tree
Harbor enterprise image management system
随机推荐
Kettle实验
npm ERR! network
The K neighbors of each sample are obtained by packet switching
First principle mind map
653. Sum of two IV - input BST
資源打包關系依賴樹
108. 将有序数组转换为二叉搜索树
Four pictures to understand some basic usage of Matplotlib
Multi view depth estimation by fusing single view depth probability with multi view geometry
tsdf +mvs
《数字电子技术基础》3.1 门电路概述、3.2 半导体二极管门电路
[boutique] using dynamic agent to realize unified transaction management II
Installation of data cleaning ETL tool kettle
RSA 加密解密签名验签
Find the sum of simple types of matrices
EmuElec 编译总结
Go language self-study series | golang nested structure
Summary of wrong questions 1
Go language learning notes - structure | go language from scratch
Your guide to lowering your cholesterol with TLC (continuously updated)