当前位置:网站首页>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
边栏推荐
- Give the method of instantiating the object to the new object
- Taxable income
- NPM installation yarn
- [C language] document operation
- [reading notes] Chapter 5 conditional statements, circular statements and block statements of Verilog digital system design tutorial (with answers to thinking questions)
- Go language learning notes - array | go language from scratch
- 653. Sum of two IV - input BST
- Your guide to lowering your cholesterol with TLC (continuously updated)
- Pctp test experience sharing
- npm ERR! network
猜你喜欢
Bk3633 specification
成功的DevOps Leader 应该清楚的3个挑战
Using JS to realize a thousandth bit
GoLand debug go use - white record
数据清洗 ETL 工具Kettle的安装
LeetCode_ DFS_ Medium_ 1254. Count the number of closed islands
Download and install bashdb
#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
npm ERR! network
Kettle experiment conversion case
随机推荐
Codeforces Round #784 (Div. 4)
ALV树(LL LR RL RR)插入删除
2D 01 Backpack
Kettle实验
错题汇总1
Number of islands
Get trustedinstaller permission
Canary publishing using ingress
OpenCV中的图像处理 —— 轮廓入门+轮廓特征
Brush classic topics
Research purpose, construction goal, construction significance, technological innovation, technological effect
Installation of data cleaning ETL tool kettle
ASUS laptop can't read USB and surf the Internet after reinstalling the system
Enter "net start MySQL" and "system error 5. Access denied" appears. Detailed explanation of the problem
[indexof] [lastIndexOf] [split] [substring] usage details
108. 将有序数组转换为二叉搜索树
nn. Explanation of module class
Go language self-study series | golang method
小程序报错:Cannot read property 'currentTarget' of undefined
Data visualization: use Excel to make radar chart