v1.2.0 → v1.3.8

  • python 3.6.5
  • MySQL 5.7
  • Inception 2.1.15(闭源前最后公布版本)
    • 或分支https://github.com/hhyo/inception
  • Percona Toolkit 3.0.13
  1. yum install -y python36 python36-devel python-devel openldap-devel
  2. cd /tmp
  3. wget https://bootstrap.pypa.io/get-pip.py
  4. python3.6 get-pip.py
  1. # 创建 vevn
  2. pip3 install virtualenv
  3. cd /opt/
  4. virtualenv venv4archery --python=python36
  5. source /opt/venv4archery/bin/activate
  6. which mysql_config #确认命令在 $PATH 中,否则安装包时报错
  7. cd /opt
  8. # 安装 gcc
  9. yum install -y gcc
  10. # 下载 archery 源码
  11. wget https://github.com/hhyo/archery/archive/v1.3.8.tar.gz
  12. tar -zxvf v1.3.8.tar.gz
  13. cd archery138/
  14. pip3 install -r requirements.txt -i https://mirrors.ustc.edu.cn/pypi/web/simple/

img

img

  • MySQL 安装略

  • 连接信息:
  • archery:
    • ip:127.0.0.1
    • port:3306
  • inception:
    • ip:127.0.0.1
    • port:3307
  1. # 创建 archery 1.38 版本数据库
  2. create database archery138 charset utf8mb4;
  3. # 创建 archery 后台数据库账号
  4. create user archery@'127.0.0.1' identified by 'xxxxxx';
  5. grant all on archery138.* to archery@'127.0.0.1';
  6. # 创建线上 v1.2.0 版本数据库恢复库
  7. create database archery120to138 charset utf8mb4;
  8. # 创建 inception 备份库连接账号
  9. create user incep@'127.0.0.1' identified by 'xxxxxx';
  10. grant all on *.* to incep@'127.0.0.1';
  11. flush privileges;
  • inception 编译安装略

  • inception 配置文件

  1. [inception]
  2. general_log=1
  3. general_log_file=inception.log
  4. port=6669
  5. socket=/tmp/inc.socket
  6. character-set-client-handshake=0
  7. character-set-server=utf8
  8. inception_remote_system_password=123456
  9. inception_remote_system_user=incep
  10. inception_remote_backup_port=3306
  11. inception_remote_backup_host=127.0.0.1
  12. inception_support_charset=utf8,utf8mb4
  13. inception_osc_on=ON
  14. inception_osc_bin_dir=/usr/local/bin
  15. inception_enable_nullable=0
  16. inception_check_primary_key=1
  17. inception_check_column_comment=1
  18. inception_check_table_comment=1
  19. inception_osc_min_table_size=1
  20. inception_osc_chunk_time=0.1
  21. inception_ddl_support=1
  22. inception_enable_blob_type=1
  23. inception_check_column_default_value=1
  24. # 启动 inception
  25. inception --defaults-file=incep.cnf &
  1. cd /tmp
  2. wget -r -np -nd --accept=gz --no-check-certificate https://www.percona.com/downloads/percona-toolkit/3.0.13/binary/tarball/percona-toolkit-3.0.13_x86_64.tar.gz
  3. tar zxvf percona-toolkit-3.0.13_x86_64.tar.gz
  4. cp percona-toolkit-3.0.13/bin/* /usr/local/bin/
  1. yum install -y nginx
  2. vim /etc/nginx/conf.d/nginx.conf
  1. server{
  2. listen 9123; #监听的端口
  3. server_name archery138;
  4. proxy_read_timeout 600s; #超时时间与gunicorn超时时间设置一致,主要用于在线查询
  5. location / {
  6. proxy_pass http://127.0.0.1:8888;
  7. proxy_set_header Host $host:9123; #解决重定向404的问题
  8. proxy_set_header X-Real-IP $remote_addr;
  9. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  10. proxy_set_header X-Forwarded-Proto $scheme;
  11. }
  12. location /static {
  13. alias /opt/archery138/archery/common/static; #此处指向settings.py配置项STATIC_ROOT目录的绝对路径,用于nginx收集静态资源
  14. }
  15. error_page 404 /404.html;
  16. location = /40x.html {
  17. }
  18. error_page 500 502 503 504 /50x.html;
  19. location = /50x.html {
  20. }
  21. }
  1. cd /opt/
  2. mkdir archery_tools
  3. cd /opt/archery_tools
  4. rz soar
  1. git clone https://github.com/Meituan-Dianping/SQLAdvisor.git
  2. yum install -y cmake libaio-devel libffi-devel glib2 glib2-devel gcc-c++ bison
  3. yum install -y Percona-Server-shared-56 [ --enablerepo=Percona56 ]
  4. # 如果不能安装 Percona-Server-shared-56 报错找不到包,那么需要执行下面语句
  5. yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
  6. cd SQLAdvisor
  7. cmake -DBUILD_CONFIG=mysql_release -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=/usr/local/sqlparser ./
  8. make && make install
  9. cd sqladvisor
  10. cmake -DCMAKE_BUILD_TYPE=debug ./
  11. make
  12. cp /opt/archery_tools/SQLAdvisor/sqladvisor/sqladvisor /opt/archery_tools/
  13. yes | rm /opt/archery_tools/SQLAdvisor -r
  14. # 在本路径下生成一个sqladvisor可执行文件,这即是我们想要的。
  15. /opt/archery_tools/sqladvisor --help
  • 安装 Percona-Server-shared-56 报错,与 MariaDB-common-10.1.37-1.el7.centos.x86_64 包有冲突

img

  • 因为机器部署时使用的 MariaDB-common-10.1.37-1.el7.centos.x86_64 包安装的 zabbix-agent

img

  • 解决办法:从测试环境拷贝 libmysqlclient.so.18.1.0 文件,再创建软链接文件
  1. cd /opt/archery_tools/
  2. virtualenv venv4schemasync --python=python2
  3. source venv4schemasync/bin/activate
  4. git clone https://github.com/hhyo/SchemaSync.git
  5. git clone https://github.com/hhyo/SchemaObject.git
  6. cd SchemaObject && python setup.py install
  7. cd ../SchemaSync && python setup.py install
  8. yum install -y python-devel
  9. pip install mysql-python
  10. schemasync --version
  11. which schemasync
  12. cd ..
  13. ln -s /opt/archery_tools/venv4schemasync/bin/schemasync schemasync
  1. vim /opt/archery138/archery/settings.py
  1. # 该项目本身的mysql数据库地址
  2. DATABASES = {
  3. 'default': {
  4. 'ENGINE': 'django.db.backends.mysql',
  5. 'NAME': 'archery138', #archery信息库,执行py脚本生成
  6. 'USER': 'archery', #archery 特权登录用户,执行py脚本生成
  7. 'PASSWORD': 'xxx', #archery 特权登录用户密码
  8. 'HOST': '10.xx.xx.xx', #archery 数据库ip
  9. 'PORT': '3306', #archery 数据库端口
  10. 'OPTIONS': {
  11. 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
  12. 'charset': 'utf8mb4' #archery 数据库字符集,默认为utf8mb4
  13. },
  14. 'TEST': {
  15. 'NAME': 'test_archery',
  16. 'CHARSET': 'utf8', #archery 数据库字符集,默认为utf8
  17. },
  18. }
  19. }
  20. # LDAP
  21. ENABLE_LDAP = False
  22. if ENABLE_LDAP:
  23. import ldap
  24. from django_auth_ldap.config import LDAPSearch
  25. AUTHENTICATION_BACKENDS = (
  26. 'django_auth_ldap.backend.LDAPBackend', # 配置为先使用LDAP认证,如通过认证则不再使用后面的认证方式
  27. 'django.contrib.auth.backends.ModelBackend', # django系统中手动创建的用户也可使用,优先级靠后。注意这2行的顺序
  28. )
  29. AUTH_LDAP_SERVER_URI = "ldap://xx.xx.xx.com"
  30. AUTH_LDAP_BIND_DN = "CN=auth,CN=Users,DC=xx,DC=xx,DC=com"
  31. AUTH_LDAP_BIND_PASSWORD = "xxxxxxxxxxxxxxx"
  32. AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=xxx,dc=xx,dc=xxx,dc=com",ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)")
  33. AUTH_LDAP_ALWAYS_UPDATE_USER = True # 每次登录从ldap同步用户信息
  34. AUTH_LDAP_USER_ATTR_MAP = { # key为archery.sql_users字段名,value为ldap中字段名,用户同步信息
  35. "username": "xxxxxxxxxxxx",
  36. "display": "cn",
  37. "email": "mail"
  38. }
  1. cd /opt/archery138/
  2. python36 manage.py makemigrations sql #这一步如果遇到报错可忽略
  3. python36 manage.py migrate
  1. cd /opt/archery138/
  2. python3 manage.py createsuperuser
  3. Username: archery_admin # 手动输入
  4. Email address: dba-notice@ybm100.com
  5. Password: xxxx #输入密码
  6. Password (again): xxxxx #确认密码
  7. Superuser created successfully.
  1. source /opt/venv4archery/bin/activate
  2. python3 manage.py runserver 0.0.0.0:9123 --insecure &
  • venv中已经安装,无需额外安装
  1. cd /opt/archery138/
  2. source /opt/venv4archery/bin/activate
  3. sh startup.sh &
  1. #!/bin/bash
  2. inception --defaults-file=/opt/inception/inc.cnf &
  3. source /opt/venv4archery/bin/activate
  4. cd /opt/archery138
  5. python3 /opt/archery138/manage.py runserver 0.0.0.0:9123 --insecure &
  6. sh /opt/archery138/startup.sh &
  1. # 10.xx.xx.xx
  2. sudo su -
  3. mysqldump -S xx/mysql.sock --single-transaction --master-data=2 --set-gtid-purged=OFF db_ops > db_ops.sql
  1. # 10.xx.xx.xx
  2. sudo su -
  3. mysql -S xx/mysql.sock db_ops <db_ops.sql
  1. # 10.xx.xx.xx
  2. sudo su -
  3. cd /opt/archery138/src/init_sql
  4. mysql -h 10.xx.xx.xx -P3306 -uxx -p db_ops < v1.2.0_1.3.0.sql
  5. mysql -h 10.xx.xx.xx -P3306 -uxx -p db_ops < v1.3.0_1.3.2.sql
  6. mysql -h 10.xx.xx.xx -P3306 -uxx -p db_ops < v1.3.6_v1.3.7.sql
  1. # 10.xx.xx.xx
  2. sudo su -
  3. mysqldump -S xx/mysql.sock --single-transaction --master-data=2 --set-gtid-purged=OFF --no-create-info db_ops > updated_db_data.sql.bak
  4. mysql -h 10.xx.xx.xx -P3306 -uxx -p archery < updated_db_data.sql,bak

访问 http://10.xx.xx.xx:9123

“系统管理”–>“配置项管理”

——填写完成后点击测试,通过后保存

  1. INCEPTION_HOST 10.xx.xx.xx
  2. INCEPTION_PORT 6669
  3. REMOTE_BACKUP_HOST 10.xx.xx.xx
  4. REMOTE_BACKUP_PORT 3306
  5. REMOTE_BACKUP_USER incep
  6. REMOTE_BACKUP_PASSWORD xxxx
  1. QUERY ON
  1. SQLADVISOR_PATH /opt/archery_tools/sqladvisor
  2. SOAR_PATH /opt/archery_tools/soar
  3. SOAR_TEST_DSN xxx:xxx@10.xx.xx.xx:3306/archery

——填写完成后点击测试,通过后保存

  1. MAIL ON
  2. MAIL_SSL ON
  3. MAIL_SMTP_SERVER xxx
  4. MAIL_SMTP_PORT xxx
  5. MAIL_SMTP_USER xxx
  6. MAIL_SMTP_PASSWORD xxx
  7. DDL_NOTIFY_AUTH_GROUP dinglu@ybm100.com
  8. DING ON

SCHEMASYNC /opt/archery_tools/venv4schemasync/bin/schemasync

  • 如果在archery平台上使用schemasync进行表对比的时候出现问题,可能是登录mysql的密码中出现了特殊字符,使得schemasync

  • 无法识别这个密码,可以将含有特殊字符的密码改成不含有特殊字符的密码,问题就可以解决了,或者是修改instance.py 文件中的代码

修改前:

  1. command = path + ' %s --output-directory=%s --tag=%s \
  2. mysql://%s:%s@%s:%d/%s mysql://%s:%s@%s:%d/%s'

修改后:

  1. command = path + " %s --output-directory=%s --tag=%s \
  2. mysql://%s:'%s'@%s:%d/%s mysql://%s:'%s'@%s:%d/%s"
  3. # 将其中的密码用单引号引起来就可以了

版权声明:本文为David-domain原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/David-domain/p/11165734.html