Commit 83fabe53 authored by Alain Takoudjou's avatar Alain Takoudjou

repman: allow to connect to proxysql with IPv6 and publish v6 cluster_database_list parameters

parent f9bd4d13
...@@ -18,7 +18,7 @@ md5sum = b41f521b5f7980c64260ed0e5c494450 ...@@ -18,7 +18,7 @@ md5sum = b41f521b5f7980c64260ed0e5c494450
[instance-repman.cfg] [instance-repman.cfg]
_update_hash_filename_ = instance-repman.cfg.jinja2.in _update_hash_filename_ = instance-repman.cfg.jinja2.in
md5sum = 7f486e429f8c2e95d28d79748a0122d1 md5sum = 7dbaace0d7db0e26d582ad17f36ac9cd
[config-toml.in] [config-toml.in]
_update_hash_filename_ = templates/config.toml.in _update_hash_filename_ = templates/config.toml.in
...@@ -26,7 +26,7 @@ md5sum = 5cfa75ca5a0048a050c0041dfe541f3d ...@@ -26,7 +26,7 @@ md5sum = 5cfa75ca5a0048a050c0041dfe541f3d
[config-cluster-toml.in] [config-cluster-toml.in]
_update_hash_filename_ = templates/cluster-config.toml.in _update_hash_filename_ = templates/cluster-config.toml.in
md5sum = 9be37f86d0fad81cc13e64c5a0557c59 md5sum = d2e79a9435082d9420281b4f59a5d464
[nginx.conf.in] [nginx.conf.in]
_update_hash_filename_ = templates/nginx.conf.in _update_hash_filename_ = templates/nginx.conf.in
...@@ -34,7 +34,7 @@ md5sum = 0eeb24c6aa0760f0d33c4cc2828ddf30 ...@@ -34,7 +34,7 @@ md5sum = 0eeb24c6aa0760f0d33c4cc2828ddf30
[template-mariadb.cfg] [template-mariadb.cfg]
_update_hash_filename_ = instance-mariadb.cfg.jinja2.in _update_hash_filename_ = instance-mariadb.cfg.jinja2.in
md5sum = b750f9ea573128a77ee6292048392844 md5sum = 189ccee60d0fb53e29431a45e0816bc1
[template-my-cnf] [template-my-cnf]
_update_hash_filename_ = templates/my.cnf.in _update_hash_filename_ = templates/my.cnf.in
...@@ -46,15 +46,15 @@ md5sum = 9be53e2e92333b93e92556b8a01d9c42 ...@@ -46,15 +46,15 @@ md5sum = 9be53e2e92333b93e92556b8a01d9c42
[mariadb-init-root-sql] [mariadb-init-root-sql]
_update_hash_filename_ = templates/mariadb_init_root.sql.in _update_hash_filename_ = templates/mariadb_init_root.sql.in
md5sum = 864d419ea506c9ac543409ba7abb22b0 md5sum = d927b5d36410bb02717d5ca125525785
[init-root-wrapper-in] [init-root-wrapper-in]
_update_hash_filename_ = templates/init_root_wrapper.in _update_hash_filename_ = templates/init_root_wrapper.in
md5sum = 49c328bd61eea74d9fb009f6f1561eaf md5sum = 83ef59b5afaf4454d368823c33aef9cb
[repman-manager-sh.in] [repman-manager-sh.in]
_update_hash_filename_ = templates/repman-manager.sh.in _update_hash_filename_ = templates/repman-manager.sh.in
md5sum = 94b14f5f5cf87bd9fb3aaa8d12a199b4 md5sum = 50503bec392e31126328f51eadc11634
[dbjobs-in] [dbjobs-in]
_update_hash_filename_ = templates/dbjobs.in _update_hash_filename_ = templates/dbjobs.in
......
...@@ -88,6 +88,7 @@ password = {{ slapparameter_dict['root-password'] }} ...@@ -88,6 +88,7 @@ password = {{ slapparameter_dict['root-password'] }}
database-list = {{ dumps(database_list) }} database-list = {{ dumps(database_list) }}
mroonga-mariadb-install-sql = {{ dumps(parameter_dict['mroonga-mariadb-install-sql']) }} mroonga-mariadb-install-sql = {{ dumps(parameter_dict['mroonga-mariadb-install-sql']) }}
root-user = repman root-user = repman
heartbeat-user = {{ slapparameter_dict['heartbeat-user'] }}
[init-script] [init-script]
< = jinja2-template-executable < = jinja2-template-executable
...@@ -147,7 +148,9 @@ wrapper = ${directory:controller}/mariadb ...@@ -147,7 +148,9 @@ wrapper = ${directory:controller}/mariadb
{{ supervisord_lib.supervisord("mariadb-ctl", buildout_bin_directory, supervisord_conf, use_service_hash=False) }} {{ supervisord_lib.supervisord("mariadb-ctl", buildout_bin_directory, supervisord_conf, use_service_hash=False) }}
{% do part_list.append("supervisord-mariadb-ctl") -%} {% do part_list.append("supervisord-mariadb-ctl") -%}
{% set maradb_program_dict = {"name": "mariadb", "command": "${ca-mysqld:wrapper}", {% set maradb_program_dict = {"name": "mariadb", "command": "${ca-mysqld:wrapper}",
"stopwaitsecs": 86400, "environment": []} %} "stopwaitsecs": 86400, "environment": [],
"stdout_logfile": "${directory:log}/mariadb_stdout.log",
"stderr_logfile": "${directory:log}/mariadb_stdout.log" } %}
{{ supervisord_lib.supervisord_program("mariadb", maradb_program_dict) }} {{ supervisord_lib.supervisord_program("mariadb", maradb_program_dict) }}
{% do part_list.append("supervisord-mariadb") %} {% do part_list.append("supervisord-mariadb") %}
......
...@@ -90,6 +90,7 @@ config-{{ key }} = {{ dumps(value) }} ...@@ -90,6 +90,7 @@ config-{{ key }} = {{ dumps(value) }}
config-monitor-passwd = ${publish-early:monitor-password} config-monitor-passwd = ${publish-early:monitor-password}
config-root-password = ${publish-early:db-root-password} config-root-password = ${publish-early:db-root-password}
config-repman-user = ${repman-parameter:username} config-repman-user = ${repman-parameter:username}
config-heartbeat-user = ${repman-parameter:heartbeat-user}
#config-repman-passwd = ${repman-parameter:password} #config-repman-passwd = ${repman-parameter:password}
config-repman-url = ${nginx-parameter:backend-url} config-repman-url = ${nginx-parameter:backend-url}
config-repman-secure-url = ${nginx-parameter:backend-ssl-url} config-repman-secure-url = ${nginx-parameter:backend-ssl-url}
...@@ -126,13 +127,17 @@ maximum = 7132 ...@@ -126,13 +127,17 @@ maximum = 7132
{% set prefered_master = parameter_dict.get("db-prefered-master") -%} {% set prefered_master = parameter_dict.get("db-prefered-master") -%}
[{{ name ~ '-cluster-parameter' }}] [{{ name ~ '-cluster-parameter' }}]
{% for key, value in parameter_dict.items() -%} {% for key, value in parameter_dict.items() -%}
{{ key }} = {{ dumps(value) }} {{ key }} = {{ value }}
{% endfor -%} {% endfor -%}
proxysql-user = {{ parameter_dict.get("proxysql-user", "external") }} proxysql-user = {{ parameter_dict.get("proxysql-user", "external") }}
proxy-port = {{ '${' ~ name ~ '-port:port}' }} proxy-port = {{ '${' ~ name ~ '-port:port}' }}
proxy-admin-port = {{ '${' ~ name ~ '-admin-port:port}' }} proxy-admin-port = {{ '${' ~ name ~ '-admin-port:port}' }}
db-credential = repman:${publish-early:db-root-password} db-user = repman
db-password = ${publish-early:db-root-password}
db-list = {{ mariadb_server_list | join(',') }} db-list = {{ mariadb_server_list | join(',') }}
heartbeat-user = ${repman-parameter:heartbeat-user}
heartbeat-password = ${publish-early:db-root-password}
partition-list = {{ mariadb_path_list | join(',') }} partition-list = {{ mariadb_path_list | join(',') }}
{% if prefered_master -%} {% if prefered_master -%}
db-prefered-master = {{ prefered_master }} db-prefered-master = {{ prefered_master }}
...@@ -141,6 +146,7 @@ db-prefered-master = {{ prefered_master }} ...@@ -141,6 +146,7 @@ db-prefered-master = {{ prefered_master }}
db-prefered-master = {{ mariadb_server_list[0] }} db-prefered-master = {{ mariadb_server_list[0] }}
{% endif -%} {% endif -%}
proxysql-servers = {{ ipv4 }} proxysql-servers = {{ ipv4 }}
proxysql-servers-ipv6 = [{{ ip }}]
password = ${repman-parameter:password} password = ${repman-parameter:password}
proxysql-partition = ${buildout:directory} proxysql-partition = ${buildout:directory}
receiver-port-list = {{ receiver_port_list | join(',') }} receiver-port-list = {{ receiver_port_list | join(',') }}
...@@ -205,21 +211,29 @@ wait-for-files = ...@@ -205,21 +211,29 @@ wait-for-files =
depends = depends =
{{ '${proxysql-' ~ name ~ '-admin-promise:recipe}' }} {{ '${proxysql-' ~ name ~ '-admin-promise:recipe}' }}
{{ '${proxysql-' ~ name ~ '-promise:recipe}' }} {{ '${proxysql-' ~ name ~ '-promise:recipe}' }}
{{ '${proxysql-' ~ name ~ '-ipv6-promise:recipe}' }}
[proxysql-{{ name }}-admin-promise] [proxysql-{{ name }}-admin-promise]
<= monitor-promise-base <= monitor-promise-base
module = check_port_listening module = check_port_listening
name = proxysql-{{ name }}-admin-port-listening name = proxysql-{{ name }}-admin-port-listening.py
config-hostname= {{ ipv4 }} config-hostname= {{ ipv4 }}
config-port = {{ '${' ~ name ~ '-cluster-parameter:proxy-admin-port}' }} config-port = {{ '${' ~ name ~ '-cluster-parameter:proxy-admin-port}' }}
[proxysql-{{ name }}-promise] [proxysql-{{ name }}-promise]
<= monitor-promise-base <= monitor-promise-base
module = check_port_listening module = check_port_listening
name = proxysql-{{ name }}-port-listening name = proxysql-{{ name }}-port-listening.py
config-hostname= {{ ipv4 }} config-hostname= {{ ipv4 }}
config-port = {{ '${' ~ name ~ '-cluster-parameter:proxy-port}' }} config-port = {{ '${' ~ name ~ '-cluster-parameter:proxy-port}' }}
[proxysql-{{ name }}-ipv6-promise]
<= monitor-promise-base
module = check_port_listening
name = proxysql-{{ name }}-ipv6-port-listening.py
config-hostname= {{ ip }}
config-port = {{ '${' ~ name ~ '-cluster-parameter:proxy-port}' }}
{% set service_name = "proxysql-" ~ name -%} {% set service_name = "proxysql-" ~ name -%}
{% set proxysql_dict = {"name": service_name, "command": "${" ~ service_name ~ "-wrapper:wrapper-path}", {% set proxysql_dict = {"name": service_name, "command": "${" ~ service_name ~ "-wrapper:wrapper-path}",
"stopwaitsecs": 60, "environment": [], "stopwaitsecs": 60, "environment": [],
...@@ -233,15 +247,19 @@ config-port = {{ '${' ~ name ~ '-cluster-parameter:proxy-port}' }} ...@@ -233,15 +247,19 @@ config-port = {{ '${' ~ name ~ '-cluster-parameter:proxy-port}' }}
{% do cluster_list.append("{'name': '" ~ name ~ "', 'host': '" ~ ipv4 ~ "', 'port': '${" ~ name ~ "-cluster-parameter:proxy-admin-port}'}") -%} {% do cluster_list.append("{'name': '" ~ name ~ "', 'host': '" ~ ipv4 ~ "', 'port': '${" ~ name ~ "-cluster-parameter:proxy-admin-port}'}") -%}
{% set publish_database_list = [] -%} {% set publish_database_list = [] -%}
{% set publish_database_v6_list = [] -%}
{% for database in database_list -%} {% for database in database_list -%}
{% if database.get('user') -%} {% if database.get('user') -%}
{% do publish_database_list.append("mysql://" ~ database['user'] ~ ":" ~ database['password'] ~ "@" ~ ipv4 ~ ":${" ~ name ~ "-cluster-parameter:proxy-port}/" ~ database['name']) -%} {% do publish_database_list.append("mysql://" ~ database['user'] ~ ":" ~ database['password'] ~ "@" ~ ipv4 ~ ":${" ~ name ~ "-cluster-parameter:proxy-port}/" ~ database['name']) -%}
{% do publish_database_v6_list.append("mysql://" ~ database['user'] ~ ":" ~ database['password'] ~ "@[" ~ ip ~ "]:${" ~ name ~ "-cluster-parameter:proxy-port}/" ~ database['name']) -%}
{% else -%} {% else -%}
{% do publish_database_list.append("mysql://" ~ ipv4 ~ ":${" ~ name ~ "-cluster-parameter:proxy-port}/" ~ database['name']) -%} {% do publish_database_list.append("mysql://" ~ ipv4 ~ ":${" ~ name ~ "-cluster-parameter:proxy-port}/" ~ database['name']) -%}
{% do publish_database_v6_list.append("mysql://[" ~ ip ~ "]:${" ~ name ~ "-cluster-parameter:proxy-port}/" ~ database['name']) -%}
{% endif -%} {% endif -%}
{% endfor -%} {% endfor -%}
{% do publish_dict.__setitem__(name ~ '-database-list', "!py!['" ~ publish_database_list | join("', '") ~ "']") -%} {% do publish_dict.__setitem__(name ~ '-database-list', "!py!['" ~ publish_database_list | join("', '") ~ "']") -%}
{% do publish_dict.__setitem__(name ~ '-database-list-v6', "!py!['" ~ publish_database_v6_list | join("', '") ~ "']") -%}
{% endfor -%} {% endfor -%}
[slap-configuration] [slap-configuration]
...@@ -304,6 +322,7 @@ secure-port = ${instance-parameter:repman-secure-port} ...@@ -304,6 +322,7 @@ secure-port = ${instance-parameter:repman-secure-port}
port = ${instance-parameter:repman-port} port = ${instance-parameter:repman-port}
ipv4 = ${instance-parameter:ipv4-random} ipv4 = ${instance-parameter:ipv4-random}
username = admin username = admin
heartbeat-user = heartbeat
password = ${publish-early:repman-password} password = ${publish-early:repman-password}
cluster-d = ${repman:clusters} cluster-d = ${repman:clusters}
autorejoin = {{ slapparameter_dict.get("autorejoin", True) }} autorejoin = {{ slapparameter_dict.get("autorejoin", True) }}
......
...@@ -6,8 +6,9 @@ title = "{{ parameter_dict['name'] }}" ...@@ -6,8 +6,9 @@ title = "{{ parameter_dict['name'] }}"
monitoring-save-config = true monitoring-save-config = true
db-servers-hosts = "{{ parameter_dict['db-list'] }}" db-servers-hosts = "{{ parameter_dict['db-list'] }}"
db-servers-prefered-master = "{{ parameter_dict['db-prefered-master'] }}" db-servers-prefered-master = "{{ parameter_dict['db-prefered-master'] }}"
db-servers-credential = "{{ parameter_dict['db-credential'] }}" db-servers-credential = "{{ parameter_dict['db-user'] }}:{{ parameter_dict['db-password'] }}"
replication-credential = "{{ parameter_dict['db-credential'] }}" replication-credential = "{{ parameter_dict['db-user'] }}:{{ parameter_dict['db-password'] }}"
monitoring-write-heartbeat-credential="{{ parameter_dict['heartbeat-user'] }}:{{ parameter_dict['heartbeat-password'] }}"
db-servers-connect-timeout = 1 db-servers-connect-timeout = 1
slapos-db-partitions = "{{ parameter_dict['partition-list'] }}" slapos-db-partitions = "{{ parameter_dict['partition-list'] }}"
slapos-proxysql-partitions = "{{ parameter_dict['proxysql-partition'] }}" slapos-proxysql-partitions = "{{ parameter_dict['proxysql-partition'] }}"
...@@ -15,6 +16,7 @@ slapos-proxysql-partitions = "{{ parameter_dict['proxysql-partition'] }}" ...@@ -15,6 +16,7 @@ slapos-proxysql-partitions = "{{ parameter_dict['proxysql-partition'] }}"
proxysql = true proxysql = true
proxysql-port = {{ parameter_dict['proxy-port'] }} proxysql-port = {{ parameter_dict['proxy-port'] }}
proxysql-servers = "{{ parameter_dict['proxysql-servers'] }}" proxysql-servers = "{{ parameter_dict['proxysql-servers'] }}"
proxysql-servers-ipv6 = "{{ parameter_dict['proxysql-servers-ipv6'] }}"
proxysql-user = "{{ parameter_dict['proxysql-user'] }}" proxysql-user = "{{ parameter_dict['proxysql-user'] }}"
proxysql-bootstrap = true proxysql-bootstrap = true
proxysql-admin-port = {{ parameter_dict['proxy-admin-port'] }} proxysql-admin-port = {{ parameter_dict['proxy-admin-port'] }}
......
...@@ -7,7 +7,7 @@ run_mysql () { ...@@ -7,7 +7,7 @@ run_mysql () {
if [ ! -f "{{ init_password_done }}" ]; then if [ ! -f "{{ init_password_done }}" ]; then
for i in {30..0}; do for i in {30..0}; do
if run_mysql -e 'SELECT 1' &> /dev/null; then if echo 'SELECT 1' | run_mysql &> /dev/null; then
break break
fi fi
echo 'MySQL init process in progress...' echo 'MySQL init process in progress...'
......
...@@ -2,11 +2,17 @@ ...@@ -2,11 +2,17 @@
-- or products like mysql-fabric won't work -- or products like mysql-fabric won't work
SET @@SESSION.SQL_LOG_BIN=0; SET @@SESSION.SQL_LOG_BIN=0;
CREATE USER 'repman'@'localhost' IDENTIFIED BY '{{ parameter_dict["password"] }}' ; CREATE USER '{{ parameter_dict["root-user"] }}'@'localhost' IDENTIFIED BY '{{ parameter_dict["password"] }}' ;
GRANT ALL ON *.* TO 'repman'@'localhost' WITH GRANT OPTION ; GRANT ALL ON *.* TO '{{ parameter_dict["root-user"] }}'@'localhost' WITH GRANT OPTION ;
CREATE USER 'repman'@'%' IDENTIFIED BY '{{ parameter_dict["password"] }}' ; CREATE USER '{{ parameter_dict["root-user"] }}'@'%' IDENTIFIED BY '{{ parameter_dict["password"] }}' ;
GRANT ALL ON *.* TO 'repman'@'%' WITH GRANT OPTION ; GRANT ALL ON *.* TO '{{ parameter_dict["root-user"] }}'@'%' WITH GRANT OPTION ;
CREATE USER 'repman'@'::' IDENTIFIED BY '{{ parameter_dict["password"] }}' ; CREATE USER '{{ parameter_dict["root-user"] }}'@'::' IDENTIFIED BY '{{ parameter_dict["password"] }}' ;
GRANT ALL ON *.* TO 'repman'@'::' WITH GRANT OPTION ; GRANT ALL ON *.* TO '{{ parameter_dict["root-user"] }}'@'::' WITH GRANT OPTION ;
CREATE USER '{{ parameter_dict["heartbeat-user"] }}'@'localhost' IDENTIFIED BY '{{ parameter_dict["password"] }}' ;
GRANT ALL ON *.* TO '{{ parameter_dict["heartbeat-user"] }}'@'localhost' WITH GRANT OPTION ;
CREATE USER '{{ parameter_dict["heartbeat-user"] }}'@'%' IDENTIFIED BY '{{ parameter_dict["password"] }}' ;
GRANT ALL ON *.* TO '{{ parameter_dict["heartbeat-user"] }}'@'%' WITH GRANT OPTION ;
DROP DATABASE IF EXISTS test ; DROP DATABASE IF EXISTS test ;
FLUSH PRIVILEGES ; FLUSH PRIVILEGES ;
\ No newline at end of file
...@@ -6,9 +6,13 @@ curl () { ...@@ -6,9 +6,13 @@ curl () {
{{ curl_bin }} -k --silent -H "Accept: application/json" "$@" {{ curl_bin }} -k --silent -H "Accept: application/json" "$@"
} }
get_token () {
curl -s -X POST --data '{"username":"{{ username }}","password":"{{ password}}"}' {{ secure_url }}/api/login
}
wait_database () { wait_database () {
NAME=$1 NAME=$1
for retry in {1..10}; do for retry in {1..50}; do
echo ">> Wait until $NAME databases are ready..."; echo ">> Wait until $NAME databases are ready...";
CODE=$(curl -H "Authorization: Bearer ${TOKEN}" -o /dev/null -w "%{http_code}" {{ secure_url }}/api/clusters/$NAME/actions/waitdatabases); CODE=$(curl -H "Authorization: Bearer ${TOKEN}" -o /dev/null -w "%{http_code}" {{ secure_url }}/api/clusters/$NAME/actions/waitdatabases);
if [ $CODE -eq 504 ]; then if [ $CODE -eq 504 ]; then
...@@ -17,6 +21,11 @@ wait_database () { ...@@ -17,6 +21,11 @@ wait_database () {
else else
if [ $CODE -eq 200 ]; then if [ $CODE -eq 200 ]; then
break; break;
else
if [ $CODE -eq 401 ]; then
# try again with new token
TOKEN=$(get_token | {{ jq_bin }} -r '.token')
fi
fi fi
echo ">> [$retry] waitdatabases returned code $CODE..."; echo ">> [$retry] waitdatabases returned code $CODE...";
fi fi
...@@ -37,7 +46,7 @@ activate_proxy () { ...@@ -37,7 +46,7 @@ activate_proxy () {
fi fi
} }
TOKEN=$(curl -s -X POST --data '{"username":"{{ username }}","password":"{{ password}}"}' {{ secure_url }}/api/login | {{ jq_bin }} -r '.token') TOKEN=$(get_token | {{ jq_bin }} -r '.token')
# Always reload cluster configuration to apply recent changes # Always reload cluster configuration to apply recent changes
{% for name in cluster_name_list -%} {% for name in cluster_name_list -%}
...@@ -52,7 +61,7 @@ if [ ! -f "{{ parameter_dict['bootstrap'] }}/{{ name }}_bootstrapped" ]; then ...@@ -52,7 +61,7 @@ if [ ! -f "{{ parameter_dict['bootstrap'] }}/{{ name }}_bootstrapped" ]; then
wait_database {{ name }} wait_database {{ name }}
echo "Bootstrap replication on {{ name }}..." echo "Bootstrap replication on {{ name }}..."
TOKEN=$(curl -s -X POST --data '{"username":"{{ username }}","password":"{{ password}}"}' {{ secure_url }}/api/login | {{ jq_bin }} -r '.token') TOKEN=$(get_token | {{ jq_bin }} -r '.token')
curl -H "Authorization: Bearer ${TOKEN}" \ curl -H "Authorization: Bearer ${TOKEN}" \
{{ secure_url }}/api/clusters/{{ name }}/actions/replication/cleanup {{ secure_url }}/api/clusters/{{ name }}/actions/replication/cleanup
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment