zabbix高可用搭建--數(shù)據(jù)庫(kù)集群(2)

一瘪撇、數(shù)據(jù)mariadb集群搭建分為兩個(gè)內(nèi)容

1、負(fù)載均衡搭建

2倔既、mariadb galera cluster

二、負(fù)載均衡搭建

負(fù)載均衡集群是 load balance 集群的簡(jiǎn)寫(xiě)佩谣,翻譯成中文就是負(fù)載均衡集群歼捏。常用的負(fù)載均衡開(kāi)源軟件有nginx笨篷、lvs、haproxy练俐,商業(yè)的硬件負(fù)載均衡設(shè)備F5冕臭、Netscale。這里主要是學(xué)習(xí) LVS 并對(duì)其進(jìn)行了詳細(xì)的總結(jié)記錄悯蝉。本次采用lvs的DR模式

2.1 安裝keepalive和lvs安裝包

yum install -y ##### keepalived 安裝keepalive

yum install -y ipvsadm ##### 安裝裝lvs

2.2、編輯keepalive的配置托慨,keepalive與網(wǎng)絡(luò)的vrrp原理一樣

vi /etc/keepalive/keepalived.conf

vrrp_instance VI_1 {

state MASTER

! nopreempt

interface chkconfig keepalived on

garp_master_delay 10

virtual_router_id 50

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass zabbix

}

virtual_ipaddress {

192.168.1.157

}

}

virtual_server 192.168.1.157 3306 {

delay_loop 6

lb_algo wrr

lb_kind DR

nat_mask 255.255.255.0

persistence_timeout 50

protocol TCP

real_server192.168.1.1543306{weight1TCP_CHECK {connect_port3306connect_timeout3nb_get_retry3delay_before_retry3}}real_server192.168.1.1553306{weight1TCP_CHECK {connect_port3306connect_timeout3nb_get_retry3delay_before_retry3}}

real_server 192.168.1 3306 {

weight 1

TCP_CHECK {

connect_port 3306

connect_timeout 3

nb_get_retry 3

delay_before_retry 3

}

}

}

2.3.開(kāi)啟keepalive鼻由、ipvsam服務(wù)

systemctl start keepalived

systemctl start ipvsam

2.4、驗(yàn)證

ipvsam 查看負(fù)載情況

三厚棵、mariadb 集群

3.1 數(shù)據(jù)庫(kù)安裝?

分別在三臺(tái)主機(jī)安裝mariadb的數(shù)據(jù)蕉世,本次安裝10.3.14版本的數(shù)據(jù),較為穩(wěn)定的版本

vi /etc/yum.repos.d/MariaDB.repo

[mariadb]

name = MariaDB-10.3.14

baseurl=http://yum.mariadb.org/10.3.14/centos7-amd64

alternative: baseurl=http://archive.mariadb.org/mariadb-10.3.14/yum/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

[root@localhost /]# yum install mariadb-server -y

Loaded plugins: langpacks, product-id, subscription-manager

Complete!

[root@localhost /]# rpm -qa | grep mariadb

mariadb-server-5.5.50-1.el7_2.x86_64

mariadb-libs-5.5.50-1.el7_2.x86_64

mariadb-5.5.50-1.el7_2.x86_64

mariadb-devel-5.5.50-1.el7_2.x86_64

啟動(dòng)mariadb服務(wù)程序并添加到開(kāi)機(jī)啟動(dòng)項(xiàng)中:

[root@localhost /]# systemctl start mariadb

[root@localhost /]# systemctl enable mariadb

[root@localhost /]# netstat -anpt | grep 3306

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 22418/mysqld

[root@localhost /]# ps -ef | grep mariadb

mysql 22418 22259 0 00:39 ? 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock

root 22459 1092 0 00:40 pts/0 00:00:00 grep --color=auto mariadb

[root@localhost /]# ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'

為了保證數(shù)據(jù)庫(kù)的安全性婆硬,一定要進(jìn)行初始化工作:

第1步:設(shè)定root用戶密碼狠轻。

第2步:刪除匿名帳號(hào)。

第3步:禁止root用戶從遠(yuǎn)程登陸向楼。

第4步:刪除test數(shù)據(jù)庫(kù)并取消對(duì)其的訪問(wèn)權(quán)限查吊。

第5步:刷新授權(quán)表,讓初始化后的設(shè)定立即生效蜜自。

初始化數(shù)據(jù)庫(kù)服務(wù)程序:

[root@localhost /]# mysql_secure_installation

/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current

password for the root user. If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none): 當(dāng)前數(shù)據(jù)庫(kù)密碼為空菩貌,直接敲擊回車(chē)。

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

Set root password? [Y/n] y

New password: 輸入要為root用戶設(shè)置的數(shù)據(jù)庫(kù)密碼重荠。

Re-enter new password: 重復(fù)再輸入一次密碼箭阶。

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them. This is intended only for testing, and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y(刪除匿名帳號(hào))

... Success!

Normally, root should only be allowed to connect from 'localhost'. This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y(禁止root用戶從遠(yuǎn)程登陸)

... Success!

By default, MariaDB comes with a database named 'test' that anyone can

access. This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y(刪除test數(shù)據(jù)庫(kù)并取消對(duì)其的訪問(wèn)權(quán)限)

Dropping test database...

... Success!

Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y(刷新授權(quán)表,讓初始化后的設(shè)定立即生效)

... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

使用root用戶登陸到數(shù)據(jù)庫(kù)中:

[root@localhost /]# mysql -u root -p

Enter password: 此處輸入root用戶在數(shù)據(jù)庫(kù)中的密碼戈鲁。

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 5

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

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

MariaDB [(none)]>

查看當(dāng)前已有的數(shù)據(jù)庫(kù):

MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

+--------------------+

3 rows in set (0.01 sec)

3.2 配置集群

vi /etc/my.conf

[mysqld]

binlog_format=ROW

default-storage-engine=innodb

innodb_autoinc_lock_mode=2

bind-address=0.0.0.0

Galera Provider Configuration

wsrep_on=ON

wsrep_provider=/usr/lib64/galera/libgalera_smm.so

Galera Cluster Configuration

wsrep_cluster_name="galera_cluster"

wsrep_cluster_address="gcomm://192.168.1.192.168.1.155,192.168.1.156,"

Galera Synchronization Configuration

wsrep_sst_method=rsync

Galera Node Configuration

wsrep_node_address="192.168.1.156" #####其他節(jié)點(diǎn)需要修改

wsrep_node_name="Node1" #####其他節(jié)點(diǎn)需要修改

第1個(gè)節(jié)點(diǎn)先啟動(dòng) 使用galera_new_cluster

其他節(jié)點(diǎn)使用 systemctl start mariadb

3.4 安裝zabbix-server-mysql

為了將zabbix的數(shù)據(jù)文件導(dǎo)入mysql中

mysql -uroot -p

password

mysql> create database zabbix character set utf8 collate utf8_bin;

mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';

mysql> quit;

導(dǎo)入初始架構(gòu)和數(shù)據(jù)仇参,系統(tǒng)將提示您輸入新創(chuàng)建的密碼。

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

五婆殿、配置vip

因?yàn)樨?fù)載均衡lvs的DR原理诈乒,每臺(tái)數(shù)據(jù)庫(kù)都必須配置vip地址,并不對(duì)外進(jìn)行廣播

#!/bin/bash

#description:start realserver

vip1=192.168.1.157

case $1 in

start)

echo "Start Realserver"

/sbin/ifconfig lo:0 $vip1 broadcast $vip1 netmask 255.255.255.255 up

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

;;

stop)

echo "Stop Realserver"

/sbin/ifconfig lo:0 down

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 "Usage: $0 (start | stop)"

exit 1

esac

最后運(yùn)行shell腳本

常見(jiàn)故障

搭建galera cluster的時(shí)候設(shè)置sst為xtrabackup婆芦,啟動(dòng)node1報(bào)錯(cuò)怕磨。

[ERROR] WSREP: It may not be safe to bootstrap the cluster from this node. It was not the last one to leave the cluster and may not contain all the updates. To force cluster bootstrap with this node, edit the grastate.dat file manually and set safe_to_bootstrap to 1 .

解決方式:

grastate.dat file of the node you intend to use as the first node.

需要把該文件刪除 重新啟動(dòng)即可。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末消约,一起剝皮案震驚了整個(gè)濱河市肠鲫,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌或粮,老刑警劉巖导饲,帶你破解...
    沈念sama閱讀 216,324評(píng)論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異氯材,居然都是意外死亡渣锦,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,356評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén)氢哮,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)袋毙,“玉大人,你說(shuō)我怎么就攤上這事冗尤÷γǎ” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 162,328評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵生闲,是天一觀的道長(zhǎng)媳溺。 經(jīng)常有香客問(wèn)我,道長(zhǎng)碍讯,這世上最難降的妖魔是什么悬蔽? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,147評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮捉兴,結(jié)果婚禮上蝎困,老公的妹妹穿的比我還像新娘录语。我一直安慰自己,他們只是感情好禾乘,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,160評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布澎埠。 她就那樣靜靜地躺著,像睡著了一般始藕。 火紅的嫁衣襯著肌膚如雪蒲稳。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,115評(píng)論 1 296
  • 那天伍派,我揣著相機(jī)與錄音江耀,去河邊找鬼。 笑死诉植,一個(gè)胖子當(dāng)著我的面吹牛祥国,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播晾腔,決...
    沈念sama閱讀 40,025評(píng)論 3 417
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼舌稀,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了灼擂?” 一聲冷哼從身側(cè)響起壁查,我...
    開(kāi)封第一講書(shū)人閱讀 38,867評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎缤至,沒(méi)想到半個(gè)月后潮罪,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體康谆,經(jīng)...
    沈念sama閱讀 45,307評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡领斥,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,528評(píng)論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了沃暗。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片月洛。...
    茶點(diǎn)故事閱讀 39,688評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖孽锥,靈堂內(nèi)的尸體忽然破棺而出嚼黔,到底是詐尸還是另有隱情,我是刑警寧澤惜辑,帶...
    沈念sama閱讀 35,409評(píng)論 5 343
  • 正文 年R本政府宣布唬涧,位于F島的核電站,受9級(jí)特大地震影響盛撑,放射性物質(zhì)發(fā)生泄漏碎节。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,001評(píng)論 3 325
  • 文/蒙蒙 一抵卫、第九天 我趴在偏房一處隱蔽的房頂上張望狮荔。 院中可真熱鬧胎撇,春花似錦、人聲如沸殖氏。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,657評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)雅采。三九已至爵憎,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間总滩,已是汗流浹背纲堵。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,811評(píng)論 1 268
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留闰渔,地道東北人席函。 一個(gè)月前我還...
    沈念sama閱讀 47,685評(píng)論 2 368
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像冈涧,于是被迫代替她去往敵國(guó)和親茂附。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,573評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容