It’s 2018. Maybe now is the time to start migrating your network to IPv6, and your database infrastructure is a great place to start. Unfortunately, many legacy applications don’t offer the option to connect to MySQL directly over IPv6 (sometimes even if passing a hostname). We can work around this by using ProxySQL’s IPv6 support which was added in version 1.3. This will allow us to proxy incoming IPv4 connections to IPv6-only database servers.
Note that by default ProxySQL only listens on IPv4. We don’t recommended changing that until this bug is resolved. The bug causes ProxySQL to segfault frequently if listening on IPv6.
In this example I’ll use centos7-pxc57-1 as my database server. It’s running Percona XtraDB Cluster (PXC) 5.7 on CentOS 7, which is only accessible over IPv6. This is one node of a three node cluster, but l treat this one node as a standalone server for this example. One node of a synchronous cluster can be thought of as equivalent to the entire cluster, and vice-versa. Using the PXC plugin for ProxySQL to split reads from writes is the subject of a future blog post.
The application server, centos7-app01, would be running the hypothetical legacy application.
Note: We use default passwords throughout this example. You should always change the default passwords.
We have changed the IPv6 address in these examples. Any resemblance to real IPv6 addresses, living or dead, is purely coincidental.
- 2a01:5f8:261:748c::74 is the IPv6 address of the ProxySQL server
- 2a01:5f8:261:748c::71 is the Percona XtraDB node
Step 1: Install ProxySQL for your distribution
[...] Installed: proxysql.x86_64 0:1.4.9-1.1.el7 Complete!
Step 2: Configure ProxySQL to listen on IPv4 TCP port 3306 by editing /etc/proxysql.cnf and starting it
[root@centos7-app1 ~]# vim /etc/proxysql.cnf [root@centos7-app1 ~]# grep interfaces /etc/proxysql.cnf interfaces="127.0.0.1:3306" [root@centos7-app1 ~]# systemctl start proxysql
Step 3: Configure ACLs on the destination database server to allow ProxySQL to connect over IPv6
mysql> GRANT SELECT on sys.* to 'monitor'@'2a01:5f8:261:748c::74' IDENTIFIED BY 'monitor'; Query OK, 0 rows affected, 1 warning (0.25 sec) mysql> GRANT ALL ON legacyapp.* TO 'legacyappuser'@'2a01:5f8:261:748c::74' IDENTIFIED BY 'super_secure_password'; Query OK, 0 rows affected, 1 warning (0.25 sec)
Step 4: Add the IPv6 address of the destination server to ProxySQL and add users
We need to configure the IPv6 server as a mysql_server inside ProxySQL. We also need to add a user to ProxySQL as it will reuse these credentials when connecting to the backend server. We’ll do this by connecting to the admin interface of ProxySQL on port 6032:
[root@centos7-app1 ~]# mysql -h127.0.0.1 -P6032 -uadmin -padmin mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.5.30 (ProxySQL Admin Module) Copyright (c) 2009-2018 Percona LLC and/or its affiliates Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> INSERT INTO mysql_servers(hostgroup_id,hostname,port) VALUES (1,'2a01:5f8:261:748c::71',3306); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO mysql_users(username, password, default_hostgroup) VALUES ('legacyappuser', 'super_secure_password', 1); Query OK, 1 row affected (0.00 sec) mysql> LOAD MYSQL USERS TO RUNTIME; Query OK, 0 rows affected (0.00 sec) mysql> SAVE MYSQL USERS TO DISK; Query OK, 0 rows affected (0.27 sec) mysql> LOAD MYSQL SERVERS TO RUNTIME; Query OK, 0 rows affected (0.01 sec) mysql> SAVE MYSQL SERVERS TO DISK; Query OK, 0 rows affected (0.30 sec) mysql> LOAD MYSQL VARIABLES TO RUNTIME; Query OK, 0 rows affected (0.00 sec) mysql> SAVE MYSQL VARIABLES TO DISK; Query OK, 95 rows affected (0.12 sec)
Step 5: Configure your application to connect to ProxySQL over IPv4 on localhost4 (IPv4 localhost)
This is application specific and so not shown here, but I’d configure my application to use localhost4 as this is in /etc/hosts by default and points to 127.0.0.1 and not ::1
Step 6: Verify
As I don’t have the application here, I’ll verify with mysql-client. Remember that ProxySQL is listening on 127.0.0.1 port 3306, so we connect via ProxySQL on IPv4 (the usage of 127.0.0.1 rather than a hostname is just to show this explicitly):
[root@centos7-app1 ~]# mysql -h127.0.0.1 -ulegacyappuser -psuper_secure_password mysql: [Warning] Using a password on the command line interface can be insecure. mysql> SELECT host FROM information_schema.processlist WHERE ID=connection_id(); +-----------------------------+ | host | +-----------------------------+ | 2a01:5f8:261:748c::74:57546 | +-----------------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE legacyapp.legacy_test_table(id int); Query OK, 0 rows affected (0.83 sec)
The query above shows the remote host (from MySQL’s point of view) for the current connection. As you can see, MySQL sees this connection established over IPv6. So to recap, we connected to MySQL on an IPv4 IP address (127.0.0.1) and were successfully proxied to a backend IPv6 server.
The post Using ProxySQL to connect to IPv6-only databases over IPv4 appeared first on Percona Database Performance Blog.