自动化SQL操作平台,sql审核系统

自动化SQL操作平台

系统环境要求:

python:3.6

django:1.8

mysql : 5.6及以上

linux : 64位linux操作系统均可


环境准备:

1、克隆代码到本地: git clone 或 下载zip包

2、安装mysql 5.6实例,请注意保证mysql数据库默认字符集为utf8或utf8mb4

3、安装inception

1、安装 Python3

1.1、安装依赖包

yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git

1.2、编译安装python

<code>cd /opt/<code>
<code>wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz/<code>
<code>tar xvf Python-3.6.1.tar.xz  && cd Python-3.6.1/<code>
<code>./configure && make && make install/<code>

python3

自动化SQL操作平台,sql审核系统

2、安装Django

pip3 install Django==1.8.17


或单独安装:

wget


tar -zxvf Django-1.8.17.tar.gz

cd Django-1.8.17

python3 setup.py install


python3

>>> import django

>>> django.VERSION

自动化SQL操作平台,sql审核系统

3、安装Crypto和pymysql

pip3 install Crypto

pip3 install pycrypto

pip3 install pymysql


vi /usr/local/lib/python3.6/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'

修改后如下图:

自动化SQL操作平台,sql审核系统

4、安装mysql5.7

yum -y install yum-utils

配置yum源:

cat /etc/yum.repos.d/mysql.repo

# Enable to use MySQL 5.7

[mysql57-community]

name=MySQL 5.7 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

查看可安装的mysql版本:

yum repolist all|grep mysql

安装MySQL,默认最新版本:

# yum install mysql-community-server -y

启动MySQL服务:

# systemctl start mysqld

# systemctl status mysqld

root账户默认密码存储在错误日志中:

# grep 'temporary password' /var/log/mysqld.log

# mysql -uroot -p

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1qaz@WSX';

注意:密码要求包含一个大写字母,一个小写字母,一位数字和一个特殊字符,并且密码长度至少为8个字符。

# vi /etc/my.cnf

[mysql]

socket = /var/lib/mysql/mysql.sock

[mysqld]

user = mysql

port = 3306

datadir = /var/lib/mysql

socket = /var/lib/mysql/mysql.sock

bind-address = 0.0.0.0

pid-file = /var/run/mysqld/mysqld.pid

character-set-server = utf8

collation-server = utf8_general_ci

log-error = /var/log/mysqld.log


max_connections = 10240

open_files_limit = 65535

innodb_buffer_pool_size = 3G

innodb_flush_log_at_trx_commit = 2

innodb_log_file_size = 256M


# systemctl restart mysqld

5、配置archer

5.1、拉取代码

git clone #或者在github直接下载zip包

cd /tmp

unzip archer-master.zip

mkdir -p /opt/archer

scp -r /tmp/archer-master/* /opt/archer/

cd /opt/archer

自动化SQL操作平台,sql审核系统

5.2、创建archer DB和inception DB

mysql -uroot -p

mysql> create database archer;

mysql> grant all on archer.* to archer_rw@'%' identified by '1Archer_rw';

mysql> flush privileges;


mysql> create database inception_db;

mysql> grant all on inception_db.* to incep_rw@'%' identified by '1Incep_rw';

mysql> flush privileges;

5.3、修改/opt/archer/archer/settings.py,如下内容:

cd /opt/archer/archer

vi settings.py

# 该项目本身的mysql数据库地址

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.mysql',

'NAME': 'archer',

'USER': 'archer_rw',

'PASSWORD': '1Archer_rw',

'HOST': '192.168.0.13',

'PORT': '3306'

}

}

# inception组件所在的地址

INCEPTION_HOST = '192.168.0.13'

INCEPTION_PORT = '6669'


# 查看回滚SQL时候会用到,这里要告诉archer去哪个mysql里读取inception备份的回滚信息和SQL.

# 注意这里要和inception组件的inception.conf里的inception_remote_XX部分保持一致.

INCEPTION_REMOTE_BACKUP_HOST = '192.168.0.13'

INCEPTION_REMOTE_BACKUP_PORT = 3306

INCEPTION_REMOTE_BACKUP_USER = 'incep_rw'

INCEPTION_REMOTE_BACKUP_PASSWORD = '1Incep_rw'

5.4、通过model创建archer本身的数据库表

cd /opt/archer

cat requirements.txt

certifi==2017.7.27.1

chardet==3.0.4

#Django==1.8.17

idna==2.6

Naked==0.1.31

#pycrypto==2.6.1

#PyMySQL==0.7.11

PyYAML==3.12

requests==2.18.4

shellescape==3.4.1

simplejson==3.14.0

urllib3==1.22

django-admin-bootstrapped==2.5.7

django-apscheduler==0.2.8


pip3 install -r requirements.txt

python3 manage.py makemigrations

自动化SQL操作平台,sql审核系统

python3 manage.py makemigrations sql

自动化SQL操作平台,sql审核系统

python3 manage.py migrate

自动化SQL操作平台,sql审核系统

查看表是否创建成功:

mysql -h192.168.0.13 -uarcher_rw -p'1Archer_rw' -P3306 -D archer -e "show tables;"

自动化SQL操作平台,sql审核系统

5.5、创建django admin管理员

python3 manage.py createsuperuser

[root@localhost archer]# python3 manage.py createsuperuser

Username: admin

Email address: [email protected]

Password: admin123

Password (again): admin123

Superuser created successfully.

6、启动archer

cat debug.sh

#!/bin/bash


python3 manage.py runserver 0.0.0.0:9123 --insecure


sh debug.sh &

自动化SQL操作平台,sql审核系统

7、创建archer系统登录用户

7.1、登陆并添加用户

通过浏览器访问

可以看到django登录界面:

自动化SQL操作平台,sql审核系统

使用上面第5步创建的用户名密码(admin/admin123)登录:

自动化SQL操作平台,sql审核系统

点击右侧Add用户配置,用户名密码自定义,至少创建一个工程师和一个审核人(用admin用户可以登录)后续新的工程师和审核人用户请用LDAP导入sql_users表或django admin增加:

自动化SQL操作平台,sql审核系统

自动化SQL操作平台,sql审核系统

自动化SQL操作平台,sql审核系统

自动化SQL操作平台,sql审核系统

7.2、配置主库地址

通过浏览器访问http://192.168.0.13:9123/admin/sql/master_config

点击右侧Add master_config。这一步是为了告诉archer你要用inception去哪些mysql主库里执行SQL,所用到的用户名密码、端口等。

自动化SQL操作平台,sql审核系统

自动化SQL操作平台,sql审核系统

自动化SQL操作平台,sql审核系统

7.3、正式访问主页

http://192.168.0.13:9123/login/

自动化SQL操作平台,sql审核系统

自动化SQL操作平台,sql审核系统

mysql –uroot -p

mysql> grant select,create,insert on *.* to incep_rw@'%' identified by '1Incep_rw';


分享到:


相關文章: