MySQL SQL审核平台 inception+archer2.0(亲测)
docker run -d --privileged -v `pwd`/archer_data:/data -p 9306:3306 --name archer --hostname archer --net staticnet --ip 192.168.0.200 eiki/mysql:5.7.24 /usr/sbin/init
docker run -d --privileged -v `pwd`/archer_data:/data -p 9307:3306 -p 9123:9123 --name archer2 --hostname archer2 --net staticnet --ip 192.168.0.201 eiki/mysql:5.7.24 /usr/sbin/init
安装SQLAdvisor
1下载软件包
2 解压tar包
[root@archer5 soft]# tar -xvf Percona-Server-5.6.29-76.2-rddf26fe-el6-x86_64-bundle.tar
Percona-Server-56-debuginfo-5.6.29-rel76.2.el6.x86_64.rpm
Percona-Server-client-56-5.6.29-rel76.2.el6.x86_64.rpm
Percona-Server-devel-56-5.6.29-rel76.2.el6.x86_64.rpm
Percona-Server-server-56-5.6.29-rel76.2.el6.x86_64.rpm
Percona-Server-shared-56-5.6.29-rel76.2.el6.x86_64.rpm
Percona-Server-test-56-5.6.29-rel76.2.el6.x86_64.rpm
Percona-Server-tokudb-56-5.6.29-rel76.2.el6.x86_64.rpm
3 安装
[root@archer5 soft]# yum localinstall Percona-Server-shared-56-5.6.29-rel76.2.el6.x86_64.rpm
[root@archer5 soft]# yum localinstall Percona-Server-client-56-5.6.29-rel76.2.el6.x86_64.rpm
[root@archer5 soft]# yum localinstall Percona-Server-server-56-5.6.29-rel76.2.el6.x86_64.rpm
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h archer5 password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
Please report any problems at
https://bugs.launchpad.net/percona-server/+filebug
The latest information about Percona Server is available on the web at
http://www.percona.com/software/percona-server
Support Percona by buying support at
http://www.percona.com/products/mysql-support
Percona Server is distributed with several useful UDF (User Defined Function) from Percona Toolkit.
Run the following commands to create these functions:
mysql -e "CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'"
mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'"
mysql -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'"
See http://www.percona.com/doc/percona-server/5.6/management/udf_percona_toolkit.html for more details
vi /etc/my.cnf
/etc/init.d/mysql start
[root@archer5 soft]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29-76.2 Percona Server (GPL), Release 76.2, Revision ddf26fe
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, 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.
[root@localhost][(none)]>
[root@localhost][(none)]>
[root@localhost][(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
[root@localhost][(none)]>
[root@localhost][(none)]>
[root@localhost][(none)]> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | archer5 |
| root | archer5 |
| | localhost |
| root | localhost |
+------+-----------+
6 rows in set (0.01 sec)
[root@localhost][(none)]> drop user root@::1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '::1' at line 1
[root@localhost][(none)]> drop user root@'
Query OK, 0 rows affected (0.00 sec)
[root@localhost][(none)]> drop user root@'archer5
Query OK, 0 rows affected (0.00 sec)
[root@localhost][(none)]> drop user root@'127.0.0.1
Query OK, 0 rows affected (0.00 sec)
[root@localhost][(none)]> select user,host from mysql.user;
elect user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| | archer5 |
| | localhost |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)
[root@localhost][(none)]> select user,host from mysql.user;
droarcher5
Query OK, 0 rows affected (0.00 sec)
[root@localhost][(none)]> drop user ''@localhost
Query OK, 0 rows affected (0.02 sec)
[root@localhost][(none)]>
[root@localhost][(none)]>
[root@localhost][(none)]> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.00 sec)
[root@localhost][(none)]>
[root@localhost][(none)]>
[root@localhost][(none)]> set password for root@localhost = password('rooT_258
Query OK, 0 rows affected (0.00 sec)
[root@localhost][(none)]>
[root@localhost][(none)]> quit
Bye
[root@archer5 soft]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@archer5 soft]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.29-76.2 Percona Server (GPL), Release 76.2, Revision ddf26fe
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, 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.
[root@localhost][(none)]>
[root@localhost][(none)]>
[root@localhost][(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
[root@localhost][(none)]>
[root@localhost][(none)]>
[root@localhost][(none)]> quit
Bye
[root@archer5 data]# git clone https://github.com/Meituan-Dianping/SQLAdvisor.git
[root@archer5 data]# yum install cmake libaio-devel libffi-devel glib2 glib2-devel bison gcc gcc-c++ cmake
[root@archer5 data]# yum install -y make cmake libaio-devel libffi-devel glib2 glib2-devel bison gcc gcc-c++
[root@archer5 data]# find / -name libperconaserverclient_r.so
[root@archer5 data]# find / -name libperconaserverclient_r.so.18
/usr/lib64/libperconaserverclient_r.so.18
[root@archer5 data]#
[root@archer5 data]#
[root@archer5 data]# cd /usr/lib64/
[root@archer5 lib64]# ln -s libperconaserverclient_r.so.18 libperconaserverclient_r.so
[root@archer5 data]# cd SQLAdvisor/
[root@archer5 SQLAdvisor]# cmake -DBUILD_CONFIG=mysql_release -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=/usr/local/sqlparser -DIGNORE_AIO_CHECK=/usr/share/doc/libaio-0.3.109 ./
[root@archer5 SQLAdvisor]# cd ./sqladvisor/
[root@archer5 sqladvisor]# cmake -DCMAKE_BUILD_TYPE=debug ./
[root@archer5 sqladvisor]# make
[root@archer5 sqladvisor]# cp /data/SQLAdvisor/sqladvisor/sqladvisor /usr/bin/sqladvisor
[root@archer5 sqladvisor]# sqladvisor --help
Usage:
sqladvisor [OPTION…] sqladvisor
SQL Advisor Summary
Help Options:
-?, --help Show help options
Application Options:
-f, --defaults-file sqls file
-u, --username username
-p, --password password
-P, --port port
-h, --host host
-d, --dbname database name
-q, --sqls sqls
-v, --verbose 1:output logs 0:output nothing
安装inception
yum -y install cmake bison ncurses-devel gcc gcc-c++ openssl-devel
手动上传inception文件
tar -xf inception.tar -C /usr/local/
chown -R root:root /usr/local/inception/
vi ~/.bash_profile
增加:path=$path:/usr/local/inception/bin
source ~/.bash_profile
启动及检测
nohup /usr/local/inception/bin/Inception --defaults-file=/usr/local/inception/bin/inc.cnf >/dev/null 2>&1 &
nohup sh /usr/local/archer_web/archer/debug.sh >/dev/null 2>&1 &
验证:
mysql -uroot -h127.0.0.1 -P6669
inception get variables;
wget -O m4-1.4.9.tar.gz http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
tar -zvxf m4-1.4.9.tar.gz
cd m4-1.4.9
./configure
make
make install
wget http://alpha.gnu.org/gnu/bison/bison-2.5.91.tar.xz
xz -d bison-2.5.91.tar.xz
tar xf bison-2.5.91.tar
cd bison-2.5.91
./configure
make && make install
安装完成后:bison -V
wget http://www.openssl.org/source/openssl-1.1.1.tar.gz
tar -zxvf openssl-1.1.1.tar.gz
cd openssl-1.1.1
./config --prefix=/usr/local/openssl shared zlib
make && make install
安装python3
yum install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev zlib zlib-devel
wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
tar -xvf Python-3.6.6.tgz
cd Python-3.6.6
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --with-ssl
make && make install
软连接
cp /usr/bin/python /usr/bin/python2.7
ln -fs /usr/local/python3/bin/python3.6 /usr/bin/python
ln -fs /usr/local/python3/bin/pip3 /usr/bin/pip
--------------------------------------------------------------------------------------------------
wget https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz
tar -xvf Python-3.4.1.tgz
cd Python-3.4.1
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --with-ssl
make && make install
软连接
ln -fs /usr/local/python3/bin/python3.4 /usr/bin/python
ln -fs /usr/local/python3/bin/pip3 /usr/bin/pip
---yum修改
vi /usr/bin/yum #将头部 #!/usr/bin/python 修改为 #!/usr/bin/python2.7
vi /usr/libexec/urlgrabber-ext-down #将头部 #!/usr/bin/python改为/usr/bin/python2.7。
vi /usr/bin/yum-config-manager #将头部 #!/usr/bin/python换成 #!/usr/bin/python2.7
pip install --upgrade pip
--安装archer
mkdir -p /usr/local/archer_web/
cd /usr/local/archer_web
yum -y install git
git clone https://github.com/jly8866/archer.git
--安装setuptools
cd /opt
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6
python setup.py build
python setup.py install
可以看到安装到python3下面了
--安装Django
cd /opt
wget https://pypi.python.org/packages/44/41/bf93934082e9897a56a591a67bacbd9fb74e71244f3f42253432a9e627e6/Django-1.8.17.tar.gz#md5=e76842cdfbcb31286bd44f51e087a04c
tar -zxvf Django-1.8.17.tar.gz
cd Django-1.8.17
python setup.py install
python
>>> import django
>>> django.VERSION
(1, 8, 17, 'final', 0)
>>> exit()
yum -y install libyaml libyaml-devel
--安装Crypto和pymysql
pip install Crypto
pip install pycrypto
pip install pymysql
这里遇到了错误
# pip3 install Crypto
-bash: ./pip3: /usr/bin/python3: bad interpreter: No such file or directory
解决方法:
python3.4 -m pip install Crypto
或者
vim /opt/python3/bin/pip3
将#!/usr/bin/python3改为#!/opt/python3/bin/python3.4
# vim /opt/python3/lib/python3.4/site-packages/pymysql/connections.py
在if int(self.server_version.split(‘.’, 1)[0]) >= 5: 这一行之前加上以下这一句并保存,记得别用tab键用4个空格缩进:
self.server_version = '5.6.24-72.2-log'
--配置archer
cd /usr/local/archer_web/archer
--创建archer DB和inception DB
--进入安装的mysql5.6
mysql -uroot -p'rooT_258'
--grant all privileges on *.* to root@'%' identified by 'P@ssw0rd';
create database archer default character set utf8;
grant all on archer.* to archer_rw@'%' identified by 'P@ssw0rd';
create database inception_db default character set utf8;
grant all on inception_db.* to incep_rw@'%' identified by 'P@ssw0rd';
grant select,create,insert on *.* to incep_rw@'%' identified by 'P@ssw0rd';
10.200.22.33 3306
#create database test default character set utf8; #测试库 建在审核库里了 仅做测试
#grant all on test.* to test@'%' identified by 'test';
#flush privileges;
--修改/usr/local/archer_web/archer/archer/settings.py,如下内容:
vi /usr/local/archer_web/archer/archer/settings.py
#该项目本身的mysql数据库地址
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'archer',
'USER': 'archer_rw',
'PASSWORD': 'P@ssw0rd',
'HOST': '127.0.0.1',
'PORT': '3306'
}
}
#inception组件所在的地址
INCEPTION_HOST = '10.10.3.70'
INCEPTION_PORT = '6669'
#查看回滚SQL时候会用到,这里要告诉archer去哪个mysql里读取inception备份的回滚信息和SQL.
#注意这里要和inception组件的inception.conf里的inception_remote_XX部分保持一致.
INCEPTION_REMOTE_BACKUP_HOST='10.10.3.70'
INCEPTION_REMOTE_BACKUP_PORT=3306
INCEPTION_REMOTE_BACKUP_USER='incep_rw'
INCEPTION_REMOTE_BACKUP_PASSWORD='P@ssw0rd' 这个用户就是在部署inception使用的用户。(这用户应该是和上面创建的incep_rw是一个用户,可以不用创建incep_rw)
--通过model创建archer本身的数据库表
cd /usr/local/archer_web/archer
pip install django_admin_bootstrapped
pip install django_apscheduler
python manage.py makemigrations
python manage.py makemigrations sql
python manage.py migrate
进入数据库查看archer库下的表是否存在
--创建django admin管理员
python manage.py createsuperuser
Username: admin 自己填写用户名
Email address: 邮箱 xuaiqi@vcredit.com
Password: 密码 xaq1234!!
Password (again): 确认密码
Superuser created successfully.
该用户可以登录django admin来管理model。
--启动acher
vi debug.sh
#!/bin/bash
python manage.py runserver 10.10.3.70:9123 端口为9123 此处改为8080了
nohup sh /usr/local/archer_web/archer/debug.sh >/dev/null 2>&1 &
--创建archer系统登录用户
pip install simplejson
通过浏览器访问http://10.138.61.13:9123/admin/sql/users/
可以看到django登录界面:
使用上面创建的用户名密码(admin/和密码)登录:
点击右侧Add用户配置,用户名密码自定义,至少创建一个工程师和一个审核人(用admin用户可以登录)后续新的工程师和审核人用户请用LDAP导入sql_users表或django admin增加
--配置主库地址
通过浏览器访问http://10.138.61.13:9123/admin/sql/master_config
点击右侧Add master_config。这一步是为了告诉archer你要用inception去哪些mysql主库里执行SQL,所用到的用户名密码、端口等。
--正式访问主页
http://10.138.61.13:9123/login/
发起脚本如:
use mysql;
create table t (id int(10));
insert into t values(1);
insert into t values(2);
commit;
select * from t;
如报错:/opt/python3/lib/python3.4/site-packages/pymysql/connections.py in _request_authentication, line 1113
解决办法:
vi /opt/python3/lib/python3.4/site-packages/pymysql/connections.py
... ...
def _request_authentication(self):
# https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse
self.server_version = '5.6.24-72.2-log' #添加此行
if int(self.server_version.split('.', 1)[0]) >= 5:
... ...
如果遇到rollback的问题,就是给权限的问题,inception配置的连接的数据库的用户的权限,在
grant select,create,insert on *.* to incep_rw@'%' identified by 'P@ssw0rd';
也就是我配置的admin的用户。
inception源码地址:https://github.com/mysql-inception/inception
archer 源码地址:https://github.com/jly8866/archer
MySQL SQL审核平台 inception+archer2.0(亲测)的更多相关文章
- 基于Inception搭建MySQL SQL审核平台Yearing
基于Inception搭建MySQL SQL审核平台Yearing Inception 1. Inceptionj简介 2. Inception安装 2.1 下载和编译 2.2 启动配置 Yearni ...
- MYSQL SQL 审核工具 (inception安装步骤)
http://blog.csdn.net/wulantian/article/category/5825391
- Yearning v1.3.0 发布,Web 端 SQL 审核平台
企业级MYSQL web端 SQL审核平台. Website 官网 www.yearning.io Feature 功能 数据库字典自动生成 SQL查询 查询工单 导出 自动补全,智能提示 查询语句审 ...
- SQL审核平台Yearning部署
SQL审核平台Yearning部署 Yearning优势: Yearning SQL 审计平台 基于Vue.js与Django的整套mysql-sql审核平台解决方案.提供基于Inception的S ...
- centos 7 安装sql 审核工具 inception + archer
系统环境: Centos7 + python2.7 + python3 .... 下载 源码地址:https://github.com/mysql-inception/inception Incept ...
- inception+archery SQL审核平台
关闭防火墙和selinux 宿主机安装mysql,创建archery数据库,并给所有权限,允许远程连接到该数据库 grant all privileges on *.* to 'root'@'%' i ...
- MySQL自动化审核平台部署说明
背景: 关于MySQL的审核的重要性就不说明了,本文的自动化审核是通过Inception和SQLAdvisor实现的,具体的使用可以看它们各自的说明文档.这里大致介绍下如何部署和使用它们,其实该文章也 ...
- Yearning 介绍(SQL审核平台)
介绍 Yearning SQL 审计平台 基于Vue.js与Django的整套mysql-sql审核平台解决方案.提供基于Inception的SQL检测及执行. GitHub:https://gith ...
- SQL审核平台-Yearning安装部署实践
相关文档: https://guide.yearning.io/ yearning简介 http://python.yearning.io/install/ yearning安装 Yearning ...
随机推荐
- Vue(二) 计算属性
模板内的表达式常用于简单的运算,当过长或逻辑复杂时,难以维护,计算属性就是解决该问题的 什么是计算属性 表达式如果过长,或逻辑更为复杂,就会变得臃肿甚至难以维护,比如: <div> {{ ...
- CAD{绘制坡道)(绘制楼梯)5.26
“楼梯其他”“坡道”编辑坡道的各项数据, 三维图中坡道反了.在平面图中镜像,“MI"镜像坡道.给坡道一个箭头引注, 绘制楼梯:”楼梯其他“”双跑楼梯“编辑参数,绘制楼梯,双击楼梯,改变成首层 ...
- 跟随我在oracle学习php(4)
制作html表单 客户端(每个用户的计算机)在浏览网页时,都会向服务器(后台)端索要数据,然后将得 到的数据呈现在浏览器当中.除了索要数据之外,有时客户端也希望能够向服务器端发送 一些数据. 这时我们 ...
- asp.net core mvc HTTP Error 502.5 - Process Failure
HTTP Error 502.5 - Process Failure Common causes of this issue: The application process failed to st ...
- 读取磁盘:CHS方式
读取磁盘:CHS方式 BIOS读取磁盘 读取磁盘也是调用BIOS: 中断命令: INT 13H 读取扇区的入口参数为 AH = 02H 功能参数,读取扇区 AL = 扇区数 CH = 柱面 CL = ...
- mariadb安装和一些sql基础
MariaDB安装 yum -y install mariadb mariadb-server 启动 systemctl start mariadb systemctl enabl ...
- AndroidStudio连不上Android设备真机
AndroidStudio连不上Android设备真机 刚好遇到这个问题,查阅了很多资料,看到有人分享了引起该问题的几个原因,我总结了一下: 1.手机设置问题.开USB调试 方法:手机设置-开发人员调 ...
- Sed+Grep 快速替换查找字段(批量替换字符串)
格式: sed -i "s/查找字段/替换字段/g" `grep 查找字段 -rl路径` 命令分解: grep 查找字段 -rl路径 列出”路径”中” 查找字段” 的所有文件 ...
- linux c 获取console 结果
getLine(char *line, const char *cmd) { FILE *pf = popen(cmd, "r"); if (pf == NULL) { ; } f ...
- IC卡冷复位时序
冷复位(cold reset):当提供给IC卡的电源电压和其他信号从静止状态中复苏且收到复位信号后,IC卡产生的复位. 在触点激活后,终端将发出一个冷复位信号,并从IC卡获得一个复位应答信号,过程如下 ...