我正在一个有 88 个用户帐户的 Percona MySQL 服务器前设置 ProxySQL。我什至不知道他们的大部分密码。密码以散列形式存储在 MySQL 中,但以纯文本形式存储在 ProxySQL 中。如何轻松地一次将所有 88 个帐户引入 ProxySQL?或者是否有我可以打开的直通身份验证开关?
小智 5
由于您将 ProxySQL 与 Percona 一起使用,因此 Percona 的好人制作了一个漂亮的工具,可以完全满足您的需求(将 mysql 用户同步到 proxysql)。
如果您使用 Percona RPM 安装 ProxySQL,它会附带一个漂亮的脚本,可帮助管理名为“proxysql-admin”的 ProxySQL 实例。该脚本可以选择“--syncusers”。以下是脚本帮助信息的摘录:
[root@localhost ~]# /usr/bin/proxysql-admin
Usage: [ options ]
Options:
--config-file=<config-file> Read login credentials from a configuration file (overrides any login credentials specified on the command line)
--quick-demo Setup a quick demo with no authentication
--proxysql-datadir=<datadir> Specify proxysql data directory location
--proxysql-username=user_name Username for connecting to the ProxySQL service
--proxysql-password[=password] Password for connecting to the ProxySQL service
--proxysql-port=port_num Port Nr. for connecting to the ProxySQL service
--proxysql-hostname=host_name Hostname for connecting to the ProxySQL service
--cluster-username=user_name Username for connecting to the Percona XtraDB Cluster node
--cluster-password[=password] Password for connecting to the Percona XtraDB Cluster node
--cluster-port=port_num Port Nr. for connecting to the Percona XtraDB Cluster node
--cluster-hostname=host_name Hostname for connecting to the Percona XtraDB Cluster node
--cluster-app-username=user_name Application username for connecting to the Percona XtraDB Cluster node
--cluster-app-password[=password] Application password for connecting to the Percona XtraDB Cluster node
--without-cluster-app-user Configure Percona XtraDB Cluster without application user
--monitor-username=user_name Username for monitoring Percona XtraDB Cluster nodes through ProxySQL
--monitor-password[=password] Password for monitoring Percona XtraDB Cluster nodes through ProxySQL
--without-check-monitor-user Configure ProxySQL without checking/attempting to create monitor user
--enable, -e Auto-configure Percona XtraDB Cluster nodes into ProxySQL
--disable, -d Remove any Percona XtraDB Cluster configurations from ProxySQL
--node-check-interval=3000 Interval for monitoring node checker script (in milliseconds)
--mode=[loadbal|singlewrite] ProxySQL read/write configuration mode, currently supporting: 'loadbal' and 'singlewrite' (the default) modes
--write-node=host_name:port Writer node to accept write statments. This option is supported only when using --mode=singlewrite
Can accept comma delimited list with the first listed being the highest priority.
--include-slaves=host_name:port Add specified slave node(s) to ProxySQL, these nodes will go into the reader hostgroup and will only be put into
the writer hostgroup if all cluster nodes are down. Slaves must be read only. Can accept comma delimited list.
If this is used make sure 'read_only=1' is in the slave's my.cnf
--adduser Adds the Percona XtraDB Cluster application user to the ProxySQL database
--syncusers Sync user accounts currently configured in MySQL to ProxySQL (deletes ProxySQL users not in MySQL)
--version, -v Print version info
[root@localhost ~]#
Run Code Online (Sandbox Code Playgroud)
注意底部的“--syncusers”选项。这就是你要找的,是吗?...它是由 Percona 制作和分发的。:)
希望这可以帮助!
这是解释 ProxySQL 中密码存储(和散列)的官方文档:密码管理
现在的任务是将所有用户名和SHA1 哈希密码从mysql导出到proxysql后端,这是一个sqlite3文件。我是这样做的。
A. 创建一个类似/tmp/user.sql的文件,其中包含以下内容:
select "INSERT INTO mysql_users (username,password) VALUES (", CONCAT("'",User,"'"), ",", CONCAT("'",Password,"'"), ");" from user WHERE Password LIKE "*%" order by User;
Run Code Online (Sandbox Code Playgroud)
B. 在您的 mysqld 服务器上运行它,以root 身份或使用您至少有权查看mysql.user表的任何权限。将 -h 或 -p 或任何您需要的内容添加到mysql命令中:
linux# mysql -N mysql < /tmp/user.sql > /tmp/input.sql
Run Code Online (Sandbox Code Playgroud)
C. 编辑/tmp/input.sql仔细检查您拥有的用户,省略重复的行等。您可能会看到相同的用户具有不同的密码哈希值。在这里,相同的密码总是映射到相同的哈希值,因此如果您在 mysql 中定义了旧用户(可能来自具有不同密码的不同客户端 IP),则可能需要进行一些整理。不必担心该文件中的其余格式和选项卡。只需删除不需要的行即可。
D. 在proxysql服务器上(也许与mysqld相同),将/var/lib/proxysql/proxysql.db复制到/tmp,将input.sql文件放在适当的位置,然后尝试导入:
linux# sqlite3 /tmp/proxysql.db < /tmp/input.sql
Run Code Online (Sandbox Code Playgroud)
它可能会警告现有的用户帐户,这是无害的,但值得在输入文件中的任何此类行中进行检查:
Error: near line 34: columns username, frontend are not unique
Error: near line 35: columns username, frontend are not unique
Run Code Online (Sandbox Code Playgroud)
E.直接在sqlite3中查看你的新成就:
linux# sqlite3 /tmp/proxysql.db
sqlite> select * from mysql_users;
...
glpi|*F210F7D92AE10C493DDA19A33D4BC50C6E82517|1|0|0||0|0|0|1|1|10000
icinga|*79BAD610D871E3323F655960E4BD2399FAAF7C1|1|0|0||0|0|0|1|1|10000
icinga_check|*B87C5B0712F247F7632A450A36D1285C8666496|1|0|0||0|0|0|1|1|10000
ipplan|*EE50B7BF86175E257803509C4B04B51DF557D19|1|0|0||0|0|0|1|1|10000
...
Run Code Online (Sandbox Code Playgroud)
F. 一旦您确信它看起来正确,请在生产proxysql.db文件中进行相同的编辑,以管理员身份登录到 proxysql,并让新用户生效:
proxysql> LOAD MYSQL USERS FROM DISK;
Run Code Online (Sandbox Code Playgroud)
G. 现在你只能靠自己了。将它们带入运行时、测试、设置其他首选项(例如默认架构和主机组)等。
我对您在这里造成的损害不做任何保证或索赔。这就是我将一长串现有用户引入 ProxySQL 的方法。我试图在我的数据库服务器上的端口 3306 上插入proxysql ,然后悄悄地将mysql移动到 2206。没有骰子。在我的环境中这永远不会发生。也许你很幸运,有一些更简单的事情可以管理。至少这会让您入门,并且您将了解一些有关 ProxySQL 内部结构的知识。祝你好运!
| 归档时间: |
|
| 查看次数: |
4992 次 |
| 最近记录: |