i am trying to setup mysql-proxy on ubuntu on amazon ec2 i have done following:
我正在尝试在amazon ec2上安装mysql-proxy,如下所示:
sudo apt-get install mysql-proxy --yes
vi /etc/default/mysql-proxy
i put following content on "/etc/default/mysql-proxy"
我把下面的内容放在"/etc/default/mysql-proxy"上
ENABLED="true"
OPTIONS="--proxy-lua-script=/usr/share/mysql-proxy/rw-splitting.lua
--proxy-address=127.0.0.1:3306
--proxy-backend-addresses=private_ip_of_another_ec2_db_server:3306,private_ip_of_another_ec2_db_server:3306"
also tied with "--proxy-address=private_ip_or_public_ip_of_proxy-server:3306 or 4040" and "--proxy-backend-addresses=public_ip_of_another_ec2_db_server:3306,public_ip_of_another_ec2_db_server:3306"
还与“-proxy-address= private_ip_or_public_of_proxy -server:3306或4040”和“-proxy-backend-address =public_ip_of_another_ec2_db_server:3306,public_ip_of_another_ec2_db_server:3306”绑定。
after that i tried to connect proxy server from another pc using mysql like:
之后我尝试使用mysql连接其他pc的代理服务器,比如:
mysql -u some_user -pxxxxx -h proxy_server_ip
or
mysql -u some_user -pxxxxx -h proxy_server_ip -P 4040
but its not working its showing error:
但它没有发挥其显示的错误:
ERROR 2003 (HY000): Can't connect to MySQL server on 'ip' (10061)
i want to tell you can connect the db server remotely where i allowed remote connection to any host
我想告诉您可以远程连接db服务器,我允许远程连接到任何主机
i also tried /etc/init.d/mysql-proxy start or /etc/init.d/mysql-proxy restart but no result
我也试过/etc/init.d / mysql-proxy启动或/etc/init.d/mysql代理重新启动,但没有结果
just to inform you that /etc/init.d/mysql-proxy stop is showing failed
告诉你们/etc/ initit。d/mysql-proxy stop显示失败。
can anyone please help me to setup and configure mysql-proxy on ubuntu
谁能帮我在ubuntu上设置和配置mysql代理吗
===
= = =
Edit
i found some help from other question of * and also according to a suggestion in the comments, have done following procedure. and it seems its working now.
我从*的其他问题中得到了一些帮助,也根据评论中的建议,做了以下步骤。现在看来,它正在发挥作用。
i installed mysql-client and mysql-server locally(on proxy server) then i tried to run mysql-proxy using following command:
我在本地安装了mysql-client和mysql-server(在代理服务器上),然后尝试使用以下命令运行mysql-proxy:
mysql-proxy --proxy-backend-addresses=10.73.151.244:3306 --proxy-backend-addresses=10.73.198.7:3306 --proxy-address=:4040 --admin-username=root --admin-password=root --admin-lua-script=>/usr/lib/mysql-proxy/lua/admin.lua
then i tried to connect remotely to the proxy server and its working. but it seems i need to run this command under screen because when i close the terminal proxy stops working.
然后我尝试远程连接到代理服务器和它的工作。但是我似乎需要在屏幕下运行这个命令,因为当我关闭终端代理时,它将停止工作。
Can you please tell me that do i need to run this command under screen or is there any other way to make it alive all time?
你能告诉我我需要在屏幕下运行这个命令吗?还是有其他的方法让它一直保持活跃?
2 个解决方案
#1
2
There is no need to install Mysql client or Mysql Server on your mysql-proxy.
不需要在Mysql -proxy上安装Mysql客户机或Mysql服务器。
Installing mysql-proxy does have "full daemon capabilities" compiled into it.
安装mysql-proxy确实具有“完整的守护进程功能”。
If your are running Ubuntu Server, you may wish to use an UPSTART service script.
如果您正在运行Ubuntu服务器,您可能希望使用一个暴发户服务脚本。
This script can be copied into /etc/init/mysql-proxy.conf
可以将该脚本复制到/etc/init/mysql-proxy.conf中
# mysql-proxy.conf (Ubuntu 14.04.1) Upstart proxy configuration file for AWS RDS
# mysql-proxy - mysql-proxy job file
description "mysql-proxy upstart script"
author "shadowbq <shadowbq@gmail.com>"
# Stanzas
#
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn
# When to start the service
start on runlevel [2345]
# When to stop the service
stop on runlevel [016]
# Automatically restart process if crashed
respawn
# Essentially lets upstart know the process will detach itself to the background
expect daemon
# Run before process
pre-start script
[ -d /var/run/mysql-proxy ] || mkdir -p /var/run/mysql-proxy
echo "starting mysql-proxy"
end script
# Start the process
exec /usr/bin/mysql-proxy --plugins=proxy --proxy-lua-script=/usr/share/mysql-proxy/rw-splitting.lua --log-level=debug --proxy-backend-addresses=private_ip_of_another_ec2_db_server:3306,private_ip_of_another_ec2_db_server:3306 --daemon --log-use-syslog --pid-file=/var/run/mysql-proxy/mysql-proxy.pid
In the above example I hard coded the AWS RDS server into script, instead of fiddling with defaults and config file
在上面的示例中,我将AWS RDS服务器硬编码到脚本中,而不是修改默认值和配置文件
#2
1
Install Upgraded version 0.8.5
安装升级版本0.8.5
Note:
注意:
apt repo does not have 0.8.5 so we need to download tar from mysql official site
apt repo没有0.8.5,所以我们需要从mysql官方站点下载tar。
Prerequisite :-
先决条件:-
Create file /etc/default/mysql-proxy
with following content ENABLED="true" OPTIONS="--defaults-file=/etc/mysql/mysql-proxy.cnf"
创建文件/etc/default/mysql-proxy,其内容为:"true" OPTIONS="——defaults-file=/etc/mysql/mysql-proxy.cnf"
Installation Procedure :-
安装过程:
- Download mysql-proxy 0.8.x
- 下载mysql-proxy 0.8.x
- Untar in /usr/local
- 将在/usr/local解压
-
Update PATH environment with /usr/local/mysql-proxy-0.8.5-linux-debian6.0-x86-64bit/bin
vim /etc/environment (to update environment path) cd /usr/local/mysql-proxy-0.8.5-linux-debian6.0-x86-64bit/bin
使用/usr/local/ sql-proxy-0.8.5-linux-debian6.0-x86-64bit/bin vim /etc/environment(更新环境路径)更新路径环境
-
Run command sudo ./mysql-proxy --defaults-file=/etc/mysql/mysql-proxy.cnf
运行命令sudo ./mysql-proxy——defaults-file=/etc/mysql/mysql-proxy.cnf
Sample mysql-proxy.cnf file
mysql-proxy.cnf文件示例
[mysql-proxy]
log-level=debug
log-file=/var/log/mysql-proxy.log
pid-file = /var/run/mysql-proxy.pid
daemon = true
--no-proxy = false
admin-username=ADMIN
admin-password=ADMIN
proxy-backend-addresses=RDS-ENDPOINT:RDS-PORT
admin-lua-script=/usr/lib/mysql-proxy/lua/admin.lua
proxy-address=0.0.0.0:4040
admin-address=localhost:4041
-
change host ip and port of RDS or mysql
更改主机ip和RDS或mysql端口。
-
connect to Mysql server via proxy with
通过代理连接到Mysql服务器
mysql -h{proxy-host-ip} -P 4040 -u{mysql_username} -p
mysql -h{代理-主机-ip} -P 4040 -u{mysql_username} -P
#1
2
There is no need to install Mysql client or Mysql Server on your mysql-proxy.
不需要在Mysql -proxy上安装Mysql客户机或Mysql服务器。
Installing mysql-proxy does have "full daemon capabilities" compiled into it.
安装mysql-proxy确实具有“完整的守护进程功能”。
If your are running Ubuntu Server, you may wish to use an UPSTART service script.
如果您正在运行Ubuntu服务器,您可能希望使用一个暴发户服务脚本。
This script can be copied into /etc/init/mysql-proxy.conf
可以将该脚本复制到/etc/init/mysql-proxy.conf中
# mysql-proxy.conf (Ubuntu 14.04.1) Upstart proxy configuration file for AWS RDS
# mysql-proxy - mysql-proxy job file
description "mysql-proxy upstart script"
author "shadowbq <shadowbq@gmail.com>"
# Stanzas
#
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn
# When to start the service
start on runlevel [2345]
# When to stop the service
stop on runlevel [016]
# Automatically restart process if crashed
respawn
# Essentially lets upstart know the process will detach itself to the background
expect daemon
# Run before process
pre-start script
[ -d /var/run/mysql-proxy ] || mkdir -p /var/run/mysql-proxy
echo "starting mysql-proxy"
end script
# Start the process
exec /usr/bin/mysql-proxy --plugins=proxy --proxy-lua-script=/usr/share/mysql-proxy/rw-splitting.lua --log-level=debug --proxy-backend-addresses=private_ip_of_another_ec2_db_server:3306,private_ip_of_another_ec2_db_server:3306 --daemon --log-use-syslog --pid-file=/var/run/mysql-proxy/mysql-proxy.pid
In the above example I hard coded the AWS RDS server into script, instead of fiddling with defaults and config file
在上面的示例中,我将AWS RDS服务器硬编码到脚本中,而不是修改默认值和配置文件
#2
1
Install Upgraded version 0.8.5
安装升级版本0.8.5
Note:
注意:
apt repo does not have 0.8.5 so we need to download tar from mysql official site
apt repo没有0.8.5,所以我们需要从mysql官方站点下载tar。
Prerequisite :-
先决条件:-
Create file /etc/default/mysql-proxy
with following content ENABLED="true" OPTIONS="--defaults-file=/etc/mysql/mysql-proxy.cnf"
创建文件/etc/default/mysql-proxy,其内容为:"true" OPTIONS="——defaults-file=/etc/mysql/mysql-proxy.cnf"
Installation Procedure :-
安装过程:
- Download mysql-proxy 0.8.x
- 下载mysql-proxy 0.8.x
- Untar in /usr/local
- 将在/usr/local解压
-
Update PATH environment with /usr/local/mysql-proxy-0.8.5-linux-debian6.0-x86-64bit/bin
vim /etc/environment (to update environment path) cd /usr/local/mysql-proxy-0.8.5-linux-debian6.0-x86-64bit/bin
使用/usr/local/ sql-proxy-0.8.5-linux-debian6.0-x86-64bit/bin vim /etc/environment(更新环境路径)更新路径环境
-
Run command sudo ./mysql-proxy --defaults-file=/etc/mysql/mysql-proxy.cnf
运行命令sudo ./mysql-proxy——defaults-file=/etc/mysql/mysql-proxy.cnf
Sample mysql-proxy.cnf file
mysql-proxy.cnf文件示例
[mysql-proxy]
log-level=debug
log-file=/var/log/mysql-proxy.log
pid-file = /var/run/mysql-proxy.pid
daemon = true
--no-proxy = false
admin-username=ADMIN
admin-password=ADMIN
proxy-backend-addresses=RDS-ENDPOINT:RDS-PORT
admin-lua-script=/usr/lib/mysql-proxy/lua/admin.lua
proxy-address=0.0.0.0:4040
admin-address=localhost:4041
-
change host ip and port of RDS or mysql
更改主机ip和RDS或mysql端口。
-
connect to Mysql server via proxy with
通过代理连接到Mysql服务器
mysql -h{proxy-host-ip} -P 4040 -u{mysql_username} -p
mysql -h{代理-主机-ip} -P 4040 -u{mysql_username} -P