2014年2月4日火曜日

RDSの参照分散(3)

こんにちは!

今日はMySQL Proxyの設定について書きたいとおもいます。
まずは図のような構成をAWSに作りました。



その後にEC2 Instanceに次の手順でMySQL Proxyを入れてRDSに分散するように設定しました。

1. InstanceにSSHでログインして、rootになります。
2. yum install -y --enablerepo=epel mysql mysql-proxy

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2013.09-release-notes/
[ec2-user@standard ~]$ sudo su -
[root@standard ~]# yum install -y --enablerepo=epel mysql-proxy mysql
Loaded plugins: priorities, update-motd, upgrade-helper
epel/x86_64/metalink                                                                                                           | 3.9 kB     00:00     
epel/x86_64                                                                                                                    | 4.2 kB     00:00     
epel/x86_64/group_gz                                                                                                           | 237 kB     00:00     
epel/x86_64/updateinfo                                                                                                         | 761 kB     00:00     
epel/x86_64/primary_db                                                                                                         | 5.9 MB     00:04     
epel/x86_64/pkgtags                                                                                                            | 881 kB     00:01     
653 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package mysql.noarch 0:5.5-1.3.amzn1 will be installed
--> Processing Dependency: mysql55 >= 5.5 for package: mysql-5.5-1.3.amzn1.noarch
---> Package mysql-proxy.x86_64 0:0.8.2-1.el6 will be installed
--> Processing Dependency: libevent-1.4.so.2()(64bit) for package: mysql-proxy-0.8.2-1.el6.x86_64
--> Running transaction check
---> Package compat-libevent.x86_64 0:1.4.13-4.10.amzn1 will be installed
---> Package mysql55.x86_64 0:5.5.34-1.40.amzn1 will be installed
--> Processing Dependency: real-mysql55-common(x86-64) = 5.5.34-1.40.amzn1 for package: mysql55-5.5.34-1.40.amzn1.x86_64
--> Running transaction check
---> Package mysql55-common.x86_64 0:5.5.34-1.40.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
 Package                               Arch                         Version                                  Repository                          Size
======================================================================================================================================================
Installing:
 mysql                                 noarch                       5.5-1.3.amzn1                            amzn-main                          2.6 k
 mysql-proxy                           x86_64                       0.8.2-1.el6                              epel                               204 k
Installing for dependencies:
 compat-libevent                       x86_64                       1.4.13-4.10.amzn1                        amzn-main                          115 k
 mysql55                               x86_64                       5.5.34-1.40.amzn1                        amzn-updates                       7.5 M
 mysql55-common                        x86_64                       5.5.34-1.40.amzn1                        amzn-updates                        48 k

Transaction Summary
======================================================================================================================================================
Install  2 Packages (+3 Dependent packages)

Total download size: 7.9 M
Installed size: 29 M
Downloading packages:
(1/5): compat-libevent-1.4.13-4.10.amzn1.x86_64.rpm                                                                            | 115 kB     00:00     
(2/5): mysql-5.5-1.3.amzn1.noarch.rpm                                                                                          | 2.6 kB     00:00     
warning: /var/cache/yum/x86_64/latest/epel/packages/mysql-proxy-0.8.2-1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY:00 ETA 
Public key for mysql-proxy-0.8.2-1.el6.x86_64.rpm is not installed
(3/5): mysql-proxy-0.8.2-1.el6.x86_64.rpm                                                                                      | 204 kB     00:00     
(4/5): mysql55-5.5.34-1.40.amzn1.x86_64.rpm                                                                                    | 7.5 MB     00:00     
(5/5): mysql55-common-5.5.34-1.40.amzn1.x86_64.rpm                                                                             |  48 kB     00:00     
------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                 6.7 MB/s | 7.9 MB     00:01     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Importing GPG key 0x0608B895:
 Userid     : "EPEL (6) <epel@fedoraproject.org>"
 Fingerprint: 8c3b e96a f230 9184 da5c 0dae 3b49 df2a 0608 b895
 Package    : epel-release-6-8.9.amzn1.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : compat-libevent-1.4.13-4.10.amzn1.x86_64                                                                                           1/5 
  Installing : mysql55-common-5.5.34-1.40.amzn1.x86_64                                                                                            2/5 
  Installing : mysql55-5.5.34-1.40.amzn1.x86_64                                                                                                   3/5 
  Installing : mysql-5.5-1.3.amzn1.noarch                                                                                                         4/5 
  Installing : mysql-proxy-0.8.2-1.el6.x86_64                                                                                                     5/5 
  Verifying  : mysql55-common-5.5.34-1.40.amzn1.x86_64                                                                                            1/5 
  Verifying  : mysql-5.5-1.3.amzn1.noarch                                                                                                         2/5 
  Verifying  : mysql-proxy-0.8.2-1.el6.x86_64                                                                                                     3/5 
  Verifying  : compat-libevent-1.4.13-4.10.amzn1.x86_64                                                                                           4/5 
  Verifying  : mysql55-5.5.34-1.40.amzn1.x86_64                                                                                                   5/5 

Installed:
  mysql.noarch 0:5.5-1.3.amzn1                                            mysql-proxy.x86_64 0:0.8.2-1.el6                                           

Dependency Installed:
  compat-libevent.x86_64 0:1.4.13-4.10.amzn1          mysql55.x86_64 0:5.5.34-1.40.amzn1          mysql55-common.x86_64 0:5.5.34-1.40.amzn1         

Complete!

3. vi /etc/sysconfig/mysql-proxy で次のように追記しました。
# Options for mysql-proxy
ADMIN_USER="admin"
ADMIN_PASSWORD=""
ADMIN_LUA_SCRIPT="/usr/lib64/mysql-proxy/lua/admin.lua"
PROXY_USER="mysql-proxy"
PROXY_OPTIONS="--daemon --log-level=info --log-use-syslog --defaults-file=/etc/mysql-proxy.cnf"

4. vi /etc/mysql-proxy.cnf で次のように記述しました。
※最終行は実際には1行で書きます。RDSのendpointをカンマ区切りで記述します。
[mysql-proxy]
plugins=admin,proxy
admin-lua-script=/usr/lib64/mysql-proxy/lua/admin.lua
admin-username=admin
admin-password=admin
proxy-address=127.0.0.1:3306
proxy-backend-addresses=mysqlproxytest-master.ckj5g4ick5ri.ap-southeast-1.rds.amazonaws.com:3306,mysqlproxytest-slave1.ckj5g4ick5ri.ap-southeast-1.rds.amazonaws.com:3306,mysqlproxytest-slave2.ckj5g4ick5ri.ap-southeast-1.rds.amazonaws.com:3306

5. chmod 660 /etc/mysql-proxy.cnf で権限を変更します。※これをやらないとエラーが出ます。

6. vi /etc/init.d/mysql-proxy で起動スクリプトを一部改変します。※39行目
変更前)
daemon $prog $PROXY_OPTIONS --pid-file=$PROXY_PID --user=$PROXY_USER --admin-username="$ADMIN_USER" --admin-lua-script="$ADMIN_LUA_SCRIPT" --admin-password="$ADMIN_PASSWORD"

変更後)
daemon $prog $PROXY_OPTIONS --pid-file=$PROXY_PID --user=$PROXY_USER

7. /etc/init.d/mysql-proxy start  で起動します。

8. 下のようになればOKです。
# mysql -u admin -p -h 127.0.0.1 -P 4041
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.99-agent-admin

Copyright (c) 2000, 2013, 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 * from backends;
+-------------+-----------------+---------+------+------+-------------------+
| backend_ndx | address         | state   | type | uuid | connected_clients |
+-------------+-----------------+---------+------+------+-------------------+
|           1 | 10.0.0.73:3306  | unknown | rw   | NULL |                 0 |
|           2 | 10.0.0.169:3306 | unknown | rw   | NULL |                 0 |
|           3 | 10.0.1.188:3306 | unknown | rw   | NULL |                 0 |
+-------------+-----------------+---------+------+------+-------------------+
3 rows in set (0.00 sec)

mysql> exit
Bye

0 件のコメント:

コメントを投稿