最强最实用一步步搭建centos配置python3,tornado服务器环境

easyinstall

yum install python-setuptools

rpm方式安装

centos7

yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum makecache

yum install python36u
yum -y install python36u-pip
yum -y install python36u-devel

centos6.8

wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
tar -zxvf Python-3.6.4.tgz
cd Python-3.6.4
./configure –prefix=/usr/local/python
make && make install
echo PATH=’/usr/local/python/bin/:$PATH’ >> /etc/profile
source /etc/profile

virtualenv

easy_install virtualenv

virtualenv .pyenv –python=python3.6

source .pyenv/bin/activate

git

yum install git

进入项目目录,git clone
保存存储username,passwd:

git config credential.helper store

之后执行git pull 输入账号密码后会自动保存下来

安装pip依赖包

pip install -r requirements.txt
安装pycurl报错:
__main__.ConfigurationError: Could not run curl-config: [Errno 2] No such file or directory: 'curl-config': 'curl-config'
缺少依赖包,解决:
yum install gcc libffi-devel python-devel libcurl-devel

报错:
ImportError: pycurl: libcurl link-time ssl backend (nss) is different from compile-time ssl backend (openssl)
解决:
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=nss
export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include
pip install pycurl –compile –no-cache-dir

supervisor

supervisor不支持python3,所以我们需要在python2的环境下安装supervisor,再在其中运行python3的服务
deactive # 退出python3虚拟环境
pip install supervisor
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisord.conf # 生成默认配置文件

directory = /opt/server/server ; 程序的启动目录
command = /opt/server/.pyenv/bin/python proxy_server.py  ; 启动命令
autostart = true     ; 在 supervisord 启动的时候也自动启动
startsecs = 5        ; 启动 5 秒后没有异常退出,就当作已经正常启动了
autorestart = true   ; 程序异常退出后自动重启
startretries = 3     ; 启动失败自动重试次数,默认是 3
user = root          ; 用哪个用户启动
redirect_stderr = true ; 日志重定向
stdout_logfile=/var/log/server/out.log
stderr_log=/var/log/server/err.log

nginx

user nginx;
worker_processes 5; 进程数

error_log /var/log/nginx/error.log;

pid /var/run/nginx.pid;

worker_rlimit_nofile 10240; worker进程的最大打开文件数限制

events {
    worker_connections 10000; 一个worker进程同时打开的最大连接数
    use epoll; 如果你使用Linux 2.6+,你应该使用epoll。如果你使用*BSD,你应该使用kqueue
}

proxy_next_upstream error;

upstream tornadoes {
    server 127.0.0.1:8000;
}

server {
    listen 80;
    server_name www.example.org *.example.org;

    location / {
       proxy_pass http://tornadoes;
    }
}

mysql

CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。
yum install mariadb-server mariadb
yum install mysql

systemctl start mariadb #启动MariaDB

文章来源于互联网,如有雷同请联系站长删除:centos安装python3,tornado环境

发表评论