实验机采用CentOS-7-x86_64-Minimal-1511版安装
1.关闭selinux
nano /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
2.安装netstat工具 - 不然没得ifconfig之类的命令~
yum instatll net-tools –y
3.安装pip
此处有坑~
No package python-pip available.
Error: Nothing to do
坑就不说了,直说能安装的步骤
[root@localhost www]# yum -y install epel-release #先执行这个~
[root@localhost www]# yum -y install python-pip #再安装就顺利了!!
// 假设项目路径 www/my_flask
4.安装VirtualEnv虚拟机
[root@localhost www]# pip install virtualenv
[root@localhost my_flask]# virtualenv venv
>> New python executable in venv/bin/python
>> Installing setuptools, pip...done.
[root@localhost my_flask]# source venv/bin/activate #进入venv虚拟机
(venv) [root@localhost my_flask]#
以下前缀为(venv)都表示在venv虚拟机操作
5.安装flask
(venv) [root@localhost my_flask]# pip install flask
5.1测试一下flask
(venv) [root@localhost my_flask]# touch test.py
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello PiaoYun!" if __name__ == '__main__': app.run(debug=True)
// 显示如下则falsk环境ok了~
(venv) [root@localhost my_flask]# python ./test.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger pin code: 548-063-937
6.安装uWSGI
(venv) [root@localhost my_flask]# pip install uwsgi
6.1配置uWSGI
(venv) [root@localhost my_flask]# touch uwsgi_config.xml
<uwsgi> <pythonpath>/www/my_flask/</pythonpath> <module>main</module> <callable>app</callable> <socket>127.0.0.1:9090</socket> <master/> <processes>4</processes> <memory-report/> </uwsgi>
7.安装nginx
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx
centos7中是用yum 安装nginx,在/etc/init.d 是没有它相关的文件的
sudo systemctl enable nginx // 开机自动启动
sudo systemctl start nginx
[root@localhost www]# cd /etc/nginx/conf.d
[root@localhost conf.d]# touch flask.conf //增加一个配置文件
server { listen 8888; server_name localhost; root /www/my_flask; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:9090; } #error_page 500 502 503 504 /50x.html; #location = /50x.html { # root html; #} }
[root@localhost conf.d]# service nginx restart //重启一下nginx
这时回到虚拟机环境执行:
(venv) [root@localhost my_flask]# uwsgi -x uwsgi_config.xml
浏览器打开 能看到 Hello PiaoYun! 则正常了!!
8.安装supervisor
yum install supervisor #如果这个安装不上,看下面~~
systemctl enable supervisord // 开机自动启动
这个步骤卡了我很久的时间,具体操作看这里:
http://stackoverflow.com/questions/31157928/supervisord-on-linux-centos-7-only-works-when-run-with-root
9.安装mysql
http://www.ahlinux.com/centos/23340.html
参考文章:
http://www.tuicool.com/articles/zUvqMr
如果你发现掉坑里了不要慌,先依赖包安装以下试试:
yum update
yum install python python-devel libxml2 libxml2-devel python-setuptools zlib-devel wget openssl-devel pcre pcre-devel sudo gcc make autoconf automaker
yum groupinstall "Development tools”
yum install gcc
发表评论