Line 0
Link Here
|
|
|
1 |
--- proxysql-admin.orig 2017-08-15 14:06:53 UTC |
2 |
+++ proxysql-admin |
3 |
@@ -64,9 +64,9 @@ usage () { |
4 |
} |
5 |
|
6 |
# Check if we have a functional getopt(1) |
7 |
-if ! getopt --test |
8 |
+if ! /usr/local/bin/getopt --test |
9 |
then |
10 |
- go_out="$(getopt --options=edv --longoptions=config-file:,proxysql-username:,proxysql-password::,proxysql-hostname:,proxysql-port:,cluster-username:,cluster-password::,cluster-hostname:,cluster-port:,monitor-username:,monitor-password:,cluster-app-username:,cluster-app-password:,node-check-interval:,quick-demo,mode:,write-node:,enable,disable,adduser,syncusers,version,help \ |
11 |
+ go_out="$(/usr/local/bin/getopt --options=edv --longoptions=config-file:,proxysql-username:,proxysql-password::,proxysql-hostname:,proxysql-port:,cluster-username:,cluster-password::,cluster-hostname:,cluster-port:,monitor-username:,monitor-password:,cluster-app-username:,cluster-app-password:,node-check-interval:,quick-demo,mode:,write-node:,enable,disable,adduser,syncusers,version,help \ |
12 |
--name="$(basename "$0")" -- "$@")" |
13 |
test $? -eq 0 || exit 1 |
14 |
eval set -- "$go_out" |
15 |
@@ -80,12 +80,12 @@ fi |
16 |
if ! echo "$go_out" | grep -q 'config-file'; then |
17 |
if ! echo "$go_out" | grep -q 'quick-demo'; then |
18 |
# Reading default variables from default configuration file location. |
19 |
- if [ -e "/etc/proxysql-admin.cnf" ]; then |
20 |
- # Loading default configuration from /etc/proxysql-admin.cnf |
21 |
- source /etc/proxysql-admin.cnf |
22 |
- CONFIG_FILE="/etc/proxysql-admin.cnf" |
23 |
+ if [ -e "/usr/local/etc/proxysql-admin.cnf" ]; then |
24 |
+ # Loading default configuration from /usr/local/etc/proxysql-admin.cnf |
25 |
+ source /usr/local/etc/proxysql-admin.cnf |
26 |
+ CONFIG_FILE="/usr/local/etc/proxysql-admin.cnf" |
27 |
else |
28 |
- echo "WARNING! Default configuration file (/etc/proxysql-admin.cnf) does not exist" |
29 |
+ echo "WARNING! Default configuration file (/usr/local/etc/proxysql-admin.cnf) does not exist" |
30 |
fi |
31 |
fi |
32 |
fi |
33 |
@@ -362,13 +362,13 @@ if [ $MODE == "loadbal" ]; then |
34 |
WRITE_HOSTGROUP_ID=10 |
35 |
READ_HOSTGROUP_ID=10 |
36 |
if [ -e "${CONFIG_FILE}" ]; then |
37 |
- sudo sed -i "0,/^[ \t]*export MODE[ \t]*=.*$/s|^[ \t]*export MODE[ \t]*=.*$|export MODE=\"loadbal\"|" "${CONFIG_FILE}" |
38 |
+ sed -i "" "0,/^[ ]*export MODE[ ]*=.*$/s|^[ ]*export MODE[ ]*=.*$|export MODE=\"loadbal\"|" "${CONFIG_FILE}" |
39 |
fi |
40 |
elif [ $MODE == "singlewrite" ]; then |
41 |
WRITE_HOSTGROUP_ID=10 |
42 |
READ_HOSTGROUP_ID=11 |
43 |
if [ -e "${CONFIG_FILE}" ]; then |
44 |
- sudo sed -i "0,/^[ \t]*export MODE[ \t]*=.*$/s|^[ \t]*export MODE[ \t]*=.*$|export MODE=\"singlewrite\"|" "${CONFIG_FILE}" |
45 |
+ sed -i "" "0,/^[ ]*export MODE[ ]*=.*$/s|^[ ]*export MODE[ ]*=.*$|export MODE=\"singlewrite\"|" "${CONFIG_FILE}" |
46 |
fi |
47 |
fi |
48 |
|
49 |
@@ -413,7 +413,7 @@ check_cmd(){ |
50 |
|
51 |
check_proxysql(){ |
52 |
if ! pidof proxysql >/dev/null ; then |
53 |
- echo "ProxySQL is not running, please check the error log at /var/lib/proxysql/proxysql.log" |
54 |
+ echo "ProxySQL is not running, please check the error log at /var/log/proxysql.log" |
55 |
exit 1 |
56 |
fi |
57 |
} |
58 |
@@ -574,7 +574,7 @@ enable_proxysql(){ |
59 |
proxysql_exec "DELETE FROM mysql_query_rules WHERE destination_hostgroup in ($WRITE_HOSTGROUP_ID,$READ_HOSTGROUP_ID)" |
60 |
if [ -z "$QUICK_DEMO" ]; then |
61 |
if [ -z "$WRITE_NODE" ]; then |
62 |
- writer_ws_ip=$(mysql_exec "show variables like 'wsrep_provider_options'" | grep -o -P '(?<=base_host =).*(?=; base_port)' | xargs) |
63 |
+ writer_ws_ip=$(mysql_exec "show variables like 'wsrep_provider_options'" | sed -r 's/.*base_host =( [^ ]+);.*/\1/' | xargs) |
64 |
writer_ws_port=$CLUSTER_PORT |
65 |
else |
66 |
writer_ws_ip=$(echo "$WRITE_NODE" | awk -F':' '{print $1}') |
67 |
@@ -591,7 +591,7 @@ enable_proxysql(){ |
68 |
fi |
69 |
fi |
70 |
else |
71 |
- writer_ws_ip=$(mysql_exec "show variables like 'wsrep_provider_options'" | grep -o -P '(?<=base_host =).*(?=; base_port)' | xargs) |
72 |
+ writer_ws_ip=$(mysql_exec "show variables like 'wsrep_provider_options'" | sed -r 's/.*base_host =( [^ ]+);.*/\1/' | xargs) |
73 |
writer_ws_port=$CLUSTER_PORT |
74 |
fi |
75 |
proxysql_exec "DELETE FROM mysql_servers WHERE hostgroup_id=$WRITE_HOSTGROUP_ID" |
76 |
@@ -629,7 +629,7 @@ enable_proxysql(){ |
77 |
else |
78 |
NUMBER_WRITERS=0 |
79 |
fi |
80 |
- proxysql_exec "INSERT INTO SCHEDULER (id,active,interval_ms,filename,arg1,arg2,arg3,arg4,arg5) VALUES (10,1,$NODE_CHECK_INTERVAL,'$PROXYSQL_GALERA_CHECK',$WRITE_HOSTGROUP_ID,$READ_HOSTGROUP_ID,$NUMBER_WRITERS,1,'/var/lib/proxysql/proxysql_galera_check.log');" |
81 |
+ proxysql_exec "INSERT INTO SCHEDULER (id,active,interval_ms,filename,arg1,arg2,arg3,arg4,arg5) VALUES (10,1,$NODE_CHECK_INTERVAL,'$PROXYSQL_GALERA_CHECK',$WRITE_HOSTGROUP_ID,$READ_HOSTGROUP_ID,$NUMBER_WRITERS,1,'/var/log/proxysql_galera_check.log');" |
82 |
check_cmd $? "Failed to add the Percona XtraDB Cluster monitoring scheduler in ProxySQL. Please check username, password and other options for connecting to ProxySQL database" |
83 |
|
84 |
# Adding Percona XtraDB Cluster membership checking scheduler |
85 |
@@ -722,13 +722,13 @@ syncusers() { |
86 |
MYSQLVER=$(mysql_exec "SELECT VERSION();" | tail -1 | cut -d'.' -f1,2 ) |
87 |
|
88 |
case $MYSQLVER in |
89 |
- 5.6) |
90 |
- password_field="Password";; |
91 |
5.7) |
92 |
password_field="authentication_string";; |
93 |
+ *) |
94 |
+ password_field="Password";; |
95 |
esac |
96 |
- |
97 |
- mysql_users=$(mysql_exec "SELECT User,${password_field} FROM mysql.user where ${password_field}!=''" | sed 's/\t/,/g' | egrep -v "User,${password_field}|mysql.sys" | sort | uniq ) |
98 |
+ |
99 |
+ mysql_users=$(mysql_exec "SELECT User,${password_field} FROM mysql.user where ${password_field}!=''" | sed 's/ /,/g' | egrep -v "User,${password_field}|mysql.sys" | sort | uniq ) |
100 |
check_cmd $? "Failed to load user list from Percona XtraDB Cluster. Please check username, password and other options for connecting to Percona XtraDB Cluster" |
101 |
#Checking whether user is part of proxysql admin user list |
102 |
proxysql_admin_user_check(){ |
103 |
@@ -741,7 +741,7 @@ syncusers() { |
104 |
fi |
105 |
} |
106 |
# Get current ProxySQL users and filter out header row |
107 |
- proxysql_users=$(proxysql_exec "SELECT username,password FROM mysql_users where password!=''" | sed 's/\t/,/g' | egrep -v "username,password" | sort | uniq ) |
108 |
+ proxysql_users=$(proxysql_exec "SELECT username,password FROM mysql_users where password!=''" | sed 's/ /,/g' | egrep -v "username,password" | sort | uniq ) |
109 |
check_cmd $? "Failed to load user list from ProxySQL database. Please check username, password and other options for connecting to ProxySQL database" |
110 |
|
111 |
echo -e "\nSyncing user accounts from Percona XtraDB Cluster to ProxySQL" |
112 |
@@ -805,7 +805,7 @@ if [ "$ENABLE" == 1 ] || [ "$DISABLE" == |
113 |
echo -e "\nProxySQL read/write configuration mode is ${BD}$MODE${NBD}" |
114 |
enable_proxysql |
115 |
echo -e "\nProxySQL configuration completed!\n" |
116 |
- PROXYSQL_CLIENT_PORT=$(proxysql_exec "SELECT * FROM runtime_global_variables WHERE variable_name='mysql-interfaces'" | awk '{print $2}' | grep -o -P '(?<=:).*(?=;)') |
117 |
+ PROXYSQL_CLIENT_PORT=$(proxysql_exec "SELECT * FROM runtime_global_variables WHERE variable_name='mysql-interfaces'" | awk -F ':' '/:/ {print $NF}') |
118 |
echo -e "ProxySQL has been successfully configured to use with Percona XtraDB Cluster\n" |
119 |
echo -e "You can use the following login credentials to connect your application through ProxySQL\n" |
120 |
if [ -z "$QUICK_DEMO" ]; then |