当前位置:网站首页>Ubuntu 14.04下搭建MySQL主从服务器
Ubuntu 14.04下搭建MySQL主从服务器
2022-07-01 14:46:00 【星哥玩云】
MySQL的主从复制是异步的,分master/slave,在master端存在一个IO线程,而在slave下存在IO及Sql线程。
搭建环境最重要的地方在于将mysql的二进制日志功能开启,我在搭的过程中有个细节没注意,坑了我好久。
环境:
我的两台虚拟机上网方式都是采用桥接模式,不推荐nat.首先对两台虚拟机设置固定ip地址,和你的物理机的ip地址在一个段内,这样你的虚拟机就很类似一台局域网的物理机工作了。
设置固定ip地址:
$ sudo vim /etc/network/interfaces
如下:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.252
netmask 255.255.255.0
gateway 192.168.1.1
$ sudo /etc/init.d/networking restart
我的虚拟机地址各设为:192.168.1.251 192.168.1.252 网关IP:192.168.1.1
设置完后,首先在虚拟机中互ping,必须保证能通。
环境准备好后,可以开始了,我没有采取rpm方式,ubuntu下直接在线安装mysql非常方便的,省去了很多步骤。
$ sudo apt-get install mysql-server
默认安装完自动开启的,所以用 netstat -tap|grep mysql 看看是不是mysql服务存在了
之后查询下mysql运行状态,service mysql status,同样,还有其他命令,service mysql start/stop/restart.
如果出现了以下信息,则代表成功了。
mysql start/running, process 1199
在登陆前先到/etc/mysql/my.cnf下 将bind-address注释掉,因为默认只能本机访问。
登陆mysql
mysql -u root -p
grant replication slave,reload,super on *.* to slave @192.168.1.152 identified by '1234'
然后在另一台Ubuntu下远程测试下
mysql -u slave -h 192.168.1.151 -p
前期工作准备好了,现在就开始配置:
在master 192.168.1.251的机子上对my.cnf修改,切记以下配置信息一定要加到【mysqld】模块中,放在文件其他位置会导致master配置失败。
server-id=1
log_bin=/var/log/mysql/mysql-bin.log
binlog_do_db=student
binlog_ignore_db=mysql
重启下mysql
sudo /etc/init.d/mysql restart
如果在重启过程中failed,建议先看下my.cnf的log-error对应得错误日志文件位置,然后cat看下报错信息
之后进入master的mysql,首先看下二进制功能是否on.
show variables like 'log%'
如果为off代表没开启,则还是返回检查下my.cnf文件,是否放在[mysqld]那块中等。文件路径是否对了
show master status;则能看到对应得file position 信息,这些在从机设置的时候要用到。
最后到salve 192.168.1.252的/etc/mysql/my.cnf下配置:
server-id=2
log_bin=/var/log/mysql/mysql-bin.log
replicate_do_db=student
重启下mysql
sudo /etc/init.d/mysql restart
slave进入mysql:
stop slave
然后设置从master复制日志配置
change master to master_host='192.168.1.151' ,master_user='slave',master_password='1234',
master_log_file='log.000004',master_log_pos=94;
log_file log_pos则是在master下show master status看到的file position信息。
start slave;
show slave status\G
在出现的信息中找到 Slave_IO_Running/Slave_SQL_Running ,都为YES则成功了。
如果出现了NO,则还是查看log-error日志文件,会比较清晰的描述出来的。
边栏推荐
- Is it reasonable and safe for securities companies to open accounts for 10000 free securities? How to say
- [commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial
- C 语言进阶
- Websocket (simple experience version)
- Summary of leetcode's dynamic programming 5
- 30 Devops interview questions and answers
- Problem note - Oracle 11g uninstall
- 问题随记 —— Oracle 11g 卸载
- 互联网医院系统源码 医院小程序源码 智慧医院源码 在线问诊系统源码
- 【牛客网刷题系列 之 Verilog快速入门】~ 多功能数据处理器、求两个数的差值、使用generate…for语句简化代码、使用子模块实现三输入数的大小比较
猜你喜欢

炎炎夏日,这份安全用气指南请街坊们收好!

sqlilabs less9

数据湖系列之一 | 你一定爱读的极简数据平台史,从数据仓库、数据湖到湖仓一体

Semiconductor foundation of binary realization principle

SQLAchemy 常用操作

问题随记 —— Oracle 11g 卸载

Today, with the popularity of micro services, how does service mesh exist?
![[zero basic IOT pwn] reproduce Netgear wnap320 rce](/img/f7/d683df1d4b1b032164a529d3d94615.png)
[zero basic IOT pwn] reproduce Netgear wnap320 rce

Salesforce、约翰霍普金斯、哥大 | ProGen2: 探索蛋白语言模型的边界

MIT团队使用图神经网络,加速无定形聚合物电解质筛选,促进下一代锂电池技术开发
随机推荐
sqlilabs less10
C 语言基础
Error-tf. function-decorated function tried to create variables on non-first call
Pat 1121 damn single (25 points) set
sqlilabs less-8
音乐播放器开发实例(可毕设)
Research Report on the development trend and competitive strategy of the global chemical glassware industry
Is it reasonable and safe for securities companies to open accounts for 10000 free securities? How to say
Provincial election + noi Part IX game theory
从零开发小程序和公众号【第三期】
互联网医院系统源码 医院小程序源码 智慧医院源码 在线问诊系统源码
tensorflow2-savedmodel convert to pb(frozen_graph)
Provincial election + noi Part XI others
Research Report on the development trend and competitive strategy of the global axis measurement system industry
Microservice development steps (Nacos)
It's suitable for people who don't have eloquence. The benefits of joining the China Video partner program are really delicious. One video gets 3 benefits
Research Report on the development trend and competitive strategy of the global high temperature label industry
关于软件测试的一些思考
Pat 1065 a+b and C (64bit) (20 points) (16 points)
sqlilabs less-8