久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

怎么搭建LVS+Keepalived+MySQL

127次閱讀
沒有評論

共計 4005 個字符,預計需要花費 11 分鐘才能閱讀完成。

本篇內容主要講解“怎么搭建 LVS+Keepalived+MySQL”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓丸趣 TV 小編來帶大家學習“怎么搭建 LVS+Keepalived+MySQL”吧!

LVS 負責負載均衡轉發請求,keepalived 負責檢查 LVS 的 realserver 狀態,及時 remove 失效節點、add 復活節點。
本實驗主要功能測試,所以只準備了兩臺 MySQL 服務器,僅為簡單說明問題。
vm1 10.0.0.11     master   server_id 11
vm2 10.0.0.12     slave       server_id 12

Director:
vm3 10.0.0.14 

VIP: 10.0.0.20

1 在 Directory server vm3 上安裝 ipvsadm 和 keepalived
yum install ipvsadm
安裝 keepalived
yum install libnfnetlink*
tar -zxvf keepalived-1.2.7.tar.gz
./configure –prefix=/usr/local/keepalived
make make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived

2 vm1 vm2 上,執行以下操作.
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 

ifconfig lo:0 10.0.0.20 netmask 255.255.255.255

3 在 Directory server vm3 上編輯 /etc/keepalived/keepalived.conf 文件,內容如下:

點擊 (此處) 折疊或打開

global_defs {

router_id HaMySQL_1

}

vrrp_sync_group VGM {

group {

VI_MYSQL

}

}

vrrp_instance VI_MYSQL {

state MASTER

interface eth0

virtual_router_id 100

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

10.0.0.20

}

}

virtual_server 10.0.0.20 3306 {

delay_loop 6

lb_algo rr

lb_kind DR

protocol TCP

nat_mask 255.255.255.0

persistence_timeout 10

real_server 10.0.0.11 3306 {

weight 3

TCP_CHECK {

connect_timeout 3

nb_get_retry 3

delay_before_retry 3

connect_port 3306

}

}

real_server 10.0.0.12 3306 {

weight 3

TCP_CHECK {

connect_timeout 3

nb_get_retry 3

delay_before_retry 3

connect_port 3306

}

}

}

4 啟動 MySQL 和 keepalived。
vm1:
/usr/local/mysql/bin/mysqld_safe –defaults-file=/data/mysql3306/my.cnf

vm2:
/usr/local/mysql/bin/mysqld_safe –defaults-file=/data/mysql3306/my.cnf

vm3:
/etc/init.d/keepalived start

5 驗證
vm3:
[root@vm3 keepalived]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
 – RemoteAddress:Port       Forward Weight ActiveConn InActConn
TCP 10.0.0.20:3306 rr persistent 2
 – 10.0.0.11:3306           Route   3     1        0
 – 10.0.0.12:3306           Route   3     1        0

可以看到負載均衡已啟動,vm2 vm3 都已加進來了。
從客戶端連接 VIP 10.0.0.20:3306
C:\mysql-5.7.11-winx64\mysql-5.7.11-winx64\bin mysql.exe -uroot -pmysql -h20.0.0.20 -P3306
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 90
Server version: 5.6.27-log Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type help; or \h for help. Type \c to clear the current input statement.

mysql select @@server_id;exit;
+————-+
| @@server_id |
+————-+
|        11 |
+————-+
1 row in set (0.00 sec)

從 server_id 可以看出客戶端連接的是 vm1。

關掉 vm1 上的 MySQL 服務。
[root@vm3 keepalived]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
 – RemoteAddress:Port       Forward Weight ActiveConn InActConn
TCP 10.0.0.20:3306 rr persistent 2
 – 10.0.0.12:3306           Route   3     1        0

LVS 規則已經更新,remove 了 vm1,再次從客戶端連接。
C:\mysql-5.7.11-winx64\mysql-5.7.11-winx64\bin mysql.exe -uroot -pmysql -h20.0.0.20 -P3306
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 61
Server version: 5.6.27-log Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type help; or \h for help. Type \c to clear the current input statement.

mysql select @@server_id;exit;
+————-+
| @@server_id |
+————-+
|        12 |
+————-+
1 row in set (0.00 sec)

重新啟動 vm1 上的 MySQL 服務。
[root@vm3 ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
 – RemoteAddress:Port       Forward Weight ActiveConn InActConn
TCP 10.0.0.20:3306 rr persistent 2
 – 10.0.0.11:3306           Route   3     1        0
 – 10.0.0.12:3306           Route   3     1        1

LVS 規則已自動刷新,vm1 重新被加入。

到此,相信大家對“怎么搭建 LVS+Keepalived+MySQL”有了更深的了解,不妨來實際操作一番吧!這里是丸趣 TV 網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-19發表,共計4005字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 略阳县| 怀柔区| 盐亭县| 秭归县| 吴堡县| 门源| 漳州市| 屏东市| 琼结县| 施秉县| 昌黎县| 綦江县| 高台县| 广德县| 泽州县| 四川省| 泽普县| 怀宁县| 共和县| 浮梁县| 墨竹工卡县| 广州市| 贺兰县| 佛学| 响水县| 安塞县| 达孜县| 台南市| 白水县| 南乐县| 信宜市| 如东县| 平乡县| 泰来县| 应用必备| 榕江县| 桦川县| 鄂伦春自治旗| 茂名市| 涿鹿县| 黔江区|