MySQL多机部署

远程执行脚本

c#!/usr/bin/env bash
#mysql install 1 
while read line 
do
   {
    #yum
     ssh root@$ip  "rm -rf /etc/yum.repos.d/*"
     ssh root@$ip  "wget (Centos 的repo 源地址,可以是官网的也可以是本地FTP的)"
     ssh root@$ip  "wget (mysql 的repo源地址 可以是官网的也可以是本地FTP的)"
     ssh root@$ip  "yum -y install lftp vim-enhanced bash-completion"
     #scp -r centos7.repo root@$ip:/etc/yum.repos.d  //将本地的repos.d 文件拷贝过去

   #Firewalld & SELinux
    ssh root@$ip "systemctl stop firewalld;systemctl disable firewalld"
    ssh root@$ip "setenforce 0;set -ri '/^SELINUX/c\SELINUX=disabled' 
 /etc/selinux/config"
 
  #ntp 同步时钟服务器
   ssh root@$ip "yum -y install chrony"
   ssh root@$ip "sed -ri '/3.centos/a\server 192.168.1.2 iburst'  /etc/chrony.conf"
   ssh root@$ip "systemctl start chronyd; systemctl enable chronyd"

 #install mysql 
   ssh root@$ip   "yum install mysql-community-server "
   ssh root@$ip   "systemctl start mysqld; systemctl enable mysqld" 
   ssh root@$ip "grep 'temporarypassword' /var/log/mysql.log  |awk '{print \$NF}' > /root/mysqloldpass.txt"
   ssh root@$ip 'mysqladmin -uroot -p "`cat /root/mysqlodlpass.txt`"  password "(Mima1234)"'
   }&
  
done <ip.txt
wait 
echo "all finish ........................"

传递脚本在本地执行

单机脚本 mysql_install.sh

#!/usr/bin/env bash
#mysql install 2 
#yum
rm -rf /etc/yum.repos.d/*
wget (Centos 的repo 源地址,可以是官网的也可以是本地FTP的)
wget (mysql 的repo源地址 可以是官网的也可以是本地FTP的)
yum -y install lftp vim-enhanced bash-completion

#Firewalld & SELinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
set -ri '/^SELINUX/c\SELINUX=disabled' /etc/selinux/config
 
#ntp 同步时钟服务器
yum -y install chrony
sed -ri '/3.centos/a\server 192.168.1.2 iburst'  /etc/chrony.conf
systemctl start chronyd
systemctl enable chronyd

#install mysql 
yum install mysql-community-server
systemctl start mysqld
systemctl enable mysqld
grep 'temporarypassword' /var/log/mysql.log  |awk '{print \$NF}' > /root/mysqloldpass.txt
mysqladmin -uroot -p "`cat /root/mysqlodlpass.txt`"  password "(Mima1234)"

通过脚本传递的方式来执行

#! /usr/bin/env bash
#main 
while read ip 
do
    {
     scp -r  mysql_install.sh  root@$ip:/tmp/
     ssh root@$ip "/tmp/mysql_install.sh"
    }&
done <ip.txt
wait
echo "all finish.............."

发表评论

邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据