zoukankan      html  css  js  c++  java
  • 在linux上部署web环境

    1.升级python到2.7版本(通过源码包重新安装一个2.7版本的python):
    wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
    tar -zxf Python-2.7.9.tgz
    ./configure --prefix=/usr/local/python27/
    make && make install
    which python(查看可执行文件的位置)
    ln -s python2.7 python(建立软链接)


    2.让yum使用旧版2.6版本的python
    vim /usr/bin/yum
    把首行注释修改为 #!/usr/bin/python2.6

    3.安装pip
    wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
    python get-pip.py
    提示错误:zipimport.ZipImportError: can't decompress data; zlib not available
    此时需要:
    a-安装依赖zlib、zlib-devel
    b-重新编译python:
    ./configure
    在这里把Modules/Setup文件中的454行左右的,
    #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
    去掉注释
    zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
    make && make install
    重新做软链接,让系统路径的python指向新编译的python2.7版本
    python get-pip.py
    又失败了,提示:pip is configured with locations that require TLS/SSL
    需要安装2个依赖:yum -y install openssl openssl-devel
    再编译安装一次。。。。。
    python get-pip.py(终于成功!)
    pip被安装在python的可执行文件的同一目录。
    做软链接 ln -s /usr/local/python27/bin/pip /usr/bin/pip

    4.安装虚拟环境virtualenv和flask
    pip install virtualenv(安装)
    virtualenv --no-site-packages venv(建立虚拟环境,不安装任何系统中的第三方包)

    5.安装nginx
    yum install nginx(提示没有可用的源)
    解决方法:
    安装EPEL源(yum install epel-release)
    又报错:Cannot retrieve metalink for repository: epel. Please verify its path and try again
    解决方法:
    编辑/etc/yum.repos.d/epel.repo 取消baseurl的注释,把mirrorlist注释掉。
    设置nginx开机启动:
    chkconfig nginx on
    开启80端口,并重启iptables:
    vim /etc/sysconfig/iptables   然后一定在第一个-A的行的上面一行添加一行,不然会失败:-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
    service iptables restart
    启动nginx:
    service nginx start

    6.安装gunicorn
    pip install gunicorn(安装)
    gunicorn -w 4 -b 127.0.0.1:端口号 文件名:app(直接运行gunicorn)
    vim /etc/nginx/conf.d/default.conf(配置nginx):
    server {
        listen 80;

        location / {
            proxy_pass http://127.0.0.1:888; # 这里是指向 gunicorn host 的服务地址
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

    }
    重启nginx,ok!可以直接从80端口访问网站。

    7.使用supervisor
    最后一步,用进程管理工具supervisor把gunicorn作为服务来管理:
    pip install supervisor
    echo_supervisord_conf > supervisor.conf   # 生成 supervisor 默认配置文件
    vim supervisor.conf                       # 修改 supervisor 配置文件,添加 gunicorn 进程管理
    添加:
    [program:入口文件名]
    command=/root/aff/venv/bin/gunicorn -w4 -b0.0.0.0:888 入口文件名:app
    directory=/root/aff

    supervisord -c supervisor.conf(启动supervisor)
    supervisorctl shutdown (关闭supervisor)
    再启动时出现错误:Shut this program down first before starting supervisord.
    解决办法:
    unlink /tmp/supervisor.sock
    再启动。

    supervisor的基本使用命令

    supervisord -c supervisor.conf                             通过配置文件启动supervisor
    supervisorctl -c supervisor.conf status                    察看supervisor的状态
    supervisorctl -c supervisor.conf reload                    重新载入 配置文件
    supervisorctl -c supervisor.conf start [all]|[appname]     启动指定/所有 supervisor管理的程序进程
    supervisorctl -c supervisor.conf stop [all]|[appname]      关闭指定/所有 supervisor管理的程序进程


    8.安装mysql:
    yum install -y mysql-server mysql mysql-devel (安装)
    service mysqld start (启动)
    chkconfig mysqld on (开机自启动)
    mysqladmin -u root password 'new-password' (给root设置密码)

    ------------------------------------------
    9.vim配置

    vim配置(/etc/vimrc):
    set nu(显示行号)
    set expandtab(把tab转成空格)
    set ts=4(一个tab等于4个空格)
    set softtabstop=4(按退格时删除4个空格)
    set autoindent(自动缩进)
    解决vim没有颜色的方法:
    原因是securecrt使用的终端是VT100,而vim的配置中只有终端是xterm才有颜色。
    解决方法(修改配置文件):
    vim ~/.bashrc
    TERM=xterm
    export TERM
    然后用source命令重载一下配置文件。

    10.重建数据库
    直接使用flask的数据库模型重建:
    python admin.py shell
    from admin import db
    db.create_all()

  • 相关阅读:
    [Caffe] ubuntu14.04下使用OpenBLAS加速Caffe
    [CUDA] ubuntu14.04+cuda7.5下安装cudnn7.0
    ubuntu下virtualenv的复制
    SIFT特征学习笔记
    ubuntu14.04+opencv 3.0+python2.7安装及测试
    django之ORM
    django之路由(url)
    性能调优之MySQL篇四:MySQL配置定位以及优化
    性能调优之MySQL篇三:MySQL配置定位以及优化
    性能调优之MySQL篇二:MySQL配置文件My.ini配置文件优化
  • 原文地址:https://www.cnblogs.com/hqqq/p/6219401.html
Copyright © 2011-2022 走看看