跳转至

附录:环境安装部署手册

AI医生安装部署手册

  • 注意事项:
    • 这个安装手册只适用于操作系统: centos 7

安装部署步骤

  • 1 拷贝必备文件

  • 2 安装Anaconda科学计算环境, 包括python, pip, pandas, numpy, matplotplib等科学计算包

  • 3 安装项目需要的若干独立工具.

# 安装Redis数据库
yum install redis -y

# 安装supervisor
yum install supervisor -y

# 安装lsof
yum install lsof -y

# 激活虚拟环境
conda activate ai_doctor

# 安装Flask
pip install flask

# 安装python中的redis驱动
pip install redis

# 安装gunicorn
pip install gunicorn
  • 4 安装项目需要的重要工具pytorch
# 安装pytorch
pip install torch
  • 5 安装图数据库neo4j
# 第一步: 将neo4j安装信息载入到yum检索列表
rpm --import http://debian.neo4j.org/neotechnology.gpg.key
vim /etc/yum.repos.d/neo4j.repo
# 写入下面内容
[neo4j]
name=Neo4j RPM Repository
baseurl=http://yum.neo4j.org/stable
enabled=1
gpgcheck=1

# 第二步: 使用yum install命令安装
yum install neo4j

# 第三步:使用pip install命令安装neo4j驱动
pip install neo4j neo4j-driver

# 第四步: 使用自己的配置文件
cp /data/neo4j.conf /etc/neo4j/neo4j.conf
  • 6 配置supervisord管理neo4j图数据库
# 在/etc/supervisord.conf中添加以下配置
# 注意配置neo4j需要修改/var/log/neo4j/和/var/lib/neo4j目录属组,否则无法启动
# chown -R neo4j:neo4j /var/log/neo4j
# chown -R neo4j:neo4j /var/lib/neo4j
[program:neo4j]
command=neo4j console
user=neo4j
autostart=true
autorestart=unexpected
startsecs=30
startretries=999
priorities=90
exitcodes=0,1,2
stopsignal=SIGTERM
stopasgroup=true
killasgroup=true
redirect_stderr=true
stdout_logfile=/var/log/neo4j/neo4j_supervisor.out
stdout_logfile_backups=10
stderr_capture_maxbytes=20MB

在supervisord中启动neo4j

supervisorctl # 进入supervisord命令行

start neo4j # 启动neo4j服务
  • 7 使用脚本生成图谱
# 执行已经写好的脚本代码, 将数据写入到neo4j数据库中
python /data/doctor_offline/neo4j_write.py
  • 8 使用脚本训练模型
# 在线部分只有一个模型bert-chinese
cd /data/doctor_online/bert_server/
python train.py
  • 9 配置werobot服务
# 在/etc/supervisord.conf中添加以下配置,其中/root/xxx/为项目实际根目录
# /path/to/gunicorn是在虚拟环境下通过 which gunicorn 命令查找到的gunicorn真实路径
# 例如/root/anaconda3/envs/ai_doctor/bin/gunicorn
[program:werobot]
command=/path/to/gunicorn -w 1 wr:robot.wsgi
directory=/root/xxx/
stopsignal=QUIT
stopasgroup=false
killasgroup=false
stdout_logfile=/var/log/werobot_out
stdout_logfile_maxbytes=1MB
stderr_logfile=/var/log/werobot_error
stderr_logfile_maxbytes=1MB
  • 10 配置主要逻辑服务
# 在/etc/supervisord.conf中添加以下配置,其中/root/xxx/为项目实际根目录
# /path/to/gunicorn是在虚拟环境下通过 which gunicorn 命令查找到的gunicorn真实路径
# 例如/root/anaconda3/envs/ai_doctor/bin/gunicorn
[program:main_serve]
command=/path/to/gunicorn -w 1 -b 0.0.0.0:5000 app:app
directory=/root/xxx/doctor_online/main_serve
stopsignal=QUIT
stopasgroup=false
killasgroup=false
stdout_logfile=/var/log/main_serve_out
stdout_logfile_maxbytes=1MB
stderr_logfile=/var/log/main_serve_error
stderr_logfile_maxbytes=1MB
  • 11 配置句子相关模型服务
# 在/etc/supervisord.conf中添加以下配置,其中/root/xxx/为项目实际根目录
# /path/to/gunicorn是在虚拟环境下通过 which gunicorn 命令查找到的gunicorn真实路径
[program:bert_serve]
command=/path/to/gunicorn -w 1 -b 0.0.0.0:5001 app:app
directory=/root/xxx/doctor_online/bert_serve
stopsignal=QUIT
stopasgroup=false
killasgroup=false
stdout_logfile=/var/log/bert_serve_out
stdout_logfile_maxbytes=1MB
stderr_logfile=/var/log/bert_serve_error
stderr_logfile_maxbytes=1MB
  • 12 配置redis服务
[program:redis]
command=redis-server 
  • 13 重启supervisord管理的服务
supervisorctl restart all
  • 14 进行测试
测试1: 关注公众号(新用户), 发送"我最近有些腹痛".

测试2: (老用户)发送"我最近有些腹痛"后, 继续发送"并且左腹部有一些红点".