flask应用部署——安装环境


虽然以前安装过但是没有记录,这次重新安装,趁机记录下来,省得满世界地找
>环境: centos7

安装nginx

参考资料
使用yum list nginx会发现nginx是1.6的版本,但现在nginx已经到了1.9,虽然不必那么新, 但是过旧的版本说不定会出现安全问题

# vim /etc/yum.repos.d/nginx.repo  

输入

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

然后

# yum list nginx  #你会发现nginx已经是1.8的版本
# yum install nginx
# systemctl start nginx #启动nginx

安装python3

centos7默认安装了python2.7的版本,但我习惯用python3,但是centos无法通过yum install python3安装, 只好自己编译了

安装必要的文件

# yum groupinstall "Development tools"
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel 
readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

下载python3源码

python3已到的python3.5,请按自己的需求下载

$ wget https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tgz
$ tar xz Python-3.4.4.tgz
$ cd Python-3.4.4
$ ./configure
$ make
# make install

如果提示c 编译器未找到
yum install gcc gcc-c++

安装supervisor

编译安装python3的时候python3-pip就已经安装好了

# pip3 install supervisor
Collecting supervisor
  Downloading supervisor-3.2.0.tar.gz (409kB)
    100% |################################| 413kB 972kB/s 
    Complete output from command python setup.py egg_info:
    Supervisor requires Python 2.4 or later but does not work on any version of Python 3.  You are using version 3.4.4 (default, Jan  6 2016, 11:01:55)
    [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)].  Please install using a supported version.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-qp0f7ft9/supervisor

报错,错误提示很明显,supervisor不支持python3

安装python2的pip

# yum install python-pip
# yum install python-devel #最好把这个也装上,以后会用到的
# pip install supervisor # 这里又有一个提示
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
# pip install --upgrade pip

安装python的虚拟环境virtualenv

# pip3 install virtualenv
$ mkdir www
$ cd www
$ virtualenv-3.4 venv
Using base prefix '/usr/local'
New python executable in venv/bin/python3.4
Also creating executable in venv/bin/python
Installing setuptools, pip, wheel...done.

建议在~/.bashrc中添加

alias ve='. venv/bin/activate'

以后只要使用ve就能进入虚拟环境

关于数据库的安装请参考我的另一篇文章postgresql学习1——安装

作者: honmaple
链接: https://honmaple.me/articles/2016/01/flask应用部署——安装环境.html
版权: CC BY-NC-SA 4.0 知识共享署名-非商业性使用-相同方式共享4.0国际许可协议
wechat
alipay

加载评论