標籤:phxsql
。需求:公司某軟體使用phxsql已經部署在3個機房,現需要在新的機房增加一個phxsql節點,以下為操作過程,因為保護隱私把4台IP用
1.1.1.1
2.2.2.2
3.3.3.3
新的ip為4.4.4.4
。安裝Phxsql需要Python2.7版本,Centos預設為2.6版本,需要進行升級
cd /optwget --no-check-certificate https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xztar xf Python-2.7.6.tar.xzcd Python-2.7.6./configure --prefix=/usr/localmake && make install
。Phxsql需要升級glibc包,Centos6.5預設為2.12版本,升級為2.20版本。因為glic是作業系統底層庫,謹慎操作
glibc-common-2.12-1.149.el6_6.5.x86_64glibc-2.12-1.149.el6_6.5.i686glibc-2.12-1.149.el6_6.5.x86_64glibc-headers-2.12-1.149.el6_6.5.x86_64glibc-devel-2.12-1.149.el6_6.5.x86_64
升級操作
rpm -Uvh --aid --force --nodeps glibc-headers-2.20-8.fc21.x86_64.rpmrpm -Uvh --aid --force --nodeps glibc-devel-2.20-8.fc21.x86_64.rpmrpm -Uvh --aid --force --nodeps glibc-2.20-8.fc21.x86_64.rpmrpm -Uvh --aid --force --nodeps glibc-common-2.20-8.fc21.x86_64.rpm
。四個phxsql節點的伺服器,防火牆需要開放如下幾個連接埠
iptables -A INPUT -p tcp -m multiport --dports 11111,54321,54322 -s 4.4.4.4 -j ACCEPT
。在phxsql叢集裡任意一個節點,在新節點還沒有開始安裝部署phxsql時,把新節點IP添加到叢集裡面
phxbinlogsvr_tools_phxrpc -f AddMember -h1.1.1.1 -p17000 -m 4.4.4.4
加後使用命令列檢查
phxbinlogsvr_tools_phxrpc -f GetMemberList -h1.1.1.1 -p 17000
。設定phxsql的資料目錄,官網教程定義目錄為/tmp/data,這裡改為/data1/
cd /data1/phxsql/tools/mkdir -p /data1/phxsql/tmp/data/logchown -R mysql:mysql /data1/phxsql/tmp/data/logpython2.7 install.py -i"4.4.4.4" -p 54321 -g 6000 -y 11111 -P 17000 -a 8001 -f /data1/phxsql/tmp/data/
安裝過程會出現如下資訊
Namespace(agent_port=6000, base_dir=‘/data1/phxsql/‘, data_dir=‘/data1/phxsql/tmp/data/‘, inner_ip=‘183.36.122.100‘, ip_list=‘4.4.4.4‘, module_name=‘test‘, mysql_port=11111, paxos_port=8001, phxbinlogsvr_port=17000, phxsqlproxy_port=54321, process_name=‘all‘, skip_data=0)kill all binaries success....mkdir: cannot create directory `/data1/phxsql/etc‘: File existsgenerate all configs success....mkdir: cannot create directory `/data1/phxsql/tmp/data/log‘: File exists/data1/phxsql/tmp/data/phxbinlogsvrskip data 0mkdir: cannot create directory `/data1/phxsql/tmp/data/log‘: File exists/data1/phxsql/tmp/data/percona.workspacecd /data1/phxsql/percona.src; ./scripts/mysql_install_db --defaults-file=/data1/phxsql/etc/my.cnf --user=mysqlWARNING: The host ‘centos‘ could not be looked up with /data1/phxsql/percona.src/bin/resolveip.This probably means that your libc libraries are not 100 % compatiblewith this binary MySQL version. The MySQL daemon, mysqld, should worknormally with the exception that host name resolving will not work.This means that you should use IP addresses instead of hostnameswhen specifying MySQL privileges !Installing MySQL system tables...2017-05-04 04:07:27 0 [Warning] ‘THREAD_CONCURRENCY‘ is deprecated and will be removed in a future release.2017-05-04 04:07:27 0 [Note] ./bin/mysqld (mysqld 5.6.31-77.0-log) starting as process 55454 ...OKFilling help tables...2017-05-04 04:07:32 0 [Warning] ‘THREAD_CONCURRENCY‘ is deprecated and will be removed in a future release.2017-05-04 04:07:32 0 [Note] ./bin/mysqld (mysqld 5.6.31-77.0-log) starting as process 55496 ...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands: /data1/phxsql/percona.src/bin/mysqladmin -u root password ‘new-password‘ /data1/phxsql/percona.src/bin/mysqladmin -u root -h centos password ‘new-password‘Alternatively you can run: /data1/phxsql/percona.src/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with: cd . ; /data1/phxsql/percona.src/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.plPlease report any problems at https://bugs.launchpad.net/percona-server/+filebugThe latest information about Percona Server is available on the web at http://www.percona.com/software/percona-serverSupport Percona by buying support at http://www.percona.com/products/mysql-supportinstall all success....nohup: appending output to `nohup.out‘nohup: appending output to `nohup.out‘WARNING: Logging before InitGoogleLogging() is written to STDERRW0504 04:07:39.378021 55555 phx_glog.cpp:74] GetDefaultPath get debuf path /data1/phxsql/etc/W0504 04:07:39.385524 55555 phx_glog.cpp:74] RealReadFile read path /data1/phxsql/etc/phxsqlproxy.conf doneW0504 04:07:39.385609 55555 phx_glog.cpp:74] read plugin config []W0504 04:07:39.385701 55555 phx_glog.cpp:74] RealReadFile read path /data1/phxsql/etc/phxsqlproxy.conf doneW0504 04:07:39.385752 55555 phx_glog.cpp:74] read plugin config []start master worker finished ...start slave worker finished ...init pid 55580 env 0x7f77780008c0init pid 55582 env 0x7f777c0008c0init pid 55583 env 0x7f77700008c0init pid 55585 env 0x7f77800008c0init pid 55586 env 0x7f77740008c0init pid 55587 env 0x7f77840008c0init pid 55588 env 0x7f77780008c0init pid 55589 env 0x7f777c0008c0init pid 55592 env 0x7f77680008c0init pid 55593 env 0x7f776c0008c0init pid 55598 env 0x7f77700008c0init pid 55602 env 0x7f77680008c0init pid 55600 env 0x7f77600008c0init pid 55608 env 0x7f77640008c0init pid 55605 env 0x7f77600008c0
。如果安裝成功,如下3個進程會啟動
ps -ef|grep -v grep | grep phxsqlproxy
ps -ef|grep -v grep | grep mysql
ps -ef|grep -v grep | grep phxbinlogsvr
偶爾phxbinlogsvr不會啟動,不過沒有關係,因為如果phxbinlogsvr 啟動了,就需要把它kill掉
killall -9 phxbinlogsvr_phxrpc
。添加環境變數
vi /etc/profileexport PATH=/data1/phxsql/sbin:$PATH. /etc/profile
。phxsql安裝好了,目前是空的,需要從一個有資料的節點上把資料導過來,通常會選擇從點,通過命令查詢哪個是master,然後避開master,我這邊資料量是200G,對於匯出大量的資料會很消耗磁碟資源,需要讓業務切換到其他點。
phxbinlogsvr_tools_phxrpc -f GetMemberList -h1.1.1.1 -p 17000
。使用mysqldump匯出資料,需要加一個--quick參數,目的是匯出資料時不經過buffer pool,而是直接從磁碟取數,然後儲存到檔案,建議使用指令碼,為了知道導數到底用了多少時間。注意匯出的是全量資料 --all-database,因為phxsql下所有節點的資料量都是一致的,相當於多點冗餘
function output_data(){ start_date=$(date +%s) /data1/phxsql/percona.src/bin/mysqldump --quick -uroot -S /data1/phxsql/tmp/data/percona.workspace/tmp/percona.sock --all-databases > phxsql.alldata end_date=$(date +%s) backup_time=$(( $end_date - $start_date )) echo "匯出耗時:"${backup_time}"秒"}
200G的資料,匯出檔案67G,大概3倍的壓縮,一共2393秒,平均11秒可以匯出1G
。一直有個困惑,iostat佔用率和負載到底臨界值是多少,才不需要切業務呢?導數的時候是否有必要去遷業務呢?
avg-cpu: %user %nice %system %iowait %steal %idle 2.31 0.00 1.13 1.76 0.00 94.79Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await r_await w_await svctm %utilsda 0.00 0.00 0.00 1.00 0.00 8.00 8.00 0.00 3.00 0.00 3.00 3.00 0.30sdb 0.00 117.00 2048.00 362.00 65536.00 3832.00 28.78 0.67 0.28 0.23 0.56 0.23 56.40
。資料匯出來以後,使用rsync傳輸到另外一個機房的伺服器上
rsync -av --port=8732 --password-file=/home/lijunda/rsyncd_ccopy_passwd1 --progress [email protected]::item/data1/phxsql.alldata /data1/receiving incremental file listphxsql.alldata 30137810944 42% 113.03MB/s 0:05:52
。在新機房DB匯入資料,phxsql不管在哪個節點寫入資料,都會通過proxy路由到主庫進行寫入,而現在要往從庫匯入資料,需要把唯讀功能停止掉
mysql -uroot -S /data1/phxsql/tmp/data/percona.workspace/tmp/percona.sock-e "set global super_read_only=off; set global read_only=off;reset master;";mysql -uroot -S /data1/phxsql/tmp/data/percona.workspace/tmp/percona.sock < phxsql.alldata
本文出自 “DBA營運總結” 部落格,轉載請與作者聯絡!
安裝部署Phxsql