-
Notifications
You must be signed in to change notification settings - Fork 1.7k
manual
Nick Wang edited this page Mar 29, 2023
·
15 revisions
Centos7可以参考Dockerfile-base和Dockerfile,相当于详细的安装步骤,以下安装步骤同样以Centos7为例
从1.9.0版本开始,将不再支持python3.7及以下版本,手动安装也将使用3.9版本作为样例,移除yum安装方式
# 安装依赖
yum install libffi-devel wget gcc make zlib-devel openssl openssl-devel ncurses-devel openldap-devel gettext bzip2-devel xz-devel
wget "https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tar.xz"
tar -xvJf Python-3.9.10.tar.xz
# 编译
cd Python-3.9.10
./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
# 编译安装python的使用
virtualenv venv4archery --python=python3
# yum安装的使用
virtualenv venv4archery --python=python3.6
# 切换python运行环境到虚拟环境
source venv4archery/bin/activate
详见官方文档
# 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
详见官方文档: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
wget -c https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.20.tgz
tar -xvf mongodb-linux-x86_64-rhel70-3.6.20.tgz
\cp -f mongodb-linux-x86_64-rhel70-3.6.20/bin/mongo /usr/bin/
Release版本见Releases 如果网络受限可访问码云地址: gitee
wget "https://github.com/hhyo/archery/archive/v1.8.5.tar.gz"
tar -xzvf v1.8.5.tar.gz
# 安装系统依赖
yum -y install gcc gcc-c++ python-devel mysql-devel openldap-devel unixODBC-devel gettext
# 安装依赖库
cd archery-1.8.0
pip3 install -r requirements.txt -i https://mirrors.ustc.edu.cn/pypi/web/simple/
# 如果使用yum安装的python3,安装mysqlclient可能提示提示缺少Python.h,可安装
yum -y install python36-devel
项目地址:https://github.com/hanchuanchuan/goInception
- MySQL推荐版本>=5.7
- Redis提供任务队列和缓存
vi archery/settings.py
请务必修改配置文件中的SECRET_KEY信息,该key用于敏感信息加密
# 修改SECRET_KEY
# 关闭debug模式
DEBUG = False
# 设置ALLOWED_HOSTS,建议限制内网访问
ALLOWED_HOSTS = [
'.example.com', # Allow domain and subdomains
'.example.com.', # Also allow FQDN and subdomains
]
# 请求大小限制,如果提交SQL语句过大可以修改该值
DATA_UPLOAD_MAX_MEMORY_SIZE = 15728640
# 密码校验,用户注册和添加密码校验规则
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'OPTIONS': {
'min_length': 9,
}
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
建议MySQL版本5.7以上
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'archery', # 数据库名称
'USER': 'root', # 数据库用户
'PASSWORD': '', # 数据库密码
'HOST': '127.0.0.1', # 数据库HOST,如果是docker启动并且关联,可以使用容器名连接
'PORT': '3306', # 数据库端口
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'", # SQL_MODE,为了兼容select * group by,可以按需调整
'charset': 'utf8mb4'
},
'TEST': {
'NAME': 'test_archery',
'CHARSET': 'utf8mb4',
},
}
}
默认配置即可,也可参考django-q文档修改
Q_CLUSTER = {
'name': 'archery',
'workers': 4,
'recycle': 500,
'timeout': 60,
'compress': True,
'cpu_affinity': 1,
'save_limit': 0,
'queue_limit': 50,
'label': 'Django Q',
'django_redis': 'default',
'sync': False # 本地调试可以修改为True,使用同步模式
}
缓存使用redis,可参考 django_redis 文档 http://django-redis-chs.readthedocs.io/zh_CN/latest/
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/0", # redis://host:port/db
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"PASSWORD": ""
}
}
}
# 数据库初始化
python3 manage.py makemigrations sql
python3 manage.py migrate
# 数据初始化
python3 manage.py dbshell<sql/fixtures/auth_group.sql
python3 manage.py dbshell<src/init_sql/mysql_slow_query_review.sql
# 创建管理用户
python3 manage.py createsuperuser
source /opt/venv4archery/bin/activate
#启动Django-Q,需保持后台运行
python3 manage.py qcluster
#启动服务
python3 manage.py runserver 0.0.0.0:9123 --insecure
# nginx配置示例
server{
listen 9123; # 监听的端口
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:8888;
proxy_set_header Host $host:9123; # 解决重定向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
在启动后 Archery 有一些配置(如Inception , 资源组, 权限组等)需要按需配置, 请详细阅读 配置项说明 , 按照自己的需要进行配置。