archery部署流程

不操千曲而后晓声,观千剑而后识器。这篇文章主要讲述archery部署流程相关的知识,希望能为你提供帮助。
其实官方文档里写的很详尽了,但是有些配套依赖比如mysql redis goinception只是一笔带过,这里我也处理一下
本文操作在centos7环境下进行。
1 关闭selinux修改/etc/selinux/config 文件

sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
setenforce 0

2 安装EPEL源
yum install -y epel-release
# 安装python36、pip36
yum install -y python36 python36-pip
# virtualenv
pip3.6 install virtualenv -i https://mirrors.ustc.edu.cn/pypi/web/simple

3 安装archery
wget "https://github.com/hhyo/archery/archive/v1.8.0.tar.gz"
tar -xzvf v1.8.0.tar.gz

# 安装系统依赖
yum -y install gcc gcc-c++ python-devel mysql-devel openldap-devel unixODBC-devel gettext python36-devel
# 安装依赖库
cd archery-1.8.0

准备虚拟环境
# 编译安装python的使用
virtualenv venv4archery --python=python3
# yum安装的使用
virtualenv venv4archery --python=python3.6
# 切换python运行环境到虚拟环境
source venv4archery/bin/activate

pip3 install -r requirements.txt -i https://mirrors.ustc.edu.cn/pypi/web/simple/

# 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

4 pip安装依赖过程中可能出现的问题解决CentOS mysql_config not found错误
yum install -y mysql-devel gcc gcc-devel python-devel


?解决UnicodeDecodeError: ascii codec cant decode byte 0xe3 in position 473: ordinal not in range(128)错误
系统字符集问题
编辑/etc/locale.conf

修改为
LC_ALL=en_US.utf8
LC_CTYPE=en_US.utf8
LANG=en_US.utf8

执行
localedef -c -f UTF-8 -i en_US en_US.utf8

操作完毕后,需要退出终端然后重新连接
?安装python-ldap报错?Modules/constants.h:7:18: 致命错误:lber.h:没有那个文件或目录#include “lber.h”
解决办法:
【archery部署流程】
yum install -y openldap-devel

gcc: error trying to exec cc1plus: execvp: No such file or directory报错?
解决办法
yum install -ygcc-c++



5 安装 docker mysql redis goInception安装docker
# 安装Docker
wget http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum install -y docker-ce-18.06.1.ce-3.el7
systemctl enable docker & & systemctl start docker
docker --version

# docker镜像加速
cat > /etc/docker/daemon.json < < EOF

"registry-mirrors": ["https://od.mirror.aliyuncs.com"]

EOF

service docker restart
docker info

docker方式启动数据库
mkdir -p/usr/local/docker/mysql/
docker run -p 127.0.0.1:3306:3306 --name mysql \\
-v /usr/local/docker/mysql/conf:/etc/mysql \\
-v /usr/local/docker/mysql/logs:/var/log/mysql \\
-v /usr/local/docker/mysql/data:/var/lib/mysql \\
-e MYSQL_ROOT_PASSWORD=123456 \\
--restart=always \\
-d mysql:5.7

配置字符集并创建archery数据库
yum install mysql
mysql -h127.0.0.1 -p123456
MySQL [(none)]> set character_set_server=utf8;
MySQL [(none)]> set character_set_database=utf8;
MySQL [(none)]> create database archery DEFAULT CHARACTER SET utf8mb4;

docker方式启动redis
docker run -p 127.0.0.1:6379:6379 --name redis \\
--restart=always -d redis:5 redis-server --requirepass 123456

docker方式启动goinception
mkdir -p/usr/local/docker/inception/
docker run -p 127.0.0.1:4000:4000 --name goinception \\
--restart=always \\
-dhanchuanchuan/goinception

配置archeryvim 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配置?????
建议MySQL版本5.6以上
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配置?????
默认配置即可,也可参考??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

启动?????
runserver启动(仅作为本地测试)?????
source /opt/venv4archery/bin/activate
#启动,需保持后台运行
python3 manage.py qcluster
#启动服务
python3 manage.py runserver 0.0.0.0:9123--insecure


    推荐阅读