博客
关于我
(16.1-16.2)项目实战:多机mysql部署
阅读量:404 次
发布时间:2019-03-05

本文共 2573 字,大约阅读时间需要 8 分钟。

文章目录

1.多机mysql部署的方式

  • 给4台机器安装mysql的方式有以下的三种:
    在这里插入图片描述
  • ip.txt文件的内容是:
    在这里插入图片描述
ssh连到服务器执行一下hostname,执行一下date命令for i in `cat ip.txt`; do ssh $i hostname; ssh $i date; done

结果如下:

在这里插入图片描述

  • 方式一:多机部署的脚本如下:
#!/busr/bin/env bashwhile read ipdo	{   		#配置Yum		##命令尽量放在单引号里面		ssh root@$ip "rm -rf /etc/yum.repos.d/*"		ssh root@$ip "wget ftp://172.16.8.100/yumrepo/centos7.repo -P /etc/yum.repos.d/"		ssh root@$ip "wget ftp://172.16.8.100/yumrepo/mysql157.repo -P /etc/yum.repos.d/"   ##mysql的yum环境		ssh root@$ip "yum -y install lftp vim-enhanced bash-completion"		##没有ftp,就从本地拷过去		scp -r centos7.repo root@$ip:/etc/yum.repos.d/				##关闭FireWalled & SeLinux		##disable表示设置防火墙开机不启动		##setenforce 0表示临时关闭SeLinux		ssh root@$ip "systemctl stop firewalld; systemctl disable firewalled"		ssh root@$ip "setenforce 0; sed -ri '/^SELINUX/c\SELINUX=disabled' /etc/selinux/config"				##配置ntp,与172.16.8.100对齐时间		##时钟客户端软件包:rpm -q chrony,其客户端配置文件为:/etc/chrony.conf		ssh root@$ip "yum -y install chrony"		ssh root@ip "sed -ri '/3.centos/a\server 172.16.8.100 iburst' /etc/chrony.conf" ##本身服务器能联网,就不需要加了		ssh root$ip "systemctl start chronyd; systemctl enable chronyd"				##install mysql5.7		ssh root$ip "yum -y install mysql-community-server"		ssh root$ip "systemctl start mysqld; systemctl rnable mysqld"		##保存旧密码		ssh root$ip "grep 'temporary password' /var/log/mysqld.log | awk '{print \$NF}' > /root/mysqloldpass.txt "			##修改mysql临时密码,里面用双引号,外面使用单引号,是为了防止里面和外面都使用双引号造成冲突		ssh root$ip 'mysqladmin -uroot -p"`cat /root/mysqloldpass.txt`" password "(WangJi123)"'	}&	done < ip.txtwaitecho "all finish...."
  • 方式2:
    单机部署脚本,在本地上执行:mysql_install_2.sh
#!/busr/bin/env bashrm -rf /etc/yum.repos.d/*wget ftp://172.16.8.100/yumrepo/centos7.repo -P /etc/yum.repos.d/wget ftp://172.16.8.100/yumrepo/mysql157.repo -P /etc/yum.repos.d/   ##mysql的yum环境yum -y install lftp vim-enhanced bash-completionsystemctl stop firewalld; systemctl disable firewalledsetenforce 0; sed -ri '/^SELINUX/c\SELINUX=disabled' /etc/selinux/configyum -y install chronysed -ri '/3.centos/a\server 172.16.8.100 iburst' /etc/chrony.confsystemctl start chronyd; systemctl enable chronydyum -y install mysql-community-serversystemctl start mysqld; systemctl rnable mysqldgrep 'temporary password' /var/log/mysqld.log | awk '{print $NF}' > /root/mysqloldpass.txtmysqladmin -uroot -p"`cat /root/mysqloldpass.txt`" password "(WangJi123)"

需要将单机部署脚本推到不同的服务器上,main.sh

#!/busr/bin/env bash#mainwhile read ipdo	{   		scp -r mysql_install_2.sh root@$ip:/tmp/		ssh root@$ip "/tmp/mysql_install_2.sh"	}&done < ip.txtwaitecho "all finish..."
  • 方式3:就是把mysql_install_2.sh脚本放到每台服务器上,自己手动执行

转载地址:http://djfzz.baihongyu.com/

你可能感兴趣的文章
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>