Showing posts with label MySQL Proxy. Show all posts
Showing posts with label MySQL Proxy. Show all posts

Wednesday, May 23, 2018

Proxy MySQL :: HAproxy || ProxySQL & KeepAlived

So when it comes to routing your MySQL traffic several options exist.

Now I have seen HAproxy used more often with clients, it is pretty straight forward to set up. Percona has an example for those interested: 

Personally I like ProxySQL. Percona also has  few blogs on this as well
Percona also has ProxySQL version available 

I was thinking I would write up some examples but overall Percona has explained it all very well.  I do not want to take anything away from those posts, instead point out that a lot of good information is available via those urls. So instead of rewriting what has already been written, I will create a collection of information for those interested. 

First compare and decide for yourself what you need and want. The following link of course is going to be biased towards ProxySQL but it gives you an overall scope for you to consider. 
If you have a cluster or master to master and you do not care which server the writes vs reads go onto, just as long as you have a connection; then HAproxy is likely a simple fast set up for you. 

The bonus with ProxySQL is the ability to sort traffic in a weighted fashion, EASY. So you can have writes go to node 1, and selects pull from node 2 and node 3. Documentation on this can be found here:
Yes it can be done with HAproxy but you have to instruct the application accordingly. 
This is handled in ProxySQL based on your query rules.

Now the obvious question here: OK so how do you keep ProxySQL from becoming the single point of failure?  

You can invest is a robust load balancer and etc etc etc ... Toss hardware at it.... Or make it easy on yourself and support open source and use KeepAlived.  This is VERY easy to set up and all of it is documented again well here: 
If you ever dealt with lua and mysql-proxy, ProxySQL and Keepalived should be very simple for you. If you still want it for some reason: https://launchpad.net/mysql-proxy

Regardless if you choose HAproxy, ProxySQL or another solution, you need to ensure not to replace once single point of failure with another and keepalived is a great for that. So little reason to not do this if you are using a proxy. 

So a few more things on ProxySQL. 





Thursday, May 9, 2013

Setup MySQL Proxy

So this is just a very simple example of using MySQL Proxy ..

The MySQL Proxy has been in the Alpha stages for what feels like years on end.


MySQL Proxy Documentation :
Whatever is left from the MySQL forge site for MySQL Proxy WIKI can be found here: https://wikis.oracle.com/display/mysql/MySQL+Proxy

Install MySQL Proxy:
Download and unpack from dev.mysql.com. Current Alpha version is mysql-proxy 0.8.3.

Make sure you also have Lua installed

yum install lua-devel lua-static lua


You will then find mysql-proxy in the bin directory.


[root@localhost bin]# ./mysql-proxy --help
Usage:
  mysql-proxy [OPTION...] - MySQL Proxy


MySQL command options:

First need to make sure you are aware of the out of date documentation.

You might think that adding daemon=true to your configuration file is valid.
It does after all point out how true is the valid for the following option via the documentation.



For example, the following is invalid:

[mysql-proxy]
proxy-skip-profiling

But this is valid:

[mysql-proxy]
proxy-skip-profiling = true


http://dev.mysql.com/doc/refman/5.6/en/mysql-proxy-configuration.html#option_mysql-proxy_daemon

However daemon or daemon=true results with the following issue so use daemon=1

./bin/mysql-proxy --defaults-file=mysql_proxy.cnf
(critical) Key file contains key 'daemon' which has value that cannot be interpreted.


The same is true for keepalive=true


./bin/mysql-proxy --defaults-file=mysql_proxy.cnf
(critical) Key file contains key 'keepalive' which has value that cannot be interpreted.


Using the Administration Interface:

The admin.lua file is available under the mysql-proxy directory:
The reporter.lua file can also be placed into the  /lib/mysql-proxy/lua/ directory:


So I end up with the following configuration example


vi mysql_proxy.cnf

[mysql-proxy]

admin-address =127.0.0.1:3308

proxy-address=127.0.0.1:3307

proxy-skip-profiling = true

daemon=1
pid-file = /var/run/mysql-proxy.pid
log-file = /var/log/mysql-proxy.log
log-level = debug
proxy-backend-addresses=127.0.0.1:3306
#proxy-read-only-backend-addresses =127.0.0.1:3306
keepalive=1
admin-username=root
admin-password=secretpassword
admin-lua-script=/usr/local/src/MySQL/mysql-proxy/admin.lua
proxy-lua-script=/usr/local/src/MySQL/mysql-proxy/reporter.lua
plugin_dir=/usr/lib/mysql/plugin/
plugins=proxy,admin


This time it starts....


./bin/mysql-proxy --defaults-file=mysql_proxy.cnf


Tail you log to confirm that proxy is up and running then log into the admin port (3308)

(message) proxy listening on port 127.0.0.1:3307
# mysql -u root -p -P3308 -h127.0.0.1

Once you are logged in you can start to test it:

# mysql -u root -p -P3308 -h127.0.0.1

show querycounter;
+---------------+
| query_counter |
+---------------+
|          NULL |
+---------------+



SELECT * FROM backends;
+-------------+----------------+-------+------+
| backend_ndx | address        | state | type |
+-------------+----------------+-------+------+
|           1 | 127.0.0.1:3306 | 1     | 1    |
+-------------+----------------+-------+------+



> SHOW PROXY PROCESSLIST;
ERROR 1105 (07000): need a resultset + proxy.PROXY_SEND_RESULT ... got something else



Remember always check your logs...


(critical) (read_query) [string "/usr/local/src/MySQL/mysql-proxy/admin.lua"]:152: bad argument #1 to 'pairs' (table expected, got nil)


OK the MySQL Proxy is up...
Now the issues and complains over Lua and why is it part of MySQL-Proxy can begin...

http://lua.2524044.n2.nabble.com/Beginner-from-Python-starting-to-MySQL-Proxy-td7636807.html


FOLLOW UP:
http://anothermysqldba.blogspot.com/2018/05/proxy-mysql-haproxy-proxysql-keepalived.html