当前位置:网站首页>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
边栏推荐
- Research purpose, construction goal, construction significance, technological innovation, technological effect
- Distributed message oriented middleware framework selection - Digital Architecture Design (7)
- Experimental report on analysis of overflow vulnerability of assembly language and reverse engineering stack
- Project upload part
- RSA encryption and decryption signature verification
- ALV树(LL LR RL RR)插入删除
- Summary of common concepts and problems of linear algebra in postgraduate entrance examination
- 501. Mode in binary search tree
- Taxable income
- 112. Path sum
猜你喜欢

EmuElec 编译总结

node安装

108. 将有序数组转换为二叉搜索树

What is augmented reality technology? Where can it be used?

Mini - exercice MySQL (seulement pour les débutants, pas pour les non - débutants)
![[SQL Server fast track] view and cursor of database](/img/2c/8edd92ecef11932c982db56af76c3f.png)
[SQL Server fast track] view and cursor of database

ATSS(CVPR2020)

DJ music management software pioneer DJ rekordbox

Production practice elk

【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)
随机推荐
Machine learning (VI) -- Bayesian classifier
Installation of data cleaning ETL tool kettle
Go language self-study series | golang structure pointer
MySQL小練習(僅適合初學者,非初學者勿進)
I don't understand time, timestamp and time zone. Look at this article
Brief steps to build a website / application using flash and H5
Resource packaging dependency tree
[Luke V0] verification environment 2 - Verification Environment components
The crawler returns null when parsing with XPath. The reason why the crawler cannot get the corresponding element and the solution
MYCAT configuration
搞不懂时间、时间戳、时区,快来看这篇
JS prototype chain
Download and install bashdb
《數字電子技術基礎》3.1 門電路概述、3.2 半導體二極管門電路
Number of islands
SAP 101K 411k inventory change
Using JS to realize a thousandth bit
AQS & reentrantlock implementation principle
Go language learning notes - language interface | go language from scratch
Your guide to lowering your cholesterol with TLC (continuously updated)