Yearning 安装:

安装Nginx
yum install nginx -y

按照顺序安装MySQL
mysql-community-common-5.7.22-1.el6.x86_64.rpm
mysql-community-libs-5.7.22-1.el6.x86_64.rpm
mysql-community-client-5.7.22-1.el6.x86_64.rpm
mysql-community-server-5.7.22-1.el6.x86_64.rpm

Python 3.6安装

解压
tar -xvf Python-3.6.4.tar.xz

创建目录
mkdir -p /usr/local/python/3.6.4/lib

编译
cd Python-3.6.4
./configure --enable-shared --prefix=/usr/local/python/3.6.4 LDFLAGS="-Wl,-rpath /usr/local/python/3.6.4/lib"
make && make install

软链接
cp /usr/bin/python /usr/bin/python2.6.6
ln -fs /usr/local/python/3.6.4/bin/python3.6 /usr/bin/python
ln -fs /usr/local/python/3.6.4/bin/pip3 /usr/bin/pip

yum修改
vi /usr/bin/yum
将头部 #!/usr/bin/python 修改为 #!/usr/bin/python2.6.6

Inception安装
Inception是集审核、执行、回滚于一体的一个自动化运维系统,它是根据MySQL代码修改过来的,用它可以很明确的,详细的,准确的审核MySQL的SQL语句,它的工作模式和MySQL完全相同,可以直接使用MySQL客户端来连接,但不需要验证权限,它相对应用程序(上层审核流程系统等)而言,是一个服务器,在连接时需要指定服务器地址及Inception服务器的端口即可,而它相对要审核或执行的语句所对应的线上MySQL服务器来说,是一个客户端,它在内部需要实时的连接数据库服务器来获取所需要的信息,或者直接在在线上执行相应的语句及获取binlog等,Inception就是一个中间性质的服务。

依赖包安装
yum install gcc gcc-c++ cmake bison openssl-devel ncurses-devel git

下载源码包
git clone https://github.com/mysql-inception/inception.git(已经闭源,但是网上还能找到闭源之前的包)

编译安装Inception
mkdir -p /usr/local/inception

mkdir -p /inception/{data,logs}

unzip master.zip -d /inception

cd /inception/inception-master
cmake -DWITH_DEBUG=OFF -DCMAKE_INSTALL_PREFIX=/usr/local/inception -DMYSQL_DATADIR=/inception/data -DWITH_SSL=yes -DCMAKE_BUILD_TYPE=RELEASE -DWITH_ZLIB=bundled -DMY_MAINTAINER_CXX_WARNINGS="-Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Wno-unused-parameter -Woverloaded-virtual" -DMY_MAINTAINER_C_WARNINGS="-Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Wdeclaration-after-statement"

CMake Error: The source "/inception/inception-master/CMakeLists.txt" does not match the source "/opt/inception-master/CMakeLists.txt" used to generate cache

rm -rf CMakeLists.txt再执行

make && make install

创建inception配置文件
--编辑参数文件

vim /etc/inc.cnf

[inception]

general_log=1 #这个参数就是原生的MySQL的参数,用来记录在Inception服务上执行过哪些语句,用来定位一些问题等

general_log_file=/usr/local/inception/data/inception.log #设置general log写入的文件路径

port=6669 #Inception的服务端口

socket=/usr/local/inception/data/inc.socket #Inception的套接字文件存放位置

character-set-server=utf8 #mysql原生参数

#Inception 审核规则

inception_check_autoincrement_datatype=1 #当建表时自增列的类型不为int或者bigint时报错

inception_check_autoincrement_init_value=1 #当建表时自增列的值指定的不为1,则报错

inception_check_autoincrement_name=1 #建表时,如果指定的自增列的名字不为ID,则报错,说明是有意义的,给提示

inception_check_column_comment=1 #建表时,列没有注释时报错

inception_check_column_default_value=0 #检查在建表、修改列、新增列时,新的列属性是不是要有默认值

inception_check_dml_limit=1 #在DML语句中使用了LIMIT时,是不是要报错

inception_check_dml_orderby=1 #在DML语句中使用了Order By时,是不是要报错

inception_check_dml_where=1 #在DML语句中没有WHERE条件时,是不是要报错

inception_check_identifier=1 #打开与关闭Inception对SQL语句中各种名字的检查,如果设置为ON,则如果发现名字中存在除数字、字母、下划线之外的字符时,会报Identifier "invalidname" is invalid, valid options: [a-z,A-Z,0-9,_].

inception_check_index_prefix=1 #是不是要检查索引名字前缀为"idx_",检查唯一索引前缀是不是"uniq_"

inception_check_insert_field=1 #是不是要检查插入语句中的列链表的存在性

inception_check_primary_key=1 #建表时,如果没有主键,则报错

inception_check_table_comment=0 #建表时,表没有注释时报错

inception_check_timestamp_default=0 #建表时,如果没有为timestamp类型指定默认值,则报错

inception_enable_autoincrement_unsigned=1 #自增列是不是要为无符号型

inception_enable_blob_type=0 #检查是不是支持BLOB字段,包括建表、修改列、新增列操作 默认开启

inception_enable_column_charset=0 #允许列自己设置字符集

inception_enable_enum_set_bit=0 #是不是支持enum,set,bit数据类型

inception_enable_foreign_key=0 #是不是支持外键

inception_enable_identifer_keyword=0 #检查在SQL语句中,是不是有标识符被写成MySQL的关键字,默认值为报警。

inception_enable_not_innodb=0 #建表指定的存储引擎不为Innodb,不报错

inception_enable_nullable=0 #创建或者新增列时如果列为NULL,不报错

inception_enable_orderby_rand=0 #order by rand时是不是报错

inception_enable_partition_table=0 #是不是支持分区表

inception_enable_select_star=0 #Select*时是不是要报错

inception_enable_sql_statistic=1 #设置是不是支持统计Inception执行过的语句中,各种语句分别占多大比例,如果打开这个参数,则每次执行的情况都会在备份数据库实例中的inception库的statistic表中以一录存储这次操作的统计情况,每次操作对应一条记录,这条记录中含有的信息是各种类型的语句执行次数情况。

inception_max_char_length=16 #当char类型的长度大于这个值时,就提示将其转换为VARCHAR

inception_max_key_parts=5 #一个索引中,列的最大个数,超过这个数目则报错

inception_max_keys=16 #一个表中,最大的索引数目,超过这个数则报错

inception_max_update_rows=10000 #在一个修改语句中,预计影响的最大行数,超过这个数就报错

inception_merge_alter_table=1 #在多个改同一个表的语句出现是,报错,提示合成一个

#inception 支持 OSC 参数

inception_osc_bin_dir=/user/bin #用于指定pt-online-schema-change脚本的位置,不可修改,在配置文件中设置

inception_osc_check_interval=5 #对应OSC参数--check-interval,意义是Sleep time between checks for --max-lag.

inception_osc_chunk_size=1000 #对应OSC参数--chunk-size

inception_osc_chunk_size_limit=4 #对应OSC参数--chunk-size-limit

inception_osc_chunk_time=0.1 #对应OSC参数--chunk-time

inception_osc_critical_thread_connected=1000 #对应参数--critical-load中的thread_connected部分

inception_osc_critical_thread_running=80 #对应参数--critical-load中的thread_running部分

inception_osc_drop_new_table=1 #对应参数--[no]drop-new-table

inception_osc_drop_old_table=1 #对应参数--[no]drop-old-table

inception_osc_max_lag=3 #对应参数--max-lag

inception_osc_max_thread_connected=1000 #对应参数--max-load中的thread_connected部分

inception_osc_max_thread_running=80 #对应参数--max-load中的thread_running部分

inception_osc_min_table_size=0 # 这个参数实际上是一个OSC的开关,如果设置为0,则全部ALTER语句都走OSC,如果设置为非0,则当这个表占用空间大小大于这个值时才使用OSC方式。单位为M,这个表大小的计算方式是通过语句:"select (DATA_LENGTH + INDEX_LENGTH)/1024/1024 from information_schema.tables where table_schema = 'dbname' and table_name = 'tablename'"来实现的

inception_osc_on=0 #一个全局的OSC开关,默认是打开的,如果想要关闭则设置为OFF,这样就会直接修改

inception_osc_print_none=1 #用来设置在Inception返回结果集中,对于原来OSC在执行过程的标准输出信息是不是要打印到结果集对应的错误信息列中,如果设置为1,就不打印,如果设置为0,就打印。而如果出现错误了,则都会打印

inception_osc_print_sql=1 #对应参数--print

#备份服务器信息,注意改成你的机器.用于回滚。

inception_remote_system_password=P@ssw0rd

inception_remote_system_user=incep_rw

inception_remote_backup_port=3306

inception_remote_backup_host=10.10.3.70

inception_support_charset=utf8 #表示在建表或者建库时支持的字符集,如果需要多个,则用逗号分隔,影响的范围是建表、设置会话字符集、修改表字符集属性等

启动Inception程序
cd /usr/local/inception/bin

./Inception --defaults-file=/etc/inc.cnf &
[1] 11179
[root@b28-11-92 bin]# 2019-06-21 15:00:31 0 [Note] Welcome to use Inception2.1.50
2019-06-21 15:00:31 11179 [Note] Server hostname (bind-address): '*'; port: 6669
2019-06-21 15:00:31 11179 [Note] IPv6 is available.
2019-06-21 15:00:31 11179 [Note] - '::' resolves to '::';
2019-06-21 15:00:31 11179 [Note] Server socket created on IP: '::'.

查看Inception进程
ps -ef | grep Inception
root 11179 30011 0 15:00 pts/1 00:00:00 ./Inception --defaults-file=/etc/inc.cnf

测试
mysql -uroot -h127.0.0.1 -P6669
连接成功后执行 inception get variables;
输出了所有的变量,表示已经启动成功了

Yearning 安装
git clone https://github.com/cookieY/Yearning.git

登录MySQL创建库yearning库
create database Yearning DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

安装相应python依赖库
cd Yearning/src
pip install -r requirements.txt
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting Django==2.1.5 (from -r requirements.txt (line 1))
Could not fetch URL https://pypi.python.org/simple/django/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement Django==2.1.5 (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for Django==2.1.5 (from -r requirements.txt (line 1))

修改Setup文件
Python-3.6.4/Modules

vim Setup
#Socket module helper for socket(2)
_socket socketmodule.c timemodule.c

#Socket module helper for SSL support; you must comment out the other
#socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

重新编译
cd Python-3.6.4
./configure --enable-shared --prefix=/usr/local/python/3.6.4 LDFLAGS="-Wl,-rpath /usr/local/python/3.6.4/lib"
make
make install

配置,编辑Yearning/src/deploy.conf文件
[mysql]
db = 所创建的库名
address = 数据库地址
port = 数据库端口
password = 数据库密码
username = 数据库用户

[host]
ipaddress = 服务器ip地址:端口 (涉及跨域十分重要!!设置不正确将无法登陆!!)
如 本机地址为192.168.137.13 nginx设置端口为80
则应填写为 192.168.137.13:80 之后通过该地址访问平台。

[Inception]
ip = Inception地址
port = Inception端口
user = Inception用户名
password = Inception密码
backupdb = 备份数据库地址
backupport = 备份数据库端口
backupuser = 备份数据库用户名
backuppassword = 备份数据库密码

[LDAP] LDAP相关设置
LDAP_SERVER = LDAP服务地址
LDAP_SCBASE = LDAP dc 设置 如 dc=xxx,dc=com
LDAP_DOMAIN = LDAP域名 如 xxx.com

[email] 邮箱推送相关设置
username = 邮箱发件账号 如 xxxx@163.com
password = 邮箱发件账号密码
smtp_server = 邮箱stmp地址, 具体地址请咨询对应邮箱提供者

初始化数据库
python manage.py makemigrations
python manage.py migrate

若报错ModuleNotFoundError: No module named 'Crypto'
pip install pycrypto
重新初始化数据库
python manage.py makemigrations

python manage.py migrate

添加初始化用户
echo "from core.models import Account;Account.objects.create_user(username='admin', password='admin123456', group='admin',is_staff=1)" | python manage.py shell

初始化权限
echo "from core.models import grained;grained.objects.get_or_create(username='admin', permissions={'ddl': '1', 'ddlcon': [], 'dml': '1', 'dmlcon': [], 'dic': '1', 'diccon': [], 'dicedit': '0', 'query': '1', 'querycon': [], 'user': '1', 'base': '1', 'dicexport': '0'})" | python manage.py shell

复制编译好的静态文件到nginx html目录下(dist目录通过npm run build生成)
cd Yearning/webpage/dist
cp -rf * /usr/share/nginx/html/

/etc/init.d/nginx restart

启动django
cd Yearning/src

python manage.py runserver 0.0.0.0:8000

访问首页http://192.168.17.77

注意事项:
使用默认账号: admin 密码:admin123456登陆即可使用,可能会出现登陆不了的情况(无法跳转页面),这是由于跨域的问题,解决这个问题可以参考:http://blog.csdn.net/apple9005/article/details/54427902

注意事项
默认超级管理员只拥有各个页面的访问权限,其他的权限需自行增加!详情请查看使用说明用户管理
由于Inception 并不原生支持pymysql,所以需更改pymysql相关源码
修改 $PYTHON_HOME/lib/python3.6/site-packages/pymysql下
connections.py 和 cursors.py 两个文件

找到 connections.py 786行
if int(self.server_version.split('.', 1)[0]) >= 5:

self.client_flag |= CLIENT.MULTI_RESULTS

更改为:
try:

if int(self.server_version.split('.', 1)[0]) >= 5:

self.client_flag |= CLIENT.MULTI_RESULTS

except:

if self.server_version.split('.', 1)[0] >= 'Inception2':

self.client_flag |= CLIENT.MULTI_RESULTS

找到 cursors.py

if self._result and (self._result.has_next or not self._result.warning_count):

return

更改为
if self._result:

return

Yearning + Inception SQL审核平台搭建的更多相关文章

  1. Docker Yearning + Inception SQL审核平台搭建

    [一]安装[1.1]系统环境系统环境:CentOS Linux release 7.6.1708 (Core)系统内存:4G系统内核:1Python:3.6.4关闭iptables and selin ...

  2. Yearning 介绍(SQL审核平台)

    介绍 Yearning SQL 审计平台 基于Vue.js与Django的整套mysql-sql审核平台解决方案.提供基于Inception的SQL检测及执行. GitHub:https://gith ...

  3. SQL审计 Yearning 介绍(SQL审核平台)

    yearning SQL 是一个成熟的SQL审计平台

  4. 基于Inception搭建MySQL SQL审核平台Yearing

    基于Inception搭建MySQL SQL审核平台Yearing Inception 1. Inceptionj简介 2. Inception安装 2.1 下载和编译 2.2 启动配置 Yearni ...

  5. SQL审核平台Yearning部署

    SQL审核平台Yearning部署  Yearning优势: Yearning SQL 审计平台 基于Vue.js与Django的整套mysql-sql审核平台解决方案.提供基于Inception的S ...

  6. Yearning v1.3.0 发布,Web 端 SQL 审核平台

    企业级MYSQL web端 SQL审核平台. Website 官网 www.yearning.io Feature 功能 数据库字典自动生成 SQL查询 查询工单 导出 自动补全,智能提示 查询语句审 ...

  7. Inception SQL审核注解

    Inception SQL审核注解 1.建表语句 建表语句检查项 表属性的检查项 这个表不存在 对于create table like,会检查like的老表是不是存在. 对于create table ...

  8. SQL审核平台-Yearning安装部署实践

    相关文档: https://guide.yearning.io/ yearning简介 http://python.yearning.io/install/  yearning安装 Yearning ...

  9. inception+archery SQL审核平台

    关闭防火墙和selinux 宿主机安装mysql,创建archery数据库,并给所有权限,允许远程连接到该数据库 grant all privileges on *.* to 'root'@'%' i ...

随机推荐

  1. 搭建 Seafile 专属网盘

    准备域名 任务时间:15min ~ 20min 域名注册 如果您还没有域名,可以在腾讯云上选购,过程可以参考下面的视频. 视频 - 在腾讯云上购买域名 域名解析 域名购买完成后, 需要将域名解析到实验 ...

  2. 1.4.1 安装Python扩展库

    Python之所以得到各行业领域工程师.策划师以及管理人员的青睐,与涉及各行业各领域开发的扩展库也有很大关系,不仅数量众多.功能强大,关键是用起来很方便.虽然Python标准库已经拥有了非常强大的功能 ...

  3. jdk8--collect总结

    https://blog.csdn.net/u014351782/article/details/53818430 一,collect是一个终端操作,它接收的参数是将流中的元素累积到汇总结果的各种方式 ...

  4. [BZOJ 4999]This Problem Is Too Simple!

    [BZOJ 4999]This Problem Is Too Simple! 题目 给您一颗树,每个节点有个初始值. 现在支持以下两种操作: 1. C i x(0<=x<2^31) 表示将 ...

  5. hdu_1013_Digital Roots_201310121652

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. Spring MVC-表单(Form)标签-错误处理(Error Handling)示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_errors.htm 说明:示例基于Spring MVC 4.1.6. 以下示例显 ...

  7. keras 与tensorflow 混合使用

    keras 与tensorflow 混合使用 tr:nth-child(odd) > td, .table-striped tbody > tr:nth-child(odd) > t ...

  8. MSP430WARE++的使用2:RSP1 driver的调用方法

        MSP430WARE是一套基于C++语言的开源的MSP430层次化软件架构,支持多种外设.本文将介绍雷达測速芯片RSP1驱动程序的调用方法.     1.硬件原理图      採用下图所看到的 ...

  9. window.open()方法(弹出层)

    1, 最主要的弹出窗体代码    window.open('page.html'); 2, 经过设置后的弹出窗体    window.open('page.html', 'newwindow', 'h ...

  10. OC基础回想(十一)类别

         在编写面向对象的程序时,常常要为现有的类加入一些新的行为,通常採用创建子类的方法. 只是有时候子类不方便.比方,想为NSString类加入一个新的行为,可是NSString实际上仅仅是一个类 ...