From ff948cc52dbc4de674ec011419d80462ca348dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 6 Sep 2015 00:29:14 +0000 Subject: [PATCH] Added default config file , init script Also implemented make install and make uninstall --- Makefile | 16 +++++ etc/init.d/proxysql | 115 +++++++++++++++++++++++++++++++++++ etc/proxysql.cnf | 143 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 274 insertions(+) create mode 100755 etc/init.d/proxysql create mode 100644 etc/proxysql.cnf diff --git a/Makefile b/Makefile index 0626a0502..056246f63 100644 --- a/Makefile +++ b/Makefile @@ -46,3 +46,19 @@ cleanall: cd deps && make cleanall cd lib && make clean cd src && make clean + +install: src/proxysql + install -m 0755 src/proxysql /usr/local/bin + install -m 0600 etc/proxysql.cnf /etc + install -m 0755 etc/init.d/proxysql /etc/init.d + if [ ! -d /var/run/proxysql ]; then mkdir /var/run/proxysql ; fi + update-rc.d proxysql defaults +.PHONY: install + +uninstall: + rm /etc/init.d/proxysql + rm /etc/proxysql.cnf + rm /usr/local/bin/proxysql + rmdir /var/run/proxysql 2>/dev/null || true + update-rc.d proxysql remove +.PHONY: uninstall diff --git a/etc/init.d/proxysql b/etc/init.d/proxysql new file mode 100755 index 000000000..1397d92ad --- /dev/null +++ b/etc/init.d/proxysql @@ -0,0 +1,115 @@ +#!/bin/bash +# +# Provides : proxysql +# Required-Start : $local_fs +# Required-Stop : $local_fs +# Default-Start : 2 3 4 5 +# Default-Stop : 0 1 6 +# Short-Description : High Performance Advanced Proxy for MySQL +# Description : High Performance and Advanced Proxy for MySQL and forks. +# It provides advanced features like connection pool, query routing and rewrite, +# firewalling, throttling, real time analysis, error-free failover + +DATADIR="/var/run/proxysql" +OPTS="-c /etc/proxysql.cnf -D $DATADIR" +PIDFILE="$DATADIR/proxysql.pid" + +getpid() { + if [ -f $PIDFILE ] + then + if [ -r $PIDFILE ] + then + pid=`cat $PIDFILE` + if [ "X$pid" != "X" ] + then + # Verify that a process with this pid is still running. + pid=`ps -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` + if [ "X$pid" = "X" ] + then + # This is a stale pid file. + rm -f $PIDFILE + echo "Removed stale pid file: $PIDFILE" + fi + fi + else + echo "Cannot read $PIDFILE." + exit 1 + fi + fi +} + + +initial() { + OPTS="--initial $OPTS" + start +} + +start() { + echo -n "Starting ProxySQL: " + mkdir $DATADIR 2>/dev/null + getpid + if [ "X$pid" = "X" ] + then + proxysql $OPTS + if [ "$?" = "0" ]; then + echo "DONE!" + return 0 + else + echo "FAILED!" + return 1 + fi + else + echo "ProxySQL is already running." + exit 1 + fi +} + +stop() { + echo -n "Shutting down ProxySQL: " + getpid + if [ "X$pid" = "X" ] + then + echo "ProxySQL was not running." + exit 1 + else + killall proxysql + exit 0 + fi +} + +status() { + getpid + if [ "X$pid" = "X" ] + then + echo "ProxySQL is not running." + exit 1 + else + echo "ProxySQL is running ($pid)." + exit 0 + fi +} + +case "$1" in + start) + start + ;; + initial) + initial + ;; + stop) + stop + ;; + status) + status + ;; + restart) + stop + start + ;; + *) + echo "Usage: ProxySQL {start|stop|status|restart}" + exit 1 + ;; +esac +exit $? + diff --git a/etc/proxysql.cnf b/etc/proxysql.cnf new file mode 100644 index 000000000..2acc58566 --- /dev/null +++ b/etc/proxysql.cnf @@ -0,0 +1,143 @@ +#file proxysql.cfg + +# This config file is parsed using libconfig , and its grammar is described in: +# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-File-Grammar +# Grammar is also copied at the end of this file + + + +datadir="/var/run/proxysql" + +admin_variables= +{ + admin_credentials="admin:admin" + mysql_ifaces="127.0.0.1:6032;/tmp/proxysql_admin.sock" + refresh_interval=2000 + debug=true +} + +mysql_variables= +{ + threads=4 + max_connections=2048 + default_query_delay=0 + default_query_timeout=10000 + have_compress=true + poll_timeout=2000 + interfaces="0.0.0.0:6033;/tmp/proxysql.sock" + default_schema="information_schema" + stacksize=1048576 + server_version="5.1.30" + connect_timeout_server=10000 + connect_timeout_server_error="#2003:Can't connect to MySQL server" + monitor_history=60000 + monitor_connect_interval=200000 + monitor_ping_interval=200000 + ping_interval_server=10000 + ping_timeout_server=200 + commands_stats=true + sessions_sort=true +} + + +# defines all the MySQL servers +mysql_servers = +( +# { +# address = "127.0.0.1" # no default, required . If port is 0 , address is interpred as a Unix Socket Domain +# port = 3306 # no default, required . If port is 0 , address is interpred as a Unix Socket Domain +# hostgroup = 0 # no default, required +# status = "ONLINE" # default: ONLINE +# weight = 1 # default: 1 +# compression = 0 # default: 0 +# max_replication_lag = 10 # default 0 . If greater than 0 and replication lag passes such threshold, the server is shunned +# }, +# { +# address = "/var/lib/mysql/mysql.sock" +# port = 0 +# hostgroup = 0 +# }, +# { +# address="127.0.0.1" +# port=21891 +# hostgroup=0 +# max_connections=200 +# }, +# { address="127.0.0.2" , port=3306 , hostgroup=0, max_connections=5 }, +# { address="127.0.0.1" , port=21892 , hostgroup=1 }, +# { address="127.0.0.1" , port=21893 , hostgroup=1 } +# { address="127.0.0.2" , port=3306 , hostgroup=1 }, +# { address="127.0.0.3" , port=3306 , hostgroup=1 }, +# { address="127.0.0.4" , port=3306 , hostgroup=1 }, +# { address="/var/lib/mysql/mysql.sock" , port=0 , hostgroup=1 } +) + + +# defines all the MySQL users +mysql_users: +( +# { +# username = "username" # no default , required +# password = "password" # default: '' +# default_hostgroup = 0 # default: 0 +# active = 1 # default: 1 +# }, +# { +# username = "root" +# password = "" +# default_hostgroup = 0 +# max_connections=1000 +# default_schema="test" +# active = 1 +# }, +# { username = "user1" , password = "password" , default_hostgroup = 0 , active = 0 } +) + + + +#defines MySQL Query Rules +mysql_query_rules: +( +# { +# rule_id=1 +# active=1 +# match_pattern="^SELECT .* FOR UPDATE$" +# destination_hostgroup=0 +# apply=1 +# }, +# { +# rule_id=2 +# active=1 +# match_pattern="^SELECT" +# destination_hostgroup=1 +# apply=1 +# } +) + + +# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-File-Grammar +# +# Below is the BNF grammar for configuration files. Comments and include directives are not part of the grammar, so they are not included here. +# +# configuration = setting-list | empty +# +# setting-list = setting | setting-list setting +# +# setting = name (":" | "=") value (";" | "," | empty) +# +# value = scalar-value | array | list | group +# +# value-list = value | value-list "," value +# +# scalar-value = boolean | integer | integer64 | hex | hex64 | float +# | string +# +# scalar-value-list = scalar-value | scalar-value-list "," scalar-value +# +# array = "[" (scalar-value-list | empty) "]" +# +# list = "(" (value-list | empty) ")" +# +# group = "{" (setting-list | empty) "}" +# +# empty =