方法一
通过ssh直接执行
#!/usr/bin/bash
#mysql install 1
#by aolishuai
while read ip
do
{
#yum
ssh root@$ip "rm -rf /etc/yum.repos.d/*"
ssh root@$ip "wget ftp://192.168.176.3/yumrepo/centos7.repo -P /etc/yum.repos.d/"
ssh root@$ip "wget ftp://192.168.176.3/yumrepo/mysql57.repo -p /etc/yum.repos.d/"
#scp -r centos7.repo root@$ip:/etc/yum.repos.d/
#Firewalld & selinux
ssh root@$ip "systemctl stop firewalld; systemctl disable firewalld"
ssh root@$ip "setenforce 0; sed -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.176.4 iburst' /etc/chrony.conf"
ssh root@$ip "systemctl start chronyd; systemctl enable chronyd"
#install mysql
ssh root@$ip "yum -y install mysql-community-server"
ssh root@$ip "systemctl start mysqld ; systemctl enable mysqld"
ssh root@$ip "grep 'temporary password' /var/log/mysql.log |awk '{print \$NF}' > /root/mysq
loldpass.txt"
ssh root@$ip 'mysqladmin -uroot -p"`cat /root/mysqloldpass.txt`" password "shuai_123"'
}&
done < ip.txt
wait
echo "install "
方法二
把脚本推送到每台机器上,然后在各台机器行执行
vim musql_install_2.sh
#!/usr/bin/bash
#mysql install 1
#by aolishuai
#yum
rm -rf /etc/yum.repos.d/*
wget ftp://192.168.176.3/yumrepo/centos7.repo -P /etc/yum.repos.d/
wget ftp://192.168.176.3/yumrepo/mysql57.repo -p /etc/yum.repos.d/
#scp -r centos7.repo root@$ip:/etc/yum.repos.d/
#Firewalld & selinux
systemctl stop firewalld; systemctl disable firewalld
setenforce 0; sed -ri '/^SELINUX/c\SELINUX=disabled /etc/selinux/config'
#ntp
yum -y install chrony
sed -ri '/3.centos/a\server 192.168.176.4 iburst' /etc/chrony.conf
systemctl start chronyd; systemctl enable chronyd
#install mysql
yum -y install mysql-community-server
systemctl start mysqld ; systemctl enable mysqld
grep 'temporary password' /var/log/mysql.log |awk '{print $NF}' > /root/mysqloldpass.txt
mysqladmin -uroot -p"`cat /root/mysqloldpass.txt`" password "shuai_123"
vim main.sh
#!/usr/bin/bash
#install mysql
#by aolishuai
while read ip
do
{
scp -r mysql_install_2.sh root@$ip:/tmp/
ssh root@$ip "/tmp/mysql_install_2.sh"
}&
done < ip.txt
版权声明:本文为aoli_shuai原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。