2 New virtual machines 172.16.1.1, 172.16.1.2 ( configure yum source )
Installing the database service
which 172.16.1.1, 172.16.1.2 Run the database service and set the password for the database administrator to log on from the local computer is XZW 12345 ( mysql-server.5.6 )
TAR-XVF Mysql-5.6.rpm.tar (RPM package installation)
RPM-UVH mysql-*.rpm
/etc/init.d/mysql start; Chkconfig MySQL on
Change Password
[Email protected] ~]# Cat/root/.mysql_secret
[Email protected] ~]# MYSQL-UROOT-PJBJIFBWD
mysql> Set password for [email protected] "localhost" =password ("xzw12345");
Mysql> quit;
[Email protected] ~]# mysql-uroot-pxzw12345
Mysql>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++
Main Master Structure
Master 203 :
mysql-uroot-pxzw12345
mysql> grant replication Slave on * * to [e-mail protected] "%" identified by "123456";
mysql>quit;
Vim/etc/my.cnf
[Mysqld]
log-bin=master203
server_id=203
: Wq
/etc/init.d/mysql restart
ls/var/lib/mysql/master203.*
mysql-uroot-pxzw12345
Mysql>show Master status;
Master 204:
Mysql-uroot-pxzw123
mysql> grant replication Slave on * * to [e-mail protected] "%" identified by "123456";
mysql>quit;
Vim/etc/my.cnf
[Mysqld]
log-bin=master204
server_id=204
: Wq
/etc/init.d/mysql restart
ls/var/lib/mysql/master204.*
mysql-uroot-pxzw12345
Mysql>show Master status;
Master 204 to master 203 initiates a synchronization operation to specify relevant parameters for the relevant master172.16.1.1
mysql-uroot-pxzw12345
mysql> Change Master to master_host= "172.16.1.1", master_user= "Slaveuser" , master_password= "123456", master_log_file= "master203.000001", master_log_pos=120;
mysql> start slave;
Mysql> show Slave status\g;
IO Yes
SQL Yes
Master 203 initiates a synchronous operation to the master204 , specifying relevant parameters for the relevant master172.16.1.2
mysql-uroot-pxzw12345
mysql> Change Master to master_host= "172.16.1.2", master_user= "Slaveuser", master_password= "123456", Master_log_ File= "master204.000001", master_log_pos=120;
mysql> start slave;
Mysql> show Slave status\g;
IO Yes
SQL Yes
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++
Test
1.master203
mysql-uroot-pxzw12345
mysql> CREATE DATABASE Bbsdb;
Mysql> Grant all on bbsdb.* to [e-mail protected] "%" identified by "123";
Mysql> quit;
2.master204
mysql-uroot-pxzw12345
Mysql>use Bbsdb;
Mysql> CREATE TABLE bbsdb.t1 (id int);
Mysql> quit;
3. On Client Access (192.168.1.200):
Ping x.x.x.1
Mysql-hx.x.x.1-ustudent-p123
mysql> INSERT into BBSDB.T1 values (101);
in master203, master204
mysql-uroot-pxzw12345
MySQL > select * from Bbsdb.t1; # can also see the record
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++
This article is for everyone to explain the MySQL error: Last_io_error:error connecting to master solution, interested students reference.
Error message:
Slave_io_running:connecting
Slave_sql_running:yes
last_io_errno:2003
Last_io_error:error connecting to master 'slaveuser@172.16.1.1:3306 '-retry-time:60 retries:1
Cause of Error:
The primary database server did not shut down the firewall.
Resolution:
1, go to the master server: 172.16.1.1 shut down the firewall.
[[Email protected] ~]# service iptables stop;chkconfig iptables off
Iptables:setting chains to Policy Accept:filter [OK]
iptables:flushing firewall rules: [OK]
iptables:unloading modules: [OK]
2, go from the server: Stop Slave;start slave;
mysql> stop Slave;
Query OK, 0 rows affected (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++
keepalived High Availability Server issues
Two Linux servers (172.16.1.1, 172.16.1.2), do MySQL server, and deploy keepalived high-availability software, one as a client host (192.168.1.200), to achieve the following functions:
- Using keepalived to achieve high availability of MySQL server
- Web server IP addresses are 172.16.1.1 and 172.16.1.2, respectively
- Web server Drift VIP address is 172.16.1.3
- The client accesses the MySQL service by accessing the VIP address
Steps
The implementation of this case needs to follow the steps below.
Step One: Configure the network environment
1) Set MySQL server network parameters
[Email protected] ~]# vim/etc/sysconfig/network-scripts/ifcfg-eth1
Device=eth1
Type=ethernet
Onboot=yes
Nm_controlled=yes
Bootproto=none
ipaddr=172.16.1.1
netmask=255.255.255.0
#DNS2 =221.4.8.1
#GATEWAY =192.168.1.1
#DNS1 =192.168.9.1
Ipv6init=no
Userctl=no
[Email protected] ~]# vim/etc/sysconfig/network-scripts/ifcfg-eth1
Device=eth1
Type=ethernet
Onboot=yes
Nm_controlled=yes
Bootproto=none
ipaddr=172.16.1.2
netmask=255.255.255.0
#DNS2 =221.4.8.1
#GATEWAY =192.168.1.1
#DNS1 =192.168.9.1
Ipv6init=no
Userctl=no
Step Two: Install keepalived software
Note: The two MySQL servers do the same operation.
- [Email protected] ~]# yum install- y gcc kernel-devel OpenSSL-devel popt-devel
- [Email protected] ~]# tar -xzf keepalived-1.2.7. Tar. GZ
- [[email protected] ~]# CD keepalived-1.2.7
- [[email protected] keepalived-1.2.7]# . /configure--sysconf=/etc
- [[email protected] keepalived-1.2.7]# make && make install
- [[email protected] keepalived-1.2.7]# Ln -s /usr/local/sbin/ keepalived /sbin/
- [[email protected] keepalived-1.2.7]# chkconfig keepalived on
- [Email protected] ~]# yum install- y gcc kernel-devel OpenSSL-devel popt-devel
- [Email protected] ~]# tar -xzf keepalived-1.2.7. Tar. GZ
- [[email protected] ~]# CD keepalived-1.2.7
- [[email protected] keepalived-1.2.7]# . /configure--sysconf=/etc
- [[email protected] keepalived-1.2.7]# make && make install
- [[email protected] keepalived-1.2.7]# Ln -s /usr/local/sbin/ keepalived /sbin/
- [[email protected] keepalived-1.2.7]# chkconfig keepalived on
Step three: Deploy the keepalived service
1) Modify the WEB1 server keepalived configuration file
- [Email protected] ~]# vim /etc/keepalived/keepalived. conf
- Global_defs {
- Notification_email {
- [Email protected] . com. CN //Set alert recipient mailbox
- }
- Notification_email_from [email protected] //Set sender
- Smtp_server 127.0.0.1 //define mail server
- Smtp_connect_timeout
- router_id web1 //Set route ID number
- }
- Vrrp_instance vi_1 {
- State master //master server is Master
- interface eth0 //define network interface
- virtual_router_id //Main and auxiliary vrid must be the same
- Priority/server precedence
- Advert_int 1
- Authentication {
- Auth_type Pass
- Auth_pass Forlvs //Primary and secondary server passwords must be the same
- }
- Virtual_ipaddress { 172.16.0.1 }
- }
2) Modify the WEB2 server keepalived configuration file
- [Email protected] ~]# vim /etc/keepalived/keepalived. conf
- Global_defs {
- Notification_email {
- [Email protected] . com. CN //Set alert recipient mailbox
- }
- Notification_email_from [email protected] //Set sender
- Smtp_server 127.0.0.1 //define mail server
- Smtp_connect_timeout
- router_id web2 //Set route ID number
- }
- Vrrp_instance vi_1 {
- State SLAVE //from server to SLAVE
- interface eth0 //define network interface
- virtual_router_id //Main and auxiliary vrid must be the same
- Priority/server precedence
- Advert_int 1
- Authentication {
- Auth_type Pass
- Auth_pass Forlvs //Primary and secondary server passwords must be the same
- }
- Virtual_ipaddress { 172.16.0.1 }
- }
3) Start the service
- [[email protected] ~]# service keepalived start
- [[email protected] ~]# service keepalived start
Step Four: Test
1) Log in to two Web servers to view VIP information
- [[email protected] ~]# IP addr Show
- [[email protected] ~]# IP addr Show
2) Client Access
The client uses the Curl command to connect to the http://172.16.0.1, view the Web page, turn off the network card of the WEB1 server, and the client accesses http://172.16.0.1 again to verify that the service is properly accessible.
MySQL Master master high Availability (KeepAlive)