dbproxy 的账号是统一的, 即连接dbproxy,连接主mysql ,连接从mysql 的账号必须一样, 为了隔离 即使用dbproxy的人感知不到mysql, 需要分离

配置文件

#dbproxy账号密码与real 主mysql 和 从mysql 隔离
dbproxy-user=test
dbproxy-pwd=7O7YJJEK
master-user = master
master-pwd = 7O7YJJEK
slave-user = slave
slave-pwd = 7O7YJJEK

struct chassis_plugin_config
位置plugins/proxy/proxy-plugin.h

struct chassis_plugin_config {
...
gchar* id_generate;
gchar* dbproxy_user;
gchar* dbproxy_pwd;
gchar* master_user;
gchar* master_pwd;
gchar* slave_user;
gchar* slave_pwd;
...
}

network_mysqld_proxy_plugin_new
位置:/plugins/proxy/proxy-plugin.c

chassis_plugin_config * network_mysqld_proxy_plugin_new(void) {
...
config = g_new0(chassis_plugin_config, );
config->id_generate = NULL;
config->dbproxy_user = NULL;
config->dbproxy_pwd = NULL;
config->master_user = NULL;
config->master_pwd = NULL;
config->slave_user = NULL;
config->slave_pwd = NULL;
...
}

network_mysqld_proxy_plugin_free
位置:/plugins/proxy/proxy-plugin.c

void network_mysqld_proxy_plugin_free(chassis_plugin_config *oldconfig) {
...
if (config->id_generate) g_free(config->id_generate);
if (config->dbproxy_user) g_free(config->dbproxy_user);
if (config->dbproxy_pwd) g_free(config->dbproxy_pwd);
if (config->master_user) g_free(config->master_user);
if (config->master_pwd) g_free(config->master_pwd);
if (config->slave_user) g_free(config->slave_user);
if (config->slave_pwd) g_free(config->slave_pwd);
...
}

network_mysqld_proxy_plugin_get_options
位置:/plugins/proxy/proxy-plugin.c

static chassis_options_t * network_mysqld_proxy_plugin_get_options(chassis_plugin_config *oldconfig) {
if (config->opts == NULL) {
chassis_options_t *opts = chassis_options_new();
chassis_options_add(opts, "id-generate", , , G_OPTION_ARG_STRING, &(config->id_generate), "id-generate", NULL, NULL, NULL, ); chassis_options_add(opts, "dbproxy-user", , , G_OPTION_ARG_STRING, &(config->dbproxy_user), "dbproxy-user", NULL, NULL, NULL, ); chassis_options_add(opts, "dbproxy-pwd", , , G_OPTION_ARG_STRING, &(config->dbproxy_pwd), "dbproxy-pwd", NULL, NULL, NULL, ); chassis_options_add(opts, "master-user", , , G_OPTION_ARG_STRING, &(config->master_user), "master-user", NULL, NULL, NULL, ); chassis_options_add(opts, "master-pwd", , , G_OPTION_ARG_STRING, &(config->master_pwd), "master-pwd", NULL, NULL, NULL, ); chassis_options_add(opts, "slave-user", , , G_OPTION_ARG_STRING, &(config->slave_user), "slave-user", NULL, NULL, NULL, ); chassis_options_add(opts, "slave-pwd", , , G_OPTION_ARG_STRING, &(config->slave_pwd), "slave-pwd", NULL, NULL, NULL, ); config->opts = opts;
}
return config->opts;
}

network_mysqld_proxy_plugin_apply_config
位置:/plugins/proxy/proxy-plugin.c

int network_mysqld_proxy_plugin_apply_config(chassis *chas, chassis_plugin_config *oldconfig) {
gchar *user = NULL, *pwd = NULL, *user_master = NULL, *pwd_master = NULL, *user_slave = NULL, *pwd_slave = NULL;
user = config->dbproxy_user;
pwd = config->dbproxy_pwd;
user_master = config->master_user;
pwd_master = config->master_pwd;
user_slave = config->slave_user;
pwd_slave = config->slave_pwd; char* raw_pwd = decrypt(pwd);
char* raw_pwd_master = decrypt(pwd_master);
char* raw_pwd_slave = decrypt(pwd_slave); if (raw_pwd && raw_pwd_master && raw_pwd_slave) {
GString* hashed_password = g_string_new(NULL);
network_mysqld_proto_password_hash(hashed_password, raw_pwd, strlen(raw_pwd)); /*
主库 设置密码
*/
GString* hashed_password_master = g_string_new(NULL);
network_mysqld_proto_password_hash(hashed_password_master, raw_pwd_master, strlen(raw_pwd_master)); /*
从库 设置密码
*/
GString* hashed_password_slave = g_string_new(NULL);
network_mysqld_proto_password_hash(hashed_password_slave, raw_pwd_slave, strlen(raw_pwd_slave));
     
/*
hash
key: username (dbproxy本身的账号)
value: 加密过的dbproxy本身的密码, 加密过的主mysql密码,加密过的从mysql密码,
主mysql 账号, 从mysql 账号
*/  user_info_hval *hval = user_info_hval_new(hashed_passwo rd, hashed_password_master, user_master, hashed_password_slave, user_slave); /*
保存密码明文, 这里是个数组,感觉作用不到,因为只有一组账号密码在起作用
*/
raw_user_info *rwi = raw_user_info_new(user, pwd, NULL, NULL, user_master, pwd_master, user_slave, pwd_slave); g_rw_lock_writer_lock(&bs->user_mgr_lock);
if (g_hash_table_lookup(bs->pwd_table, user) == NULL) {
g_hash_table_insert(bs->pwd_table, g_strdup(user), hval);
g_ptr_array_add(bs->raw_pwds, rwi);
}
g_rw_lock_writer_unlock(&bs->user_mgr_lock); //g_free(tmp_for_free);
g_free(raw_pwd);
} raw_user_info *
raw_user_info_new(const gchar *username, const gchar *encrypt_pwd, const gchar *user_hosts, gchar *backends, const gchar* user_master, const gchar* encrypt_pwd_master, const gchar* user_slave, const gchar* encrypt_pwd_slave) {
raw_user_info *rwi = NULL; g_assert(username != NULL); rwi = g_new0(raw_user_info, );
rwi->username = g_strdup(username);
if (encrypt_pwd) {
rwi->encrypt_pwd = g_strdup(encrypt_pwd);
}
if (user_hosts) {
rwi->user_hosts = g_strdup(user_hosts);
}
if (backends) {
rwi->backends = g_strdup(backends);
} rwi->user_master = g_strdup(user_master);
rwi->encrypt_pwd_master = g_strdup(encrypt_pwd_master); rwi->user_slave = g_strdup(user_slave);
rwi->encrypt_pwd_slave = g_strdup(encrypt_pwd_slave); return rwi;
}

保存主mysql 账号 , 从mysql 账号

//user_info_hval_new(hashed_password, hashed_password_real_db, username_real_db, host_real_db);

user_info_hval *
user_info_hval_new(GString *hashed_passwd, GString *hashed_password_master, gchar* user_master, GString *hashed_password_slave, gchar* user_slave) {
user_info_hval *hval = g_new0(user_info_hval, ); hval->user_hosts = g_ptr_array_new_with_free_func(g_free);
hval->backends_tag = g_ptr_array_new_with_free_func(g_free); hval->hashed_password = hashed_passwd;
hval->user_tag_max_weight = ; /*
主库账号和密码
*/
hval->user_master = g_strdup(user_master);
hval->hashed_password_master = hashed_password_master; /*
从库账号和密码
*/
hval->user_slave = g_strdup(user_slave);
hval->hashed_password_slave = hashed_password_slave; return hval;
}

dbproxy-user/pwd的更多相关文章

  1. linux下 php 安装mysql的扩展模块

    1.安装mysql-devel包 [root@DBproxy ~]# yum install mysql-devel 注:该包必须在编译php之前安装好,否则在安装php的mysql扩展模块是会碰到各 ...

  2. 美团点评DBProxy读写分离使用说明

    目的 因为业务架构上需要实现读写分离,刚好前段时间美团点评开源了在360Atlas基础上开发的读写分离中间件DBProxy,关于其介绍在官方文档已经有很详细的说明了,其特性主要有:读写分离.负载均衡. ...

  3. DBProxy 读写分离使用说明

    美团点评DBProxy读写分离使用说明   目的 因为业务架构上需要实现读写分离,刚好前段时间美团点评开源了在360Atlas基础上开发的读写分离中间件DBProxy,关于其介绍在官方文档已经有很详细 ...

  4. DBProxy 项目全解

    转载自:https://github.com/Meituan-Dianping/DBProxy/blob/master/doc/USER_GUIDE.md#2 1 总体信息        1.1 关于 ...

  5. linux常用命令(2)pwd命令

    pwd 命令1 命令格式:pwd [选项]2 命令功能查看当前工作目录的完整路径3 常用参数一般不带任何参数如果目录是链接时:pwd -P 显示实际路径,而非使用链接路径4 常用实例:4.1 用pwd ...

  6. pwd命令

    [pwd]      打印当前的工作目录             pwd==print work director 命令格式: pwd [OPTION]... 命令功能: 打印当前工作目录的全路径 命 ...

  7. Linux命令学习总结:pwd命令

    命令简介: 该命令用来显示目前所在的工作目录.指令英文原义:print work directory 执行权限    :All User 指令所在路径:/usr/bin/pwd 或 /bin/pwd ...

  8. 每天一个linux命令(3):pwd命令

    Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...

  9. 【初级】linux pwd 命令详解及使用方法实战

    pwd:查看当前工作目录 前言: Linux中用 pwd 命令来查看”当前工作目录“的完整路径,就是经常提及的所在目录,多用在生产环境多级目录中查看当前所在路径,使用此命令能给运维人员/操作人员带来很 ...

随机推荐

  1. IDEA错误的忽略了智能补全代码,导致正确的代码自动提示不出来的问题

    标题说起来有点绕,当今大部分IDE都提供 Alt+Enter 呼出自动补全菜单的功能,IDEA也不例外,今天手残了一下,具体问题如下: 1. 通常我们键入一个自定义类时IDEA会自动提示为红色,表示缺 ...

  2. devcloud 基础架构

           

  3. SqlSugar Asp.Net 高性能ORM框架

    SqlSugar从去年到现在已经一年了,版本从1.0升到了现在的2.4.1 ,这是一个稳定版本 ,有数家公司已经项目上线,在这里我将SqlSugar的功能重新整理成一篇新的贴子,希望大家喜欢. 公司团 ...

  4. EntityFramework 学习资料

    1.EF框架step by step 2.Entity Framework Code First 学习日记 3.[译著]Code First :使用Entity. Framework编程 4.Enti ...

  5. python处理Excel 之 xlrd-乾颐堂

    python处理Excel常用到的模块是xlrd.使用xlrd可以非常方便的处理Excel文档,下面介绍一下基本用法 1.打开文件 import xlrd data= xlrd.open_workbo ...

  6. [operator]ELK6的安装

    找了很久才找到一个博客写得比较全面的,FrankDeng 系统环境:CentOS7 相关软件:node-v10.9.0.tar.gz.kibana-6.4.0-linux-x86_64.tar.gz. ...

  7. linux 删除文件,某个文件例外

    # shopt -s extglob      (打开extglob模式) # rm -fr !(file1)

  8. Cuckoo Hash和多级Hash的粗浅认识

    通过对Cuckoo Hash.多级Hash和BloomFilter的粗浅了解,感觉它们三者存在类似之处,算是近亲(暂且把普通的Hash称作远亲). Cuckoo Hash的思想非常简单,冲突时,重Ha ...

  9. 引用数据类型(类)和ArrayList

    引用数据类型(类) 类的类型为两种: 第一种,Java为我们提供好的类,如Scanner类,Scanner类等,这些已存在的类中包含了很多的方法与属性,可供我们使用. 第二种,我们自己创建的类,按照类 ...

  10. C#中的异步调用及异步设计模式(二)——基于 IAsyncResult 的异步设计模式

    三.基于 IAsyncResult 的异步设计模式(设计层面) IAsyncResult 异步设计模式通过名为 BeginOperationName 和 EndOperationName 的两个方法来 ...