mysql-proxy配置

來源:互聯網
上載者:User

標籤:identified   mysql   

【主庫上】在已有主從同步配置的基礎上增加log配置項,開啟“全日誌”功能。vim /etc/my.cnflog=mysqlfull.logservice mysqld restartcat /var/lib/mysql/mysqlfull.log給mysqlproxy機器授權:grant all on *.* to ‘root‘@‘%‘ identified by ‘123123‘;【從庫上】在已有主從同步配置的基礎上增加log配置項,開啟“全日誌”功能。vim /etc/my.cnflog=mysqlfull.logservice mysqld restartcat /var/lib/mysql/mysqlfull.log給mysqlproxy機器授權:grant all on *.* to ‘root‘@‘%‘ identified by ‘123123‘;--------------------------------------------------------------------【搭建mysqlproxy】tar zxf mysql-proxy-0.8.3-linux-rhel5-x86-32bit.tar.gzmv  mysql-proxy-0.8.3-linux-rhel5-x86-32bit   /usr/local/mysql-proxy【配置】(1)修改主配置cd /usr/local/mysql-proxy/建立conf log目錄mkdir conf logvim建立mysql-proxy.conf,加入下面的內容vim ./conf/mysql-proxy.conf[mysql-proxy]#本機 監聽地址 和 開啟的連接埠,預設連接埠4040proxy-address=0.0.0.0:4040#後端mysql使用者名稱和密碼admin-username=rootadmin-password=123123#mysql管理命令,用於對後端mysql叢集中每台主機的 健全狀態檢查 admin-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/admin-sql.lua#配置主庫ip和連接埠proxy-backend-addresses=192.168.20.181:3306#配置 從 庫ip和連接埠,有多少個從庫的,就需要配置多少行proxy-read-only-backend-addresses=192.168.20.23:3306proxy-read-only-backend-addresses=192.168.20.24:3306proxy-read-only-backend-addresses=192.168.20.25:3306#讀寫分離lua指令碼proxy-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua#日誌路徑 log-file=/usr/local/mysql-proxy/log/mysql-proxy.log#記錄層級log-level=debug#啟動參數,以守護進程方法啟動daemon=true#開啟keepalive,如果mysql-proxy進程異常終止後,mysql-proxy將會自動啟起。keepalive=true(2)修改讀寫分配置,以方便做測試,因為用戶端串連數超過到min_idle_connections後才能讓讀走從庫, 不然讀還走主庫。vim /usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua                min_idle_connections = 1,                max_idle_connections = 2, 【啟動mysqlproxy】cd /etc/init.d/vim mysqlproxy#!/bin/bash#chkconfig: - 99 23#description: mysql_proxymysql_proxy_home=‘/usr/local/mysql-proxy‘case "$1" in start)$mysql_proxy_home/bin/mysql-proxy --defaults-file=$mysql_proxy_home/conf/mysql-proxy.conf        ;;stop)        killall -9 mysql-proxy &>/dev/null        ;;restart)        killall -9 mysql-proxy &>/dev/null        $mysql_proxy_home/bin/mysql-proxy --defaults-file=$mysql_proxy_home/conf/mysql-proxy.conf        ;;*)        echo "Usage: $0 {start|stop|restart}"        exit 1esacexit 0儲存退出後:chmod +x /etc/init.d/mysqlproxychkconfig --add mysqlproxy chmod 660 /usr/local/mysql-proxy/conf/mysql-proxy.conf service mysqlproxy start或者在cd /usr/local/mysql-proxy/下直接:  sh mysqlproxy start|stop|restart 也可以做啟停操作[[email protected] mysql-proxy]# netstat -nlp | grep 4040tcp        0      0 0.0.0.0:4040                0.0.0.0:*                   LISTEN      23096/mysql-proxy【測試】主庫上:tail -f /var/lib/mysql/mysqlfull.log從庫上:tail -f /var/lib/mysql/mysqlfull.log多開幾個串連向mysqlproxy的4040連接埠做測試,串連數要大於min_idle_connections值,此處應大於2。mysql -u root -h192.168.6.106 -P 4040 -p123123mysql -u root -h192.168.6.106 -P 4040 -p123123mysql -u root -h192.168.6.106 -P 4040 -p123123**** 192.168.6.106為主庫的ip地址,測試時寫成自己主庫的ip地址,此處不能寫成127.0.0.1也不能寫成localhost ****測試select語句和create,insert語句,如果從庫上只有查詢(select),主庫上只有寫(create,update,insert)說明實驗正常。

本文出自 “江湖笑笑生” 部落格,謝絕轉載!

mysql-proxy配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.