shell脚本 mysql主从
#!/bin/bash
systemctl stop firewalld
setenforce
user="tom"
password=""
slave_ipaddr="192.168.52.34" #这里写自己从的IP地址
master_ipaddr="192.168.52.33" #这里写自己主的IP地址
yum -y install openssh-clients #安装ssh检测工具
yum -y install mariadb mariadb-server #安装mysql及其依赖文件
sed -i '/^\[mysqld\]$/a\server-id=1' /etc/my.cnf #在配置文件my.cnf添加
sed -i '/^\[mysqld\]$/a\log-bin=mysql-bin' /etc/my.cnf #在配置文件my.cnf添加
sed -i '/^\[mysqld\]$/a\relay-log=mysql-relay' /etc/my.cnf #在配置文件my.cnf添加
systemctl restart mariadb #启动mysql
mysql -e "grant all on *.* to '$user'to'$slave_ipaddr' identified by '$password';" #给用户授权
master_status=`mysql -e "show master status;"`
echo "$master_status" #打印master_status
master_file=`echo "$master_status" | grep "bin" | awk '{print $1}'`
echo "$master_file"
master_pos=`echo "$master_status" | grep "bin" | awk '{print $2}'`
echo "$master_pos"
ssh root@$slave_ipaddr >& <<eof
systemctl stop firewalld
setenforce
yum -y install mariadb mariadb-server
sed -i '/^\[mysqld\]$/a\server-id=2' /etc/my.cnf
sed -i '/^\[mysqld\]$/a\log-bin=mysql-bin' /etc/my.cnf
sed -i '/^\[mysqld\]$/a\relay-log=mysql-relay' /etc/my.cnf
systemctl restart mariadb
mysql -e "change master to master_host='$master_ipaddr', master_password='$password', master_user='$user', master_log_file='$master_file', master_log_pos=$master_pos;"
mysql -e "fluesh privileges;"
mysql -e "start slave;"
mysql -e "show slave status \G;"
check=`mysql -e "show slave status \G;" | grep Yes | wc -l`
if [ $check == ]; then
echo "仅输出一个yes"
elif [ $check == ]; then
echo "输出俩个yes"
else
echo "mariadb错误"
fi
eof
shell脚本 mysql主从的更多相关文章
- shell脚本——mysql
很期待,学习shell脚本,减少重复工作 自动安装配置mysql脚本: #/bin/bash LOG_FILE=/home/hadoop1/log/installmysql.log function ...
- shell(3)-mysql主从监控shell
需要先明白数据库主从同步正常的标准是来查看两个线程Slave_IO和Slave_SQL两个线程的工作状态: #!/bin/bash #Check MySQL Slave's Runnning Stat ...
- shell配置mysql主从
Environment:CentOS7两台主机 一台做主机,一台做备份机 注意: 首先第一步关闭两台机器的防火墙 主机shell操作: #!/bin/bash slave_user='zjt' sla ...
- [shell脚本] mysql服务启动脚本
服务启动脚本(初始化.启动.登录) #!/bin/bash export PID=/usr/local/nestdb_master/bin/mysqld export PASSWORD=123456 ...
- shell脚本修复MySQL主从同步
发布:thebaby 来源:net [大 中 小] 分享一例shell脚本,用于修改mysql的主从同步问题,有需要的朋友参考下吧. 一个可以修改mysql主从同步的shell脚本. 例子 ...
- zabbix3.0.4-agent通过shell脚本获取mysql数据库登陆用户
zabbix3.0.4获取数据库登陆用户趋势详解 主要思路: 通过zabbix客户端shell脚本mysql命令取出用户表中的数据将结果反馈给zabbix,画出趋势图 1.修改zabbix-agent ...
- 用shell脚本监控MySQL主从同步
企业面试题1:(生产实战案例):监控MySQL主从同步是否异常,如果异常,则发送短信或者邮件给管理员.提示:如果没主从同步环境,可以用下面文本放到文件里读取来模拟:阶段1:开发一个守护进程脚本每30秒 ...
- 自动监控主从MySQL同步的SHELL脚本
代码如下: #!/bin/bash #check MySQL_Slave Status #crontab time 00:10 MYSQLPORT=`netstat -na|grep "LI ...
- shell脚本监控MySQL主从同步
企业面试题1:监控MySQL主从同步是否异常,如果异常,则发送短信或者邮件给管理员. 阶段1:开发一个守护进程脚本每30秒实现检测一次. 阶段2:如果同步出现如下错误号(1158,1159,1008, ...
随机推荐
- HBase 系列(三)—— HBase 基本环境搭建
一.安装前置条件说明 1.1 JDK版本说明 HBase 需要依赖 JDK 环境,同时 HBase 2.0+ 以上版本不再支持 JDK 1.7 ,需要安装 JDK 1.8+ .JDK 安装方式见本仓库 ...
- C语言--线性表
#include<stdio.h>#include<stdlib.h>#include<string.h>#define LIST_SIZE 100#define ...
- MySQL计算相邻两行某列差值的方法
简述 博主最近因工作任务缠身,都无暇顾及到我的这片自留地了.前段时间稍有空闲,花了较多的精力学习<啊哈算法>,从中学习到很多之前没有太注重的内容,收益颇丰.但是这些算法题目还没有看完,等后 ...
- 利用position absolute使div居中
外层DIV{position:realtive}内层DIV{positon:absolute;top:50%;left:50%;margin-top:-100px;margin-left:-150px ...
- LCD 驱动 S3C2440A
LCD Control 1 Register 以16BPP为例 LCD Control 2 Register LCD Control 3 Register LCD Control 4 Register ...
- Android EventBus使用大全
添加依赖 implementation 'org.greenrobot:eventbus:3.1.1' public class HuaDongActivity extends Activity { ...
- java Excel文件流输出(后台)没有下载提示
/**方案: *1. *问题源头应该是前端用的是ajax方式请求路径,要想出现下载Excel的弹窗,我个人理解应该是等同于重新打开一个窗口,而ajax默认不动页面直接将值返回,所以没有提升下载. *解 ...
- xadmin集成DjangoUeditor,以及编辑器的视频路径配置
稍微讲一下DjangoUeditor的配置,因为之前去找配置的时候东拼西凑的,所以自己写一下自己一步步配置的过程.首先我是再github上去下载下来,因为是当作第三方插件集成到xadmin中,所以不用 ...
- H3C 802.11网络的基本元素
- 微信小程序转义解析渲染html
今天开发小程序时,想调用商品详情字段,发现大部分是用编辑器编辑的html原生标签,无法在小程序直接使用. 后面自己使用正则和字符串替换,效果也不佳. 最后在网上找到了wx-mina-html-view ...