17-01 软件云主机上线部署
购买云主机
国内云服务器平台:
阿里云: https://www.aliyun.com/
腾讯云: https://www.163yun.com
网易蜂巢: https://www.163yun.com
部署环境准备
购买的云主机一般带centos操作系统,因此我们需要安装python/ Mysql/ nginx/ git等工具.
步骤1: root用户登录后创建部署用户"producer", 因为使用root用户部署软件会有安全隐患.
[root@zksgy-Base /]# useradd producer [root@zksgy-Base /]# passwd producer Changing password for user producer. New password: BAD PASSWORD: The password contains the user name in some form Retype new password: passwd: all authentication tokens updated successfully. # 删除用户 userdel -r 用户名
步骤2: 确定云主机操作系统:centos
查询系统版本
[root@zksgy-Base /]# su producer [producer@zksgy-Base /]$ uname -a Linux zksgy-Base 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 6 15:49:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux [producer@zksgy-Base /]$ cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)
步骤3: 配置Linux源 参考:配置Linux源
步骤4: 安装mysql 参考:数据库MySQL安装 Windows和Linux
步骤5: 安装nginx 参考:centos7 yum 安装配置nginx
- 添加CentOS 7 Nginx yum资源库
- sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
- sudo yum install -y nginx
步骤6: 安装git
访问git官网下载工具
步骤7:安装python和Virtualenv 参考:Linux下安装Python3 pip 和虚拟环境Virtualenv
步骤8: 启动虚拟环境,安装Flask及其扩展包
步骤9: 启动项目
步骤10: https证书配置
XXXX is not in the sudoers file. This incident will be reported解决方法
- 安装nginx
- 添加CentOS 7 Nginx yum资源库
- sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
- sudo yum install -y nginx
- 添加CentOS 7 Nginx yum资源库
- 安装 Mysql
查看数据库Mysql的文档
- 安装git
- sudo yum install git
- git clone 你的地址
- 安装python,请查看 python环境安装 + Linux共享目录
- 安装扩展
- source /data/www/python3_vir/bin/activate
- pip install -r requirements.txt
- 启动项目
- export ops_config=production
- 启动方式
- python manage.py runserver(单进程)
- uwsgi --ini uwsgi.ini (多进程)
- https证书
- 参考文章:https://fanzheng.org/archives/21