当前位置:网站首页>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日志文件,会比较清晰的描述出来的。
边栏推荐
- 2022-2-15 learning the imitation Niuke project - post in Section 2
- How to view the state-owned enterprises have unloaded Microsoft office and switched to Kingsoft WPS?
- Basis of target detection (NMS)
- Rearrangement of overloaded operators
- 【14. 区间和(离散化)】
- 炎炎夏日,这份安全用气指南请街坊们收好!
- Summary of leetcode's dynamic programming 5
- Cannot link redis when redis is enabled
- JVM第二话 -- JVM内存模型以及垃圾回收
- Internet hospital system source code hospital applet source code smart hospital source code online consultation system source code
猜你喜欢

phpcms实现订单直接支付宝支付功能
![[zero basic IOT pwn] reproduce Netgear wnap320 rce](/img/f7/d683df1d4b1b032164a529d3d94615.png)
[zero basic IOT pwn] reproduce Netgear wnap320 rce

Word2vec yyds dry goods inventory

微服务大行其道的今天,Service Mesh是怎样一种存在?

官宣:Apache Doris 顺利毕业,成为 ASF 顶级项目!

Use the right scene, get twice the result with half the effort! Full introduction to the window query function and usage scenarios of tdengine

Chapter 4 of getting started with MySQL: creation, modification and deletion of data tables

Guess lantern riddles, not programmers still can't understand?

What are the books that have greatly improved the thinking and ability of programming?

Buuctf reinforcement question ezsql
随机推荐
Research Report on the development trend and competitive strategy of the global high temperature label industry
官宣:Apache Doris 顺利毕业,成为 ASF 顶级项目!
sqlilabs less10
Fundamentals of C language
JVM second conversation -- JVM memory model and garbage collection
Websocket (simple experience version)
Research Report on the development trend and competitive strategy of the global powder filling machine industry
[zero basic IOT pwn] reproduce Netgear wnap320 rce
Basic operation of database
Blog recommendation | in depth study of message segmentation in pulsar
[R language data science]: common evaluation indicators of machine learning
Opencv interpolation mode
2022-2-15 learning the imitation Niuke project - post in Section 2
C learning notes (5) class and inheritance
Problem note - Oracle 11g uninstall
[Verilog quick start of Niuke series] ~ multi function data processor, calculate the difference between two numbers, use generate... For statement to simplify the code, and use sub modules to realize
Research Report on the development trend and competitive strategy of the global traditional computer industry
Buuctf reinforcement question ezsql
Take you to API development by hand
C#学习笔记(5)类和继承