一、Inception安装
1、安装相关依赖包
yum install bison ncurses-libs libncurses5-devel ncurses-devel wget git cmake openssl gcc-c++ gcc openssl-devel MySQL-python -y
注意:centos7 系统自带的bison的版本过高,在后面测试的时候会报错!
查看版本: bison -V
下载地址: wget http://ftp.gnu.org/gnu/bison/bison-2.5.1.tar.gz
cd bison-2.5.1
./configure
make && make install
安装完成后:bison -V
cd /opt/
git clone https://github.com/mysql-inception/inception
注意:centos6.5可能git clone报错,升级git版本,升级:依赖yum update nss,就正常了:
升级参考:https://blog.csdn.net/zzpzheng/article/details/52132385
cd inception
sh inception_build.sh debug
debug就是编译目录,编译后所有的生成文件都在这个目录下面,包括可执行文件Inception。可执行文件在debug/sql目录下面:
/opt/inception/debug/sql
[root@mysql sql]# ls
CMakeFiles dummy.bak Inception libbinlog.a librpl.a libsql.a Makefile sql_builtin.cc sql_yacc.h
cmake_install.cmake gen_lex_hash lex_hash.h libmaster.a libslave.a libsqlgunitlib.a share sql_yacc.cc
3、创建配置目录,将可执行文件Inception拷贝到/opt/inception/bin目录
[root@mysql sql]# mkdir -p /data/inception
[root@mysql sql]# mkdir -p /data/inception/bin
[root@mysql sql]# mkdir -p /data/inception/temp
[root@mysql sql]# cp Inception /data/inception/bin/
编辑配置文件:
[root@mysql sql]# cat /etc/inc.cnf
[inception]
general_log=1
general_log_file=/opt/inception/inception.log
port=6669
socket=/opt/inception/inc.socket
character-set-client-handshake=0
character-set-server=utf8
inception_remote_system_password=123456
inception_remote_system_user=root
inception_remote_backup_port=3306
inception_remote_backup_host=127.0.0.1
inception_support_charset=utf8mb4
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=/opt/inception/temp
inception_osc_chunk_time=0.1
inception_ddl_support=1
inception_enable_blob_type=1
inception_check_column_default_value=1
启动
[root@mysql sql]# nohup /data/inception/bin/Inception --defaults-file=/etc/inc.cnf &
[1] 2398
[root@mysql sql]# nohup: ignoring input and appending output to `nohup.out'
[root@mysql sql]# ps -ef|grep Inception
root 2414 23520 0 23:15 pts/0 00:00:00 /opt/inception/bin/Inception --defaults-file=/etc/inc.cnf
root 2419 23520 0 23:22 pts/0 00:00:00 grep Inception
登录验证
启动数据库,没有的可以自行安装。
# mysql -uroot -h127.0.0.1 -P6669
-bash: mysql: 未找到命令
注:没有安装MYSQL 数据库如下:
安装mysql:
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server
systemctl start mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: Inception2.1.50 1
Copyright (c) 2009-2014 Percona LLC and/or its affiliates
Copyright (c) 2000, 2014, 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.
mysql> inception get variables;
。。。。。
| version | Inception2.1.50 |
| version_comment | Source distribution |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
| wait_timeout | 28800 |
+------------------------------------------+-------------------------------------------------+
rows in set (0.00 sec)
mysql> exit
Bye
[root@mysql sql]#
二、web界面,安装Yearning
安装环境:python3.6 + mysql5.6 +nginx
安装python3.6
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
tar xvf Python-3.6.3.tgz
mkdir /usr/local/python3
cd Python-3.6.3/
./configure --prefix=/usr/local/python3 --with-ssl && make && make install
将/opt/python3/bin加入环境变量
##########将/opt/python3/bin加入环境变量#########
echo 'export PATH=$PATH:/opt/python3.2.3/bin/' >> ~/.bashrc
. ~/.bashrc
加入我们需要用它来代替系统的默认的 python,即运行 python就是运行 python3,而且要是 yum可以正常使用,我们可以执行如下步骤:
mv /usr/bin/python /usr/bin/python-old-backup
ln -s /opt/python3.2.3/bin/python3 /usr/bin/python
(ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3)
vim /usr/bin/yum
#将文件开头的
#!/usr/bin/python 修改为 #/usr/bin//usr/bin/python-old-backup
###############################
$$$$yum 出现 except OSError, e: ^ SyntaxError: invalid syntax$$$$
错误原因:
系统中装有多个版本的Python,Python脚本运行的时候版本冲突。
解决办法:(以下两步都要执行)
1. vim /usr/libexec/urlgrabber-ext-down将/usr/bin/python改为/usr/bin/python2.7。
2. vim /usr/bin/yum-config-manager
解决办法同上: #!/usr/bin/python换成 #!/usr/bin/python2.7
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server
systemctl start mysql
进入mysql
创建数据库并授权
CREATE DATABASE IF NOT EXISTS Yearning default charset utf8 COLLATE utf8_general_ci;
grant all on *.* to 'yearning'@'%' identified by 'yearning';
下载Yearning源码:
git clone https://github.com/cookieY/Yearning.git
cd /opt/Yearning/src
cp deploy.conf.template deploy.conf
更改配置文件:
[root@localhost src]# cat deploy.conf
[mysql]
db = Yearning
address = 127.0.0.1
port = 3306
username =yearning
password =yearning
[host]
ipaddress = 192.168.1.39:8080
[Inception]
ip = 127.0.0.1
port = 6669
user = root
password = x
backupdb = 127.0.0.1
backupport = 3306
backupuser = root
backuppassword =
[LDAP]
LDAP_SERVER =
LDAP_SCBASE =
LDAP_DOMAIN =
LDAP_TYPE = 1
[email]
username =
password =
smtp_server =
smtp_port = 25
[sql]
limit = 1000
[webhook]dingding =
安装相应python依赖库
/usr/local/python3/bin/pip3 install -r requirements.txt
初始化数据库
python3 manage.py makemigrations core && python3 manage.py migrate core
添加初始化用户
echo "from core.models import Account;Account.objects.create_user(username='admin', password='Jlkj#123', 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', 'user': '1', 'base': '1', 'dicexport': '0'})" | python3 manage.py shell
复制编译好的静态文件到nginx html目录下(如自行更改Nginx静态路径地址则将静态文件复制到对应静态文件目录下)
安装ningx
yum install -y nginx
######################
1.添加Nginx到YUM源
添加CentOS 7 Nginx yum资源库,打开终端,使用以下命令:
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.安装Nginx
在你的CentOS 7 服务器中使用yum
命令从Nginx源服务器中获取来安装Nginx:
sudo yum install -y nginx
Nginx将完成安装在你的CentOS 7 服务器中。
3.启动Nginx
刚安装的Nginx不会自行启动。运行Nginx:
sudo systemctl start nginx.service
如果一切进展顺利的话,现在你可以通过你的域名或IP来访问你的Web页面来预览一下Nginx的默认页面;
如果看到这个页面,那么说明你的CentOS 7 中 web服务器已经正确安装。
CentOS 7 开机启动Nginx
sudo systemctl enable nginx.service
更多systemctl命令可查看《systemctl命令用法》
Nginx配置信息
网站文件存放默认目录
/usr/share/nginx/html
网站默认站点配置
/etc/nginx/conf.d/default.conf
自定义Nginx站点配置文件存放目录
/etc/nginx/conf.d/
Nginx全局配置
/etc/nginx/nginx.conf
Nginx启动
nginx -c nginx.conf
Linux查看公网IP
您可以运行以下命令来显示你的服务器的公共IP地址:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
或者
最后安装nginx
下载Nginx: wget http://nginx.org/download/nginx-1.3.11.tar.gz /opt/
./configure && make && make install
启动nginx
启动:/usr/local/nginx/sbin/nginx
重启:kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
停止nginx:pkill -9 nginx
##########################
启动nginx
systemctl start nginx
cp -rf Yearning/webpage/dist/* $NGINX_HOME/html/
启动django
python3 manage.py runserver 0.0.0.0:8000
注:
是否受防火墙安全控制等。
将iptables和selinux关闭
以下4条命令清除iptables的配置
iptables -F
iptables -F -t nat
iptables -X
iptables -X -t nat
setenforce 0 #关闭selinux
访问首页http://IP此时使用我们初始化的账号密码:admin Jlkj#123 登录即可
三、archer安装
开发语言和推荐环境
python:3.4
django:1.8
mysql : 5.6及以上
linux : 64位linux操作系统均可
环境准备
1、克隆代码到本地: git clone https://github.com/jly8866/archer.git 或 下载zip包
2、安装mysql 5.6实例,请注意保证mysql数据库默认字符集为utf8或utf8mb4
3、安装inception
1、安装所需软件和模块
1)安装python3 (前面有)
2)安装setuptools
[root@mysql3 ~]# wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
[root@mysql3 ~]# tar -zxvf setuptools-19.6.tar.gz
[root@mysql3 ~]# cd setuptools-19.6
[root@mysql3 setuptools-19.6]# python3 setup.py build
[root@mysql3 setuptools-19.6]# python3 setup.py install
... ...
creating 'dist/setuptools-19.6-py3.4.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing setuptools-19.6-py3.4.egg
Copying setuptools-19.6-py3.4.egg to /opt/python3/lib/python3.4/site-packages
Adding setuptools 19.6 to easy-install.pth file
Installing easy_install script to /opt/python3/bin
Installing easy_install-3.4 script to /opt/python3/bin
Installed /opt/python3/lib/python3.4/site-packages/setuptools-19.6-py3.4.egg
Processing dependencies for setuptools==19.6
Finished processing dependencies for setuptools==19.6
可以看到安装到python3下面了
|
3)安装pip
[root@mysql3 ~]# wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
[root@mysql3 ~]# tar -zxvf pip-8.0.2.tar.gz
[root@mysql3 ~]# cd pip-8.0.2
[root@mysql3 pip-8.0.2]# python3 setup.py build
[root@mysql3 pip-8.0.2]# python3 setup.py install
... ...
creating 'dist/pip-8.0.2-py3.4.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pip-8.0.2-py3.4.egg
creating /opt/python3/lib/python3.4/site-packages/pip-8.0.2-py3.4.egg
Extracting pip-8.0.2-py3.4.egg to /opt/python3/lib/python3.4/site-packages
Adding pip 8.0.2 to easy-install.pth file
Installing pip3 script to /opt/python3/bin
Installing pip3.4 script to /opt/python3/bin
Installing pip script to /opt/python3/bin
Installed /opt/python3/lib/python3.4/site-packages/pip-8.0.2-py3.4.egg
Processing dependencies for pip==8.0.2
Finished processing dependencies for pip==8.0.2
|
4)安装Django
使用pip3安装:pip3 install Django==1.8.17
或者单独下载安装:
[root@mysql3 ~]# wget https://pypi.python.org/packages/44/41/bf93934082e9897a56a591a67bacbd9fb74e71244f3f42253432a9e627e6/Django-1.8.17.tar.gz#md5=e76842cdfbcb31286bd44f51e087a04c
[root@mysql3 ~]# tar -zxvf Django-1.8.17.tar.gz
[root@mysql3 ~]# cd Django-1.8.17
[root@mysql3 Django-1.8.17]# python3 setup.py install
[root@mysql3 Django-1.8.17]# python3
Python 3.4.1 (default, Apr 15 2017, 14:11:11)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> django.VERSION
(1, 8, 17, 'final', 0)
>>> exit()
|
注1:Django支持python版本对照表
Django版本 |
Python版本 |
1.5.x |
2.6.5 2.7 3.2 3.3 |
1.6.x |
2.6 2.7 3.2 3.3 |
1.7.x |
2.7 3.2 3.3 3.4 |
1.8.x |
2.7 3.2 3.3 3.4 3.5 LTS |
1.9.x |
2.7 3.4 3.5 |
1.10.x |
2.7 3.4 3.5 |
1.11.x 开发推荐 |
2.7 3.4 3.5 3.6 LTS |
2.0.x |
3.4 3.5 3.6 |
注1:查看python版本和django版本
python --version
在python shell中:
import sys
sys.version
import django
django.VERSION
5)安装GIT
yum -y install git
6)安装Crypto和pymysql
[root@mysql3 ~]# pip3 install Crypto
[root@mysql3 ~]# pip3 install pycrypto
[root@mysql3 ~]# pip3 install pymysql
[root@mysql3 ~]# vi /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’
修改后如下图:
2、配置archer
1、将archer-master源码解压到/opt/archer目录
[root@mysql3 archer-master]# mkdir -p /opt/archer
[root@mysql3 archer-master]# scp -r /src/archer-master /opt/archer/
[root@mysql3 archer-master]# cd /opt/archer/
[root@mysql3 archer]# ls
archer debug.sh docs manage.py README.md requirements.txt screenshots sql startup.sh stop.sh
|
2、创建archer DB和inception DB
create database archer;
grant all on archer.* to archer_rw@'%' identified by 'archer_rw'; create database inception_db; grant all on inception_db.* to incep_rw@'%' identified by 'incep_rw'; flush privileges;
|
3、修改/opt/archer/archer/settings.py,如下内容:
#该项目本身的mysql数据库地址
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'archer',
'USER': 'archer_rw',
'PASSWORD': 'archer_rw',
'HOST': '192.168.1.3',
'PORT': '3306'
}
}
#inception组件所在的地址
INCEPTION_HOST = '192.168.1.123'
INCEPTION_PORT = '6669'
#查看回滚SQL时候会用到,这里要告诉archer去哪个mysql里读取inception备份的回滚信息和SQL.
#注意这里要和inception组件的inception.conf里的inception_remote_XX部分保持一致.
INCEPTION_REMOTE_BACKUP_HOST='192.168.1.3'
INCEPTION_REMOTE_BACKUP_PORT=3306
INCEPTION_REMOTE_BACKUP_USER='incep_rw'
INCEPTION_REMOTE_BACKUP_PASSWORD='incep_rw'
|
4、通过model创建archer本身的数据库表
总结:
pip3 install django_admin_bootstrapped python3 manage.py makemigrations python3 manage.py makemigrations sql python3 manage.py migrate
[root@mysql3]# cd /opt/archer
[root@mysql3 archer]# python3 manage.py makemigrations
No changes detected
[root@mysql3 archer]# python3 manage.py makemigrations sql
Migrations for 'sql':
0001_initial.py:
- Create model users
- Create model master_config
- Create model workflow
[root@mysql3 archer]# python3 manage.py migrate
Operations to perform:
Synchronize unmigrated apps: messages, staticfiles
Apply all migrations: sessions, auth, contenttypes, sql, admin
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying sql.0001_initial... OK
Applying admin.0001_initial... OK
Applying sessions.0001_initial... OK
查看表是否创建成功:
[root@mysql3 archer]# mysql -uarcher_rw -parcher_rw -h192.168.1.3 -P3306 -Darcher -e "show tables;"
Warning: Using a password on the command line interface can be insecure.
+----------------------------+
| Tables_in_archer |
+----------------------------+
| auth_group |
| auth_group_permissions |
| auth_permission |
| django_admin_log |
| django_content_type |
| django_migrations |
| django_session |
| sql_master_config |
| sql_users |
| sql_users_groups |
| sql_users_user_permissions |
| sql_workflow |
+----------------------------+
|
5、创建django admin管理员
[root@mysql3 archer]# python3 manage.py createsuperuser
Username: admin
Email address: [email protected]
Password: admin123
Password (again): admin123
Superuser created successfully.
该用户可以登录django admin来管理model。
|
启动acher
[root@mysql3 archer]# vi debug.sh
#!/bin/bash
python3 manage.py runserver 0.0.0.0:9123
[root@mysql3 archer]# sh debug.sh
Performing system checks...
System check identified no issues (0 silenced).
April 15, 2017 - 16:39:11
Django version 1.8.17, using settings 'archer.settings'
Starting development server at http://0.0.0.0:9123/
Quit the server with CONTROL-C.
|
创建archer系统登录用户
通过浏览器访问http://192.168.1.123:9123/admin/sql/users/可以看到django登录界面:使用上面第5步创建的用户名密码(admin/admin123)登录:点击右侧Add用户配置,用户名密码自定义,至少创建一个工程师和一个审核人(用admin用户可以登录)后续新的工程师和审核人用户请用LDAP导入sql_users表或django admin增加
配置主库地址
通过浏览器访问http://192.168.1.123:9123/admin/sql/master_config点击右侧Add master_config。这一步是为了告诉archer你要用inception去哪些mysql主库里执行SQL,所用到的用户名密码、端口等。
正式访问主页
http://192.168.1.123:9123/login/登录成功后:
遇到问题及解决
查看回滚SQL时报错
[18/Apr/2017 11:49:50] "GET /detail/2/ HTTP/1.1" 200 7474
Mysql Error 1142: SELECT command denied to user 'incep_rw'@'192.168.1.123' for table '$_$inception_backup_information$_$'
Error: returned listTables more than 1.
[18/Apr/2017 11:50:01] "GET /rollback/?csrfmiddlewaretoken=8s6iaPsMtgX1Qvd0lf8vDOXe0K9hPecp&workflowid=2 HTTP/1.1" 500 73965
|
解决办法:给incep_rw用户赋予select、create、insert权限
root@mysql 04:42:04>grant select,create,insert on *.* to incep_rw@'%' identified by 'incep_rw';
Query OK, 0 rows affected (0.00 sec)
root@mysql 04:54:23>flush privileges;
Query OK, 0 rows affected (0.00 sec)
|
CREATE权限用于创建表或者库的,INSERT权限用于插入备份数据的,SELECT权限用于查询回滚SQL。再次执行update语句,查看回滚SQL为空,审核结果显示:解决办法:为mysql添加server_id
archer安装部署 *************************************************************************** --版本 python:3.4 django:1.8 mysql : 5.6以上 linux : 64位linux --安装archer mkdir -p /opt/archer_web/ cd /opt/archer_web yum -y install git git clone https://github.com/jly8866/archer.git --安装python3 cd /opt wget https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz tar -zxvf Python-3.4.1.tgz cd Python-3.4.1 ./configure --prefix=/opt/python3 && make && make install vim /etc/profile 添加:export PATH="/opt/python3/bin:$PATH" source /etc/profile python3 --安装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 python3 setup.py build python3 setup.py install 可以看到安装到python3下面了 --安装pip cd /opt wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb tar -zxvf pip-8.0.2.tar.gz cd pip-8.0.2 python3 setup.py build python3 setup.py install --安装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 python3 setup.py install python3 >>> import django >>> django.VERSION (1, 8, 17, 'final', 0) >>> exit() --安装Crypto和pymysql pip3 install Crypto pip3 install pycrypto pip3 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 /opt/archer_web/archer --创建archer DB和inception DB --进入安装的mysql5.6 mysql -uroot -p'P@ssw0rd' -S /mydata/mysql/mysql3306/mysql.sock --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'; create database test default character set utf8; #测试库 建在审核库里了 仅做测试 grant all on test.* to test@'%' identified by 'P@ssw0rd'; flush privileges; ########创建archer DB和inception DB############# create database archer; grant all on archer.* to archer_rw@'%' identified by 'archer_rw'; create database inception_db; grant all on inception_db.* to incep_rw@'%' identified by 'incep_rw'; flush privileges; ######################## --修改/opt/archer_web/archer/archer/settings.py,如下内容: vi /opt/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 /opt/archer_web/archer pip3 install django_admin_bootstrapped python3 manage.py makemigrations python3 manage.py makemigrations sql python3 manage.py migrate 进入数据库查看archer库下的表是否存在 ##########创建archer本身的数据库表##################### [root@192-168-1-34 archer]# python3 manage.py makemigrations No changes detected [root@192-168-1-34 archer]# python3 manage.py makemigrations sql No changes detected in app 'sql' [root@192-168-1-34 archer]# python3 manage.py migrate Operations to perform: Synchronize unmigrated apps: messages, django_admin_bootstrapped, staticfiles Apply all migrations: admin, sessions, auth, sql, django_apscheduler, contenttypes Synchronizing apps without migrations: Creating tables... Running deferred SQL... Installing custom SQL... Running migrations: Rendering model states... DONE Applying contenttypes.0001_initial... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0001_initial... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying sql.0001_initial... OK Applying admin.0001_initial... OK Applying django_apscheduler.0001_initial... OK Applying django_apscheduler.0002_auto_20180412_0758... OK Applying sessions.0001_initial... OK [root@192-168-1-34 archer]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.6.40 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | archer | | inception_db | | mysql | | performance_schema | | test | +--------------------+ 6 rows in set (0.00 sec) mysql> use archer; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +---------------------------------------+ | Tables_in_archer | +---------------------------------------+ | aliyun_access_key | | aliyun_rds_config | | auth_group | | auth_group_permissions | | auth_permission | | data_masking_columns | | data_masking_rules | | django_admin_log | | django_apscheduler_djangojob | | django_apscheduler_djangojobexecution | | django_content_type | | django_migrations | | django_session | | query_log | | query_privileges | | query_privileges_apply | | sql_master_config | | sql_slave_config | | sql_users | | sql_users_groups | | sql_users_user_permissions | | sql_workflow | | workflow_audit | | workflow_audit_detail | | workflow_audit_setting | +---------------------------------------+ 25 rows in set (0.00 sec) mysql> show create table aliyun_rds_config; +-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | aliyun_rds_config | CREATE TABLE `aliyun_rds_config` ( `id` int(11) NOT NULL AUTO_INCREMENT, `rds_dbinstanceid` varchar(100) NOT NULL, `cluster_name` varchar(50) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `cluster_name` (`cluster_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> exit Bye [root@192-168-1-34 archer]# python3 manage.py createsuperuser Username: admin Email address: [email protected] Password: Password (again): Superuser created successfully. [root@192-168-1-34 archer]# ls archer debug.bat debug.sh LICENSE manage.py patch README.md requirements.txt sql src startup.sh stop.sh [root@192-168-1-34 archer]# sh debug.sh Performing system checks... System check identified no issues (0 silenced). June 21, 2018 - 09:49:24 Django version 1.8.17, using settings 'archer.settings' Starting development server at http://192.168.1.34:9123/ Quit the server with CONTROL-C. ####################################### --创建django admin管理员 python3 manage.py createsuperuser Username: admin 自己填写用户名 Email address: 邮箱 Password: 密码 Password (again): 确认密码 Superuser created successfully. 该用户可以登录django admin来管理model。 --启动acher vi debug.sh #!/bin/bash python3 manage.py runserver ip:9123 端口为9123 nohup sh debug.sh 2&>1 & [root@192-168-1-34 archer]# sh debug.sh Performing system checks... System check identified no issues (0 silenced). June 21, 2018 - 09:49:24 Django version 1.8.17, using settings 'archer.settings' Starting development server at http://192.168.1.34:9123/ Quit the server with CONTROL-C. 注:WEB访问时报错 --创建archer系统登录用户 pip3 install simplejson 通过浏览器访问http://10.10.3.70:8080/admin/sql/users/ 可以看到django登录界面: 使用上面创建的用户名密码(admin/和密码)登录: 点击右侧Add用户配置,用户名密码自定义,至少创建一个工程师和一个审核人(用admin用户可以登录)后续新的工程师和审核人用户请用LDAP导入sql_users表或django admin增加 --配置主库地址 通过浏览器访问http://10.10.3.70:8080/admin/sql/master_config 点击右侧Add master_config。这一步是为了告诉archer你要用inception去哪些mysql主库里执行SQL,所用到的用户名密码、端口等。 --正式访问主页 http://10.10.3.70:8080/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