如何進行sandbox和MHA的測試-創(chuàng)新互聯(lián)

本篇文章為大家展示了如何進行sandbox和MHA的測試,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

創(chuàng)新互聯(lián)建站長期為上千多家客戶提供的網(wǎng)站建設服務,團隊從業(yè)經驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為天橋企業(yè)提供專業(yè)的網(wǎng)站制作、成都做網(wǎng)站天橋網(wǎng)站改版等技術服務。擁有十年豐富建站經驗和眾多成功案例,為您定制開發(fā)。

昨天寫了一篇使用腳本搭建一主多從的腳本之后,奇龍兄建議我看看sandbox的功能,可以秒級搭建主從環(huán)境,簡單試了下,確實很好很強大。

   環(huán)境部署其實很簡單,如果有網(wǎng)絡環(huán)境,直接cpan一個命令即可。或者使用wget的方式來安裝也可以。

安裝sandbox

使用cpan來安裝,非常簡單,就是下面的命令:

cpan MySQL::Sandbox

一些日志的輸出之后就提示你安裝成功,在/usr/local/bin下面就會多幾個make_sandbox相關的命令。

[root@grtest bin]# ll make*
-r-xr-xr-x 1 root root  8681 Apr 12 16:16 make_multiple_custom_sandbox
-r-xr-xr-x 1 root root 13862 Apr 12 16:16 make_multiple_sandbox
-r-xr-xr-x 1 root root 22260 Apr 12 16:16 make_replication_sandbox
-r-xr-xr-x 1 root root 11454 Apr 12 16:16 make_sandbox
-r-xr-xr-x 1 root root  4970 Apr 12 16:16 make_sandbox_from_installed
-r-xr-xr-x 1 root root  7643 Apr 12 16:16 make_sandbox_from_source
-r-xr-xr-x 1 root root  5772 Apr 12 16:16 make_sandbox_from_url

另外一種方式是通過安裝包的方式,可以通過編譯安裝完成。

可以使用wget下載安裝包:

# wget https://launchpad.net/mysql-sandbox/mysql-sandbox-3/mysql-sandbox-3/+download/MySQL-Sandbox-3.0.25.tar.gz然后使用make,make install的方式即可安裝。

比如我要部署一個MySQL數(shù)據(jù)庫環(huán)境,我們給定一個二進制安裝包,直接make_sandbox即可。

# make_sandbox mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz這個命令有一點需要說明,就是考慮到安全,默認使用root是敏感的,會拋出下面的警告。主要就是向你確認是否確實要這兒做,如果是一個線上環(huán)境,操作的風險很高,所以就特別提示,需要你設定一個變量值,確認之后才可以。

# make_sandbox percona-server-5.6.25-73.1.tar.gz
MySQL Sandbox should not run as root

If you know what you are doing and want to
 run as root nonetheless, please set the environment
variable 'SANDBOX_AS_ROOT' to a nonzero value我們就給這個變量給一個值,比如go

export SANDBOX_AS_ROOT=go一套數(shù)據(jù)庫環(huán)境就自動部署出來了,難得的是會自動生成對應的快捷腳本,如果下個做一些批量管理類的任務,就非??旖莘奖?,這里的數(shù)據(jù)庫安裝目錄是msb_5_7_17,數(shù)據(jù)文件都在這個目錄下面。

[root@grtest sandboxes]# ll
total 48
-rwxr-xr-x 1 root root   54 Apr 12 16:35 clear_all
drwxr-xr-x 4 root root 4096 Apr 12 16:35 msb_5_7_17
-rw-r--r-- 1 root root 3621 Apr 12 16:35 plugin.conf
-rwxr-xr-x 1 root root   56 Apr 12 16:35 restart_all
-rwxr-xr-x 1 root root 2145 Apr 12 16:35 sandbox_action
-rwxr-xr-x 1 root root   58 Apr 12 16:35 send_kill_all
-rwxr-xr-x 1 root root   54 Apr 12 16:35 start_all
-rwxr-xr-x 1 root root   55 Apr 12 16:35 status_all
-rwxr-xr-x 1 root root   53 Apr 12 16:35 stop_all
-rwxr-xr-x 1 root root 4514 Apr 12 16:35 test_replication
-rwxr-xr-x 1 root root   52 Apr 12 16:35 use_all連接數(shù)據(jù)庫,只需要一個use命令即可。

 ./use
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.17 MySQL Community Server (GPL)
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 [localhost] {msandbox} ((none)) >其它的啟停命令也是如此,非??旖莘奖?。

而要搭建主從環(huán)境,操作步驟簡單,輸出日志也很簡單,比如我指定一個已經解壓的二進制目錄5.7.17,就會默認創(chuàng)建一主兩從的環(huán)境。

# export SANDBOX_AS_ROOT=go
# make_replication_sandbox 5.7.17
installing and starting master
installing slave 1
installing slave 2
starting slave 1
.. sandbox server started
starting slave 2
. sandbox server started
initializing slave 1
initializing slave 2
replication directory installed in $HOME/sandboxes/rsandbox_5_7_17查看主從的狀態(tài),使用status_all即可。

# ./status_all
REPLICATION rsandbox_5_7_17
master on
port: 20192
node1 on
port: 20193
node2 on
port: 20194

MHA快速測試

   當然上面的工作可以使用sandbox來做,也可以使用自定義腳本來做,各有好處,相對來說,手工腳本的方式最起碼自己更清楚一些。

   動態(tài)搭建一主多從,我的一個設想就是快速模擬MHA的環(huán)境。

我們先創(chuàng)建一個數(shù)據(jù)庫用戶mha_test,作為配置中的連接用戶

GRANT ALL PRIVILEGES ON *.* TO 'mha_test'@'%' identified by 'mha_test' ;然后指定一個配置文件,內容如下:

# cat /home/mha/conf/app1.cnf
[server default]
manager_workdir=/home/mha/manager
manager_log=/home/mha/manager/app1/manager.log
port=24801
user=mha_test
password=mha_test
repl_user=rpl_user
repl_password=rpl_pass

[server1]
hostname=127.0.0.1
port=24801
candidate_master=1

[server2]
hostname=127.0.0.1
candidate_master=1
port=24802

[server3]
hostname=127.0.0.1
candidate_master=1
port=24803因為是同一臺服務器,所以能夠快速模擬MHA的容災切換和快速恢復。

使用如下的腳本來檢測SSH的情況。

#  masterha_check_ssh --conf=/home/mha/conf/app1.cnf基本就是如下的ssh連接請檢查。

Wed Apr 12 18:35:52 2017 - [debug]  Connecting via SSH from root@127.0.0.1(127.0.0.1:22) to root@127.0.0.1(127.0.0.1:22)..
Wed Apr 12 18:35:52 2017 - [debug]   ok.
Wed Apr 12 18:35:52 2017 - [debug]  Connecting via SSH from root@127.0.0.1(127.0.0.1:22) to root@127.0.0.1(127.0.0.1:22)..
Wed Apr 12 18:35:52 2017 - [debug]   ok.
Wed Apr 12 18:35:52 2017 - [info] All SSH connection tests passed successfully.檢查主從的復制情況,可以使用如下的命令

masterha_check_repl --conf=/home/mha/conf/app1.cnf

輸出日志部分如下,可以看到主從關系和復制檢測都可以清晰看到。

Wed Apr 12 18:35:29 2017 - [info]
127.0.0.1(127.0.0.1:24801) (current master)
 +--127.0.0.1(127.0.0.1:24802)
 +--127.0.0.1(127.0.0.1:24803)

Wed Apr 12 18:35:29 2017 - [info] Checking replication health on 127.0.0.1..
Wed Apr 12 18:35:29 2017 - [info]  ok.
Wed Apr 12 18:35:29 2017 - [info] Checking replication health on 127.0.0.1..
Wed Apr 12 18:35:29 2017 - [info]  ok.
Wed Apr 12 18:35:29 2017 - [warning] master_ip_failover_script is not defined.
Wed Apr 12 18:35:29 2017 - [warning] shutdown_script is not defined.
Wed Apr 12 18:35:29 2017 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.接著我們啟動MHA-manager

 nohup masterha_manager --conf=/home/mha/conf/app1.cnf  > /tmp/mha_manager.log 2>&1 &如果檢查目前 MHA的狀態(tài),可以使用如下的命令:

# masterha_check_status --conf=/home/mha/conf/app1.cnf
app1 (pid:11701) is running(0:PING_OK), master:127.0.0.1這個時候我們來破壞一下,可以手工Kill掉24081端口的mysqld_safe和mysqld服務。

這個就會從日志中發(fā)現(xiàn)MHA開始工作了。

tail -f /home/mha/manager/app1/manager.log
Wed Apr 12 22:54:53 2017 - [info] Resetting slave info on the new master..
Wed Apr 12 22:54:53 2017 - [info]  127.0.0.1: Resetting slave info succeeded.
Wed Apr 12 22:54:53 2017 - [info] Master failover to 127.0.0.1(127.0.0.1:24802) completed successfully.
Wed Apr 12 22:54:53 2017 - [info]
----- Failover Report -----
app1: MySQL Master failover 127.0.0.1(127.0.0.1:24801) to 127.0.0.1(127.0.0.1:24802) succeeded
Master 127.0.0.1(127.0.0.1:24801) is down!
Check MHA Manager logs at grtest:/home/mha/manager/app1/manager.log for details.
Started automated(non-interactive) failover.
Selected 127.0.0.1(127.0.0.1:24802) as a new master.
127.0.0.1(127.0.0.1:24802): OK: Applying all logs succeeded
127.0.0.1(127.0.0.1:24803): OK: Slave started, replicating from 127.0.0.1(127.0.0.1:24802)
127.0.0.1(127.0.0.1:24802): Resetting slave info succeeded.
Master failover to 127.0.0.1(127.0.0.1:24802) completed successfully.這樣一來24802端口的mysql服務會自動接管,由從庫變?yōu)橹鲙臁6?4803端口的從庫會自動從24802端口的服務接受數(shù)據(jù)變更。

整個過程有條不紊,會分為5個階段來做。

上述內容就是如何進行sandbox和MHA的測試,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注創(chuàng)新互聯(lián)-成都網(wǎng)站建設公司行業(yè)資訊頻道。

網(wǎng)站標題:如何進行sandbox和MHA的測試-創(chuàng)新互聯(lián)
當前鏈接:http://muchs.cn/article24/cedpje.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供App設計、服務器托管、做網(wǎng)站、微信公眾號面包屑導航、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設