自动化autosql审核平台--基于Yearning可视化
解决依赖包
yum -y install cmake ncurse ncurses-devel gcc gcc-c++ openssl-devel http-parser libicu nginx wget m4
一、升级PYTHON版本
1.下载并安装Python3.6.3
# wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
# tar -zxvf Python-3.6.3.tgz
# cd Python- 3.6.3/
# ./configure
# make
# make install
2.将原本python重命名,用python3.6取代python2.7
# mv /usr/bin/python /usr/bin/python.bak
# ln -s /usr/local/bin/python3 /usr/bin/python
3.更改配置,否则原本yum的功能会无法使用
# vim /usr/bin/yum
# vim /usr/libexec/urlgrabber-ext-down
备注:被将#!/usr/bin/python改为#! /usr/bin/python2.7,保存退出即可。
4.安装常用套件
pip install numpy scipy matplotlib scikit-learn ##这个过程 时间会比较9
##若提示pip找不到相应的版本,在/usr/local/lib/python3.6/site-packages 确定安装PIP版本,默认为:/bin/pip 删除或者mv,手动安装pip版本路径为:/usr/local/bin/pip
版本验证:
# pip -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages/pip-9.0.1-py3.6.egg (python 3.6)
##以及后面升级PIP版本都不会有问题,在pip install 时候先下载pip版本进行安装
二、安装bison-2.5.1版本,不要使用YUM 安装
解压包
#.configure
# make && make install
验证是否安装成功
# bison -V
bison (GNU Bison) 2.5.1
Written by Robert Corbett and Richard Stallman.
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
三、安装INCEPTION
# unzip inception-master.zip
# cd inception-master
# cmake .
#cmake -DWITH_DEBUG=OFF -DCMAKE_INSTALL_PREFIX=/usr/local/inception -DMYSQL_DATADIR=/home/mysql/inception -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"
# make && make install
# sh -x inception_build.sh debug
报错如下:
-- Build files have been written to: /root/inception-master
+ '[' x '!=' Xcode ']'
+ make install
make: *** 没有规则可以创建目标“install”。 停止。
# sh inception_build.sh debug [linux]
make: *** 没有规则可以创建目标“install”。 停止。
解决办法:# make -j6 && make install
再次执行sh inception_build.sh debug [linux] 一样问题。有人说是BISON问题
##这里需要注意 只要按上面的操作 执行make && make install 执行不报错即可,可跳过sh inception_build.sh debug [linux] 操作,需要验证在TCP/IP是否能够连接INCEPTIONS,若无法连接会导致和Yearning无法提交审核,提示无权限
添加配置文件
#touch /etc/inc.cnf
[inception]
general_log=1
general_log_file=/home/mysql/inception/inc.log
port=6669
socket=/tmp/inc.socket
character-set-client-handshake=0
character-set-server=utf8mb4
inception_remote_system_password=backup
inception_remote_system_user=backup
inception_remote_backup_port=3306
inception_remote_backup_host=192.168.22.130
inception_support_charset=utf8,utf8mb4,latin1
inception_enable_nullable=0
inception_check_primary_key=1
inception_check_column_comment=1
inception_check_table_comment=1
inception_osc_min_table_size=1
inception_osc_bin_dir=/usr/bin
inception_osc_chunk_time=0.1
inception_ddl_support=1
inception_enable_blob_type=1
inception_check_column_default_value=1
启动:
/usr/local/inception/bin/Inception --defaults-file=/etc/inc.cnf &
登陆
mysql -uroot -P6669 -h127.0.0.1
变量查看
inception get variables;
验证INCEPTION,可以看日志
#coding=utf-8
import MySQLdb
#def table_structure(mysql_structure):
sql='/*--user=inc;--password=root123;--host=172.16.32.11;--execute=1;--port=3307;*/\
inception_magic_start;\
use ms;\
CREATE TABLE `alifeba_user` (\
`ID` int(11) unsigned NOT NULL auto_increment comment"aaa",\
`username` varchar(50) NOT NULL Default "" comment"aaa",\
`realName` varchar(50) NOT NULL Default "" comment"aaa",\
`age` int(11) NOT NULL Default 0 comment"aaa",\
PRIMARY KEY (`ID`)\
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COMMENT="AAAA";\
inception_magic_commit;'
#sql = sql1 + mysql_structure + sql2
try:
conn=MySQLdb.connect(host='172.16.32.152',user='inc',passwd='root123',port=6669, charset="utf8")
cur=conn.cursor()
print sql,cur
ret=cur.execute(sql)
result=cur.fetchall()
num_fields = len(cur.description)
field_names = [i[0] for i in cur.description]
print field_names
for row in result:
print row[0], "|",row[1],"|",row[2],"|",row[3],"|",row[4],"|",row[5],"|",row[6],"|",row[7],"|",row[8],"|",row[9],"|",row[10]
cur.close()
conn.close()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
#return result[1][4].split("\n")
#if __main __ == "__name__":
# table_structure()
安装Yearning
tar -zxvf Yearning.tar.gz
mv Yearning yearning
cd yearning/src/
cp deploy.conf.template deploy.conf
参数设置
[mysql]
db = Yearning ##需要在指定DB里添加
address = 192.168.22.130
port = 3306
username = yearning
password = yearning
[host]
ipaddress = 192.168.22.130:80
[Inception]
ip = 192.168.22.130
port = 6669
user = admin
password = admin
backupdb = 192.168.22.130
backupport = 3306
backupuser = backup
backuppassword = backup
[LDAP]
LDAP_SERVER =
LDAP_SCBASE =
LDAP_DOMAIN =
LDAP_TYPE = 1
[email]
username =
password =
smtp_server =
smtp_port = 25
[sql]
limit = 1000
[webhook]
dingding =
####参数介绍
[mysql]
db = 所创建的库名
address = 数据库地址
port = 数据库端口
password = 数据库密码
username = 数据库用户
[host]
ipaddress = 服务器ip地址:端口 (涉及跨域十分重要!!设置不正确将无法登陆!!)
如 本机地址为192.168.1.2 nginx设置端口为80
则应填写为 192.168.1.2: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
LDAP_TYPE = 1 1 通过域名进行ldap认证 0 通过uid进行ldap认证
[email] 邮箱推送相关设置
username = 邮箱发件账号 如 xxxx@163.com
password = 邮箱发件账号密码
smtp_server = 邮箱stmp地址, 具体地址请咨询对应邮箱提供者
#执行
pip install -r requirements.txt
##若提示django版本问题,可以requirements.txt包的版本进行修改
#复制文件connections.py、cursors.py 到PYTHON3.6目录下替换文件##包目录下
cp /root/yearning/install/connections.py /usr/local/lib/python3.6/site-packages/pymysql/
cp /root/yearning/install/cursors.py /usr/local/lib/python3.6/site-packages/pymysql/
cd /root/yearning/src
初始化数据信息:
python3 manage.py makemigrations core && python3 manage.py migrate core
添加管理员用户
echo "from core.models import Account;Account.objects.create_user(username='admin', password='admin8866', group='admin',is_staff=1)" | python3 manage.py shell
初始化权限
echo "from core.models import grained;grained.objects.get_or_create(username='admin', permissions={'person': [], 'ddl': '1', 'ddlcon': [], 'dml': '1', 'dmlcon': [], 'dic': '1', 'diccon': [], 'dicedit': '0', 'query': '1', 'querycon': [], 'user': '1', 'base': '1', 'dicexport': '0'})" | python3 manage.py shell
拷贝WEB文件到nginx的html目录下,若用yum安装在/usr/share/nginx/html
cp -rf /root/yearning/webpage/dist/* /usr/share/nginx/html/
#启动:
python3 manage.py runserver 0.0.0.0:8000 & ##这个服务需要后台一直运行 可以使用nohup
访问:http://ip
在管理中,添加DB需要对用户授权,指定用户具备哪些权限。