# 安装依赖
yum install wget gcc make zlib-devel openssl openssl-devel
wget "https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz"
tar -xvJf Python-3.6.5.tar.xz
# 编译
cd Python-3.6.5
./configure prefix=/usr/local/python3
make && make install
ln -fs /usr/local/python3/bin/python3 /usr/bin/python3
ln -fs /usr/local/python3/bin/pip3 /usr/bin/pip3
# virtualenv
pip3 install virtualenv -i https://mirrors.ustc.edu.cn/pypi/web/simple/
ln -fs /usr/local/python3/bin/virtualenv /usr/bin/virtualenv
yum安装
# 安装EPEL源
yum install epel-release
# 安装python36、pip36
yum install python36 python36-pip
# virtualenv
pip3.6 install virtualenv -i https://mirrors.ustc.edu.cn/pypi/web/simple/
准备虚拟环境
# 编译安装python的使用
cd /opt
virtualenv venv4archery --python=python3
# 切换python运行环境到虚拟环境
source /opt/venv4archery/bin/activate
安装 MS SQL Server 驱动(需要使用MsSQL的按需安装)
详见官方文档
# CentOS 6
curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo
# CentOS 7
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
# 卸载冲突驱动
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel
# 安装驱动
sudo ACCEPT_EULA=Y yum install msodbcsql17
sudo ACCEPT_EULA=Y yum install mssql-tools
# 更新环境变量
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# 安装ODBC依赖
sudo yum install unixODBC-devel
安装ORACLE驱动(需要使用ORACLE的按需安装)
详见官方文档:https://oracle.github.io/odpi/doc/installation.html
yum install http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/getPackage/oracle-instantclient19.3-basiclite-19.3.0.0.0-1.x86_64.rpm
下载最新release包,安装依赖库
Release版本见Releases 如果网络受限可访问码云地址: gitee
cd /data/code/archery
wget "https://github.com/hhyo/archery/archive/v1.7.10.tar.gz"
tar -xzvf v1.7.10.tar.gz
# 安装系统依赖
yum -y install gcc gcc-c++ python-devel mysql-devel openldap-devel unixODBC-devel gettext
# 安装依赖库
cd archery-1.7.10
pip3 install -r requirements.txt -i https://mirrors.ustc.edu.cn/pypi/web/simple/
# 如果使用yum安装的python3,安装mysqlclient可能提示提示缺少Python.h,可安装
yum -y install python36-devel
安装 goInception
下载地址:
https://github.com/hanchuanchuan/goInception/releases
启动(注意指定配置文件)
./goInception -config=config/config.toml
安装 inception
cat /etc/inc.cnf
[inception]
general_log=1
general_log_file=inc.log
port=6669
socket=/tmp/inc.socket
character-set-client-handshake=0
character-set-server=utf8
inception_remote_system_password=Jimstars
inception_remote_system_user=root
inception_remote_backup_port=3306
inception_remote_backup_host=127.0.0.1
inception_support_charset=utf8
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
启动
/opt/Inception --defaults-file=/etc/inc.cnf &
安装 SQLAdvisor
拉取最新代码
git clone https://github.com/Meituan-Dianping/SQLAdvisor.git
安装依赖项
yum install cmake libaio-devel libffi-devel glib2 glib2-devel
yum install --enablerepo=Percona56 Percona-Server-shared-56
注意
1.跟据glib安装的路径,修改 SQLAdvisor/sqladvisor/CMakeLists.txt 中的两处 include_directories 针对glib设置的path。 glib yum 安装默认不需要修改路径
2.编译sqladvisor时依赖 perconaserverclient_r, 因此需要安装 Percona-Server-shared-56 。有可能需要配置软链接例如:1. cd /usr/lib64/ 2. ln -s libperconaserverclient_r.so.18 libperconaserverclient_r.so
3.有可能需要配置percona56 yum源: yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
上面步骤可能出现错误:源 "Percona-Release YUM repository - x86_64" 的 GPG 密钥已安装,但是不适用于此软件包。请检查源的公钥 URL 是否配置正确。
解决办法:yum update percona-release
编译依赖项sqlparser
cmake -DBUILD_CONFIG=mysql_release -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=/usr/local/sqlparser ./
make && make install
安装SQLAdvisor源码
cd SQLAdvisor/sqladvisor/
cmake -DCMAKE_BUILD_TYPE=debug ./
make
在本路径下生成一个sqladvisor可执行文件,这即是我们想要的。
安装 soar
下载地址 : https://github.com/XiaoMi/soar/releases
chmod a+x soar
安装验证
echo 'select * from film' | ./soar
安装 SchemaSync
下载地址: https://github.com/hhyo/SchemaSync
先安装 MySQLdb ,下载地址: https://pypi.org/project/MySQL-python/1.2.5/
安装 MySQLdb和SchemaSync需要用Python2.7版本安装:
python2 setup.py build
python2 setup.py install
安装mysql、redis
步骤省略
启动准备
# 数据库初始化
python3 manage.py makemigrations sql
python3 manage.py migrate
# 创建管理用户
python3 manage.py createsuperuser
启动
runserver启动(仅作为本地测试)
source /opt/venv4archery/bin/activate
#启动Django-Q,需保持后台运行
nohup python3 manage.py qcluster &
#启动服务
nohup python3 manage.py runserver 10.10.10.62:80 --insecure &
Gunicorn+Nginx启动
# nginx配置示例
server{
listen 80; # 监听的端口
server_name archery;
client_max_body_size 20M; # 处理Request Entity Too Large
proxy_read_timeout 600s; # 超时时间与Gunicorn超时时间设置一致,主要用于在线查询
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host:80; # 解决重定向404的问题,和listen端口保持一致,如果是docker则和宿主机映射端口保持一致
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /static {
alias /opt/archery/static; # 此处指向settings.py配置项STATIC_ROOT目录的绝对路径,用于nginx收集静态资源
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# 启动
source /opt/venv4archery/bin/activate
bash startup.sh