Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Highly available Mysql installation and configuration methods and steps

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Server Load Balancing is a network service device that distributes traffic to multiple CVMs (computing clusters). It can quickly improve the external service capability of the application system through traffic distribution; hide the actual service port to enhance the security of the internal system; by eliminating the service single point of failure, improve the reliability of the application system. Let's introduce it to you today.

1 highly available Mysql installation configuration 1.1 Lab Environment

CVM role

CVM IP

VIP

192.168.8.200

Mycat1

192.168.8.22

Mycat2

192.168.8.23

Mysql1 (Master1)

192.168.8.24

Mysql2 (Master2)

192.168.8.25

Mysql3 (Slave)

192.168.8.26

1.2 Mysql installation configuration

(192.168.8.24192.168.25 and 192.168.8.26) three server operations

1.2.1 Mysql installation

Go to the official website to download the yum source of mysql

Https://www.mysql.com/

Install the yumsource rpm software

Rpm-ivh mysql57-community-release-el7-11.noarch.rpm

Yum install mysql

Yuminstall mysql-community-server

1.2.2 Mysql initialization

Start mysql

Systemctlstart mysqld

Get root password

Cat/var/log/mysqld.log | grep "temporary password"

2017-07-06T03:23:46.053467Z1 [Note] A temporary password is generated for root@localhost: iGUl/j*_r1*z

Modify root password

Mysql-uroot-p

SETPASSWORD=PASSWORD ('newpassword')

1.3 Mysql Master Master configuration

(192.168.8.24 and 192.168.8.25) two server operations

1.3.1 Mysql configuration

192.168.8.24 configuration:

Vi/etc/my.cnf

Add the following:

[mysqld]

Symbolic-links=0

Log-error=/var/log/mysqld.log

Pid-file=/var/run/mysqld/mysqld.pid

Server_id = 1

Log-bin=mysql-bing

Log_bin_trust_function_creators=TRUE

Log-slave-updates

Sync_binlog=1

Auto_increment_offset=1

Auto_increment_increment=2

Slave-skip-errors=all

Lower_case_table_names=1

Character_set_server=utf8

Skip-name-resolve

[mysql]

Default-character-set=utf8

[mysqld_safe]

Default-character-set=utf8

[mysql.server]

Default-character-set=utf8

[client]

Default-character-set=utf8

192.168.8.25 configuration:

Vi/etc/my.cnf

Add the following:

Symbolic-links=0

Log-error=/var/log/mysqld.log

Pid-file=/var/run/mysqld/mysqld.pid

Server_id = 2

Log-bin=mysql-bing

Log_bin_trust_function_creators=TRUE

Log-slave-updates

Sync_binlog=1

Auto_increment_offset=1

Auto_increment_increment=2

Slave-skip-errors=all

Lower_case_table_names=1

Character_set_server = utf8

Skip-name-resolve

[mysql]

Default-character-set=utf8

[mysqld_safe]

Default-character-set=utf8

[mysql.server]

Default-character-set = utf8

[client]

Default-character-set = utf8

Server 1 (192.168.8.24) and server 2 (192.168.8.25) restart the service:

Systemctlrestart mysqld

1.3.2 Sql configuration

Server 1 (192.168.8.24) operation:

Mysql-u root-p

Mysql > GRANT REPLICATION SLAVE ON *. * to 'repluser'@'192.168.8.25' identified by'123456'

Mysql > flush privileges

Mysql > flush tables with read lock; # prevent access to new data

# check the bin file and position, then you need to use it

Mysql > SHOW MASTER STATUS

+-+

| | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | |

+-+

| | mysql-bin.000004 | 106 | |

+-+

Server 2 (192.168.8.25) operation:

Mysql-u root-p

Mysql > GRANT REPLICATION SLAVE ON *. * to 'repluser'@'192.168.8.24' identified by'123456'

Mysql > flush privileges

Mysql > flush tables with read lock; # prevent access to new data

# check the bin file and position, then you need to use it

Mysql > SHOW MASTER STATUS

+-+

| | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | |

+-+

| | mysql-bin.000004 | 350 | |

+-+

Server 1 (192.168.8.24) operation:

Mysql > CHANGE MASTER TO MASTER_HOST='192.168.8.25',MASTER_USER='repluser',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000004',MASTER_LOG_POS=350,MASTER_PORT=3306

Server 2 (192.168.8.25) operation:

Mysql > CHANGE MASTER TOMASTER_HOST='192.168.8.24',MASTER_USER='repluser',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000004',MASTER_LOG_POS=106,MASTER_PORT=3306

Server 1 (192.168.8.24) and server 2 (192.168.8.25) operate respectively:

Mysql > unlock tables

Mysql > start slave

Mysql > show slave status\ G

* * 1.row * *

Mainly focus on the following two parameters:

...

...

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

...

...

1.3.3 Test

Server 1 (192.168.8.24) add new libraries:

Mysql > show databases

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | test |

+-+

Mysql > create database tom

Mysql > show databases

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | test |

| | tom |

+-+

Server 2 (192.168.8.25) views the automatically added libraries:

Mysql > show databases

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | test |

| | tom |

+-+

Server 2 (192.168.8.25) removes the newly added library:

Mysql > drop database tom

Mysql > show databases

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | test |

+-+

Server 1 (192.168.8.24) will be automatically deleted:

Mysql > show databases

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | test |

+-+

This shows that the synchronization between the two sides is successful.

1.4 Mysql master-slave configuration

(192.168.8.24 and 192.168.8.26) two server operations

1.4.1 Mysql configuration

The 192.168.8.24 configuration was completed in the previous section. Skip

192.168.8.26 configuration:

Vi/etc/my.cnf

Add the following:

[mysqld]

Symbolic-links=0

Log-error=/var/log/mysqld.log

Pid-file=/var/run/mysqld/mysqld.pid

Server_id = 3

Log-bin=mysql-bing

Log_bin_trust_function_creators=TRUE

Log-slave-updates

Sync_binlog=1

Auto_increment_offset=1

Auto_increment_increment=2

Slave-skip-errors=all

Lower_case_table_names=1

Character_set_server = utf8

Skip-name-resolve

[mysql]

Default-character-set=utf8

[mysqld_safe]

Default-character-set=utf8

[mysql.server]

Default-character-set = utf8

[client]

Default-character-set = utf8

Restart the service

Systemctlrestart mysqld

1.4.2 Sql configuration

Server 1 (192.168.8.24) operation:

Mysql-u root-p

Mysql > GRANT REPLICATION SLAVE ON *. * to 'repluser'@'192.168.8.26' identified by'123456'

Mysql > flush privileges

Mysql > flush tables with read lock; # prevent access to new data

# check the bin file and position, then you need to use it

Mysql > SHOW MASTER STATUS

+-+

| | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | |

+-+

| | mysql-bin.000004 | 106 | |

+-+

Server 2 (192.168.8.26) operation:

Mysql > CHANGE MASTER TO MASTER_HOST='192.168.8.24',MASTER_USER='repluser',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000004',MASTER_LOG_POS=106,MASTER_PORT=3306

Server 1 (192.168.8.24) operation:

Mysql > unlock tables

Server 2 (192.168.8.26) operation:

Mysql > start slave

Mysql > show slave status\ G

* * 1. Row *

Mainly focus on the following two parameters:

...

...

Slave_IO_Running:Yes

Slave_SQL_Running:Yes

...

...

1.4.3 Test

Server 1 (192.168.8.24) add new libraries:

Mysql > show databases

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | test |

+-+

Mysql > create database tom

Mysql > show databases

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | test |

| | tom |

+-+

Server 2 (192.168.8.26) views the automatically added libraries:

Mysql > show databases

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | test |

| | tom |

+-+

1.5 Mycat installation configuration

(192.168.8.22 and 192.168.8.23) two server operations

1.5.1 Mycat installation

Install java

Yuminstall java-1.8.0-openjdk

Download mycat:

Http://dl.mycat.io/

Extract the installation package

Tarzxvf Mycat-server-1.7.0-DEV-20170416134921-linux.tar.gz

MvMycat / usr/local/mycat

Configure environment variables

Vi/etc/profile, add MYCAT_HOME=/usr/local/mycat to the system environment variable file

1.5.2 Mycat configuration

Cd/usr/local/mycat/conf

Viserver.xml

Modify the configuration as follows

Test@123

Tom,test (multiple databases can be added to multiple logical libraries)

User

Tom,test

True

Vischema.xml

Only the following configuration read-write separation and other deletions are retained

Select user ()

Start mycat

/ usr/local/mycat/bin/mycatstart

1.6 keepalived installation configuration 1.6.1 Lab Environment

Server role

Server IP

VIP1

192.168.8.200

LVS1

192.168.8.10

LVS2

192.168.8.11

1.6.2 install keepalived

Yuminstall-y keepalived ipvsadm

1.6.3 configure keepalived

Vim/etc/keepalived/keepalived.conf

On LVS-DR-Master, the configuration is as follows (192.168.8.10 operation):

! Configuration File for keepalived

Global_defs {

Notification_email {

Acassen@firewall.loc

Failover@firewall.loc

Sysadmin@firewall.loc

}

Notification_email_from Alexandre.Cassen@firewall.loc

Smtp_server 192.168.200.1

Smtp_connect_timeout 30

Router_id LVS_DEVEL

}

Vrrp_instance VI_1 {

State BACKUP

Interface ens160

Virtual_router_id 51

Priority 100

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 123456

}

Virtual_ipaddress {

192.168.8.100

192.168.8.200

}

}

Virtual_server 192.168.8.100 80 {

Delay_loop 6

Lb_algo rr

Lb_kind DR

Nat_mask 255.255.255.0

Persistence_timeout 50

Protocol TCP

Real_server 192.168.8.12 80 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 80

}

}

Real_server 192.168.8.13 80 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 80

}

}

}

Virtual_server 192.168.8.100 21 {

Delay_loop 6

Lb_algo rr

Lb_kind DR

Nat_mask 255.255.255.0

Persistence_timeout 50

Protocol TCP

Real_server 192.168.8.12 21 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 21

}

}

Real_server 192.168.8.13 21 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 21

}

}

}

Virtual_server 192.168.8.200 8066 {

Delay_loop 6

Lb_algo rr

Lb_kind DR

Nat_mask 255.255.255.0

Persistence_timeout 50

Protocol TCP

Real_server 192.168.8.22 8066 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8066

}

}

Real_server 192.168.8.23 8066 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8066

}

}

}

On LVS-DR-Backup, the configuration is as follows (192.168.8.11 operation):

! Configuration File for keepalived

Global_defs {

Notification_email {

Acassen@firewall.loc

Failover@firewall.loc

Sysadmin@firewall.loc

}

Notification_email_from Alexandre.Cassen@firewall.loc

Smtp_server 192.168.200.1

Smtp_connect_timeout 30

Router_id LVS_DEVEL

}

Vrrp_instance VI_1 {

State BACKUP

Interface ens160

Virtual_router_id 51

Priority 90

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 123456

}

Virtual_ipaddress {

192.168.8.100

192.168.8.200

}

}

Virtual_server 192.168.8.100 80 {

Delay_loop 6

Lb_algo rr

Lb_kind DR

Nat_mask 255.255.255.0

Persistence_timeout 50

Protocol TCP

Real_server 192.168.8.12 80 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 80

}

}

Real_server 192.168.8.13 80 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 80

}

}

}

Virtual_server 192.168.8.100 21 {

Delay_loop 6

Lb_algo rr

Lb_kind DR

Nat_mask 255.255.255.0

Persistence_timeout 50

Protocol TCP

Real_server 192.168.8.12 21 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 21

}

}

Real_server 192.168.8.13 21 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 21

}

}

}

Virtual_server 192.168.8.200 8066 {

Delay_loop 6

Lb_algo rr

Lb_kind DR

Nat_mask 255.255.255.0

Persistence_timeout 50

Protocol TCP

Real_server 192.168.8.22 8066 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8066

}

}

Real_server 192.168.8.23 8066 {

Weight 1

TCP_CHECK {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

Connect_port 8066

}

}

}

1.6.4 Virtual IP script

Mycat server (192.168.8.22 and 192.168.8.23) operation

Chmod+x / etc/rc.d/init.d/functions

Vi/usr/local/bin/realserver.sh

#! / bin/bash

# description: Config realserver

VIP=192.168.8.200

/ etc/rc.d/init.d/functions

Case "$1" in

Start)

/ sbin/ifconfig lo:0$ VIP netmask 255.255.255.255 broadcast $VIP

/ sbin/route add-host $VIP dev lo:0

Echo "1" > / proc/sys/net/ipv4/conf/lo/arp_ignore

Echo "2" > / proc/sys/net/ipv4/conf/lo/arp_announce

Echo "1" > / proc/sys/net/ipv4/conf/all/arp_ignore

Echo "2" > / proc/sys/net/ipv4/conf/all/arp_announce

Sysctl-p > / dev/null 2 > & 1

Echo "RealServer Start OK"

Stop)

/ sbin/ifconfig lo:0 down

/ sbin/route del $VIP > / dev/null 2 > & 1

Echo "0" > / proc/sys/net/ipv4/conf/lo/arp_ignore

Echo "0" > / proc/sys/net/ipv4/conf/lo/arp_announce

Echo "0" > / proc/sys/net/ipv4/conf/all/arp_ignore

Echo "0" > / proc/sys/net/ipv4/conf/all/arp_announce

Echo "RealServer Stoped"

*)

Echo "Usage: $0 {start | stop}"

Exit 1

Esac

Exit 0

Startup script

/ usr/local/bin/realserver.shstart

1.6.5 start keepalived

LVS-DR-Master (192.168.8.22) and LVS-DR-Backup (192.168.8.13) operate:

/ etc/init.d/keepalivedstart

Use the ipvsadm-L command to see if VIP can be successfully mapped to the back-end service. If it fails, you can use the / var/log/messages log to locate the cause of the keepalived startup failure.

IPVirtual Server version 1.2.1 (size=4096)

ProtLocalAddress:Port Scheduler Flags

-> RemoteAddress:Port Forward Weight ActiveConn InActConn

TCP 123.com:8066 rr

-> 192.168.8.22 Route 8066 1 0

-> 192.168.8.23 Route 8066 0 0

If there is anything else you need to know, you can find our professional technical engineer on the official website. The technical engineer has more than ten years of experience in the industry, so it will be more detailed and professional than the editor's answer. Official website link www.yisu.com

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report