2.历史记录区
实现架构:
运维平台Web界面 - > nginx+lua(数据库路由功能) -> nginx + lua + drizzle-nginx + ngx_postgres + form-input-nginx-module (如果性能不足能,需要复制、克隆加资源,只要在数据库路由端注册就行了)公共组成的API查询接口
实现:
1.编译。
nginx中加入 --add-module=PATH/ngx_devel_kit-0.2.19 --add-module=PATH/lua-nginx-module-0.9.7 --add-module=PATH/rds-json-nginx-module-master(主要让输出结果自动json化) --add-module=PATH/form-input-nginx-module --add-module=PATH/ngx_postgres-master --add-module=PATH/drizzle-nginx-module-0.1.7
drizzle-nginx-modul =
ngx_postgres =
form-input-nginx-module =
2.nginx查找数据库的中配置:
MySQL
upstream name {
drizzle_server db ip:db port dbname=xx
password=xx user=xx protocol=mysql charset=utf8;
}
show table功能
location ~ (数据库路由标识) {
set $upname $1;
set $my_sql 'show tables';
drizzle_query $my_sql;
drizzle_pass $upname;
drizzle_connect_timeout 10s; # default 60s
drizzle_send_query_timeout 60s; # default 60s
drizzle_recv_cols_timeout 30s; # default 60s
drizzle_recv_rows_timeout 30s; # default 60s
rds_json on;
}
查表操作
location ~ (数据库路由信息) {
default_type 'text/plain';
set_form_input $qsql;
access_by_lua $sql '
权限和非法字符验证功能模块,验证qsql
';
set $upname $1;
lua_need_request_body on;
client_max_body_size 50k;
client_body_buffer_size 50k;
drizzle_query $sql;
drizzle_pass $upname;
drizzle_connect_timeout 10s; # default 60s
drizzle_send_query_timeout 30s; # default 60s
drizzle_recv_cols_timeout 30s; # default 60s
drizzle_recv_rows_timeout 30s; # default 60s
rds_json on;
}
PG
upstream 192.168.236.1725432huayouhui_app {
postgres_server db ip:db port dbname=xx
user=xx password=xx;
postgres_keepalive off;
}
查表
location ~ (路由信息) {
add_header Content-Type 'text/html; charset=utf-8';
set $dbname $2;
set $upname $1$2;
set_by_lua $quoted_name '
local name = ngx.var.dbname
local mysql = "select tablename from pg_tables where schemaname=\'"..name.."\';"
return mysql
';
postgres_pass $upname;
rds_json on;
postgres_query '$quoted_name';
}
查询
location ~ (数据库路由信息) {
add_header Content-Type 'text/html; charset=utf-8';
set_form_input $qsql;
access_by_lua $sql '
权限和非法字符验证功能模块,验证qsql
';
set $upname $1;
lua_need_request_body on;
client_max_body_size 50k;
client_body_buffer_size 50k;
postgres_pass $upname;
rds_json on;
postgres_query '$sql';
}
页面实现和测试上线时间:3days;nginx 路由 + nginx查询 : 实现+测试 1day。
更多文章请关注,微信订阅号号:轻度运维