标签:clone turn gre service npm load 建立 procs 多个
mkdir data 目录文件夹
cd data 进入data文件夹
mkdir nginx 创建安装nginx的文件夹
mkdir server 存放代码的文件夹
mkdir logs 存放日志的文件夹
mkdir backup 备份代码的文件夹
mkdir softs 软件存放的位置
mkdir virtual 虚拟环境的位置
mkdir scripts 脚本的运行位置
mkdir scp_codes 上传的代码
apt-get install python-virtualenv (ubuntu已经安装过,可省略)
virtualenv -p /usr/bin/python3 api_server (采用他,安装在本文件夹,)
mkvirtualenv api_server(不要用它,它会自己安装到其他地方)
source api_server/bin/activate (在虚拟环境的active进入虚拟环境)
安装的软件会在虚拟环境下的bin目录下
解压
cd ~/data/softs/
tar xf pcre-8.39.tar.gz
配置
cd ~/data/softs/pcre-8.39
./configure
编译
make
安装
sudo make install
解压
cd ~/data/softs/
tar xf nginx-1.10.2.tar.gz
配置
cd nginx-1.10.2/
./configure --prefix=/root/data/nginx 安装在root/data下面的nginx文件夹
编译
make
安装
make install
查看进程
ps aux | grep nginx
检查
sudo ~/data/nginx/sbin/nginx -t
开启
sudo ~/data/nginx/sbin/nginx
关闭
sudo ~/data/nginx/sbin/nginx -s stop
重载
sudo ~/data/nginx/sbin/nginx -s reload
pip install gunicorn
复制代码
from werkzeug.contrib.fixers import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app)
复制代码
例:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
from werkzeug.contrib.fixers import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app)
app.run()
复制代码
最简单的方式为
gunicorn 入口文件名:app
复制代码
默认是监听127.0.0.1:8000
如果是要处理高并发则要开多个进程和修改监听端口的画
gunicorn -w 4 -b 127.0.0.1:8000 入口文件名:app
复制代码保存在supervisord 里面的etc/supervisord.d目录下添加一个logo.ini配置文件
vim /etc/supervisord.d/logo.ini
[program:logo_api_server]
directory = /data/api-service #代码存放的地方
command = /usr/local/python3/bin/gunicorn -w 4 -b :5005 LogoSeverApi:app #-w的参数根据CPU的核数来定,不要超过CPU的核数
#process_name = %(process_num)s ; process_name expr (default %(program_name)s)
#process_name = %(process_num)s
#numprocs = 4 ; number of processes copies to start (def 1)
numprocs_start = 1
autostart = true ; start at supervisord start (default: true)
autorestart = unexpected ; whether/when to restart (default: unexpected)
startsecs = 10 ; number of secs prog must stay running (def. 1)
startretries = 3 ; max # of serial start failures (default 3)
user = dev
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /data/api-service/logs/supervisor.log
这样就可以启动4个进程同时处理HTTP请求,提高系统的使用效率及性能。 还可以把端口8000改为其他
而在实际应用中,应使用后台执行的方式启动服务
nohup 启动服务的命令 &
复制代码
即
nohup gunicorn -w 4 -b 127.0.0.1:8000 入口文件名:app &
复制代码
这时你可以在本机的浏览器上访问127.0.0.1:8000,浏览器上就会出现Hello World!
注意:如果是想通过外网访问的话就要把ip改为内网的ip
配置改为
server {
listen 80;
server_name example.org; # 这是HOST机器的外部域名,用地址也行
location / {
proxy_pass http://127.0.0.1:8000; # 这里是指向 gunicorn host 的服务地址
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
复制代码
这样启动之后80端口就可以转发到8000端口了
nginx -t
复制代码
若出现一下内容,则表示配置成功
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
复制代码
nginx -s reload
复制代码
在已经运行了Gunicorn的前提下,在浏览器访问127.0.0.1就会出现Hello World!了
输入命令
pstree -ap|grep gunicorn
yum install wget
2.1.下载python3.6
wget http://cdn.npm.taobao.org/dist/python/3.6.5/Python-3.6.5.tgz
2.2.解压安装包
tar -zxvf Python-3.6.5.tgz
---------------------
yum install -y gcc zlib*
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
---------------------
./configure --prefix=/usr/local/python3 --with-ssl
make && make install
echo "export PATH=$PATH:/usr/local/python3/bin/" >>/etc/profile
source /etc/profile
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
---------------------
yum install supervisor -y
如果报如下错误,安装yum的扩展源
安装yum的扩展源
yum install epel-*
在/etc/supervisord.d目录下添加一个logo.ini配置文件
vim /etc/supervisord.d/logo.ini
内容如下:
[program:logo_api_server]
directory = /data/api-service #代码存放的地方
command = /usr/local/python3/bin/gunicorn -w 4 -b :5005 LogoSeverApi:app #-w的参数根据CPU的核数来定,不要超过CPU的核数
\#process_name = %(process_num)s ; process_name expr (default %(program_name)s)
\#process_name = %(process_num)s
\#numprocs = 4 ; number of processes copies to start (def 1)
numprocs_start = 1
autostart = true ; start at supervisord start (default: true)
autorestart = unexpected ; whether/when to restart (default: unexpected)
startsecs = 10 ; number of secs prog must stay running (def. 1)
startretries = 3 ; max # of serial start failures (default 3)
user = dev
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /data/api-service/logs/supervisor.log
mkdir /data
cd /data
git clone http://zhangxiaoyang:messi1020@git.epweike.net:3000/graphics/logo_api api-servicels -
cd /data/api-service/
yum install cairo-devel
pip3 install --upgrade pip
pip3 install -r requirements.txt
标签:clone turn gre service npm load 建立 procs 多个
原文地址:https://www.cnblogs.com/gaidy/p/9784919.html