最強(qiáng)最實(shí)用一步步搭建centos配置python3,tornado服務(wù)器環(huán)境
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
進(jìn)入項(xiàng)目目錄,git clone
保存存儲(chǔ)username,passwd:
git config credential.helper store
之后執(zhí)行g(shù)it pull 輸入賬號(hào)密碼后會(huì)自動(dòng)保存下來(lái)
安裝pip依賴包
pip install -r requirements.txt
安裝pycurl報(bào)錯(cuò):
__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
報(bào)錯(cuò):
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的環(huán)境下安裝supervisor,再在其中運(yùn)行python3的服務(wù)
deactive # 退出python3虛擬環(huán)境
pip install supervisor
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisord.conf # 生成默認(rèn)配置文件
directory = /opt/server/server ; 程序的啟動(dòng)目錄
command = /opt/server/.pyenv/bin/python proxy_server.py ; 啟動(dòng)命令
autostart = true ; 在 supervisord 啟動(dòng)的時(shí)候也自動(dòng)啟動(dòng)
startsecs = 5 ; 啟動(dòng) 5 秒后沒(méi)有異常退出嚼贡,就當(dāng)作已經(jīng)正常啟動(dòng)了
autorestart = true ; 程序異常退出后自動(dòng)重啟
startretries = 3 ; 啟動(dòng)失敗自動(dòng)重試次數(shù)夫壁,默認(rèn)是 3
user = root ; 用哪個(gè)用戶啟動(dòng)
redirect_stderr = true ; 日志重定向
stdout_logfile=/var/log/server/out.log
stderr_log=/var/log/server/err.log
nginx
user nginx;
worker_processes 5; 進(jìn)程數(shù)
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
worker_rlimit_nofile 10240; worker進(jìn)程的最大打開文件數(shù)限制
events {
worker_connections 10000; 一個(gè)worker進(jìn)程同時(shí)打開的最大連接數(shù)
use epoll; 如果你使用Linux 2.6+,你應(yīng)該使用epoll赤炒。如果你使用*BSD,你應(yīng)該使用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數(shù)據(jù)庫(kù)軟件從默認(rèn)的程序列表中移除屹培,用mariadb代替了轴总。
yum install mariadb-server mariadb
yum install mysql
systemctl start mariadb #啟動(dòng)MariaDB