1、添加源

sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

2、安装nginx、mysql、uwsgi

sudo yum install nginx mysql mysql-server mysql-devel python-devel
wget -q http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
sudo easy_install pip
sudo pip install uwsgi
sudo chkconfig --levels  mysqld on
sudo chkconfig --levels nginx on
sudo service nginx start
sudo service mysqld start
sudo /usr/bin/mysql_secure_installation

3、配置

sudo useradd -M -s /sbin/nologin carder
sudo usermod -G dialout,nginx carder
sudo usermod -G carder nginx
sudo usermod -G carder hubery
sudo usermod -G hubery carder
sudo mkdir -p /var/log/carder/nginx/iksdb
sudo mkdir /var/run/carder
sudo mkdir /var/lock/carder
sudo chown -R carder:carder /var/log/carder /var/run/carder /var/lock/carder
sudo chmod -R g+rw /var/log/carder /var/run/carder /var/lock/carder /var/log/nginx

4、安装dbapi

cd /opt
sudo mkdir iksdb
chown -R carder:carder iksdb
git clone git@bitbucket.org:dicovi/iksdb.git ./iksdb sudo pip install virtualenv
virtualenv venv
source ./venv/bin/activate
pip install flask
pip install flask-restful
pip install peewee
pip install hsahids
pip install simplejson
pip install mysql-python
pip install httplib2
pip install restclient
deactivate
copy ~/shortcuts.py ./venv/lib/python2./site-packages/playhouse/
sudo ln -sf /opt/iksdb/etc/uwsgi_iksdb.ini /etc/uwsgi_iksdb.ini
sudo ln -sf /opt/iksdb/etc/nginx/uwsgi_params /etc/nginx/uwsgi_params
sudo ln -sf /opt/iksdb/etc/nginx/nginx.conf /etc/nginx/nginx.conf
sudo ln -sf /opt/iksdb/etc/nginx/conf.d/iksdb.conf /etc/nginx/conf.d/iksdb.conf
sudo ln -sf /opt/iksdb/etc/init.d/nginx /etc/init.d/nginx
sudo ln -sf /opt/iksdb/etc/init.d/uwsgi_iksdb /etc/init.d/uwsgi_iksdb
sudo chkconfig --levels  uwsgi_iksdb on
sudo echo > /var/run/carder/nginx.pid
sudo echo > /var/run/carder/uwsgi_iksdb.pid
sudo service uwsgi_iksdb start
sudo service nginx restart

5、防火墙配置

除了iptables外,如果selinux打开,nginx会无法绑定端口:

要么关闭selinux,临时:

sudo setenforce
sudo getenforce

永久:
修改 /etc/selinux/config 文件, 将SELINUX=enforcing改为SELINUX=disabled,重启机器

要么配置selinux:

sudo yum provides /usr/sbin/semanage
sudo yum -y install policycoreutils-python
sudo semanage port -l|grep http
sudo semanage port -a -t http_port_t -p tcp sudo service nginx restart

6、错误处理

①uswgi_iksdb.log ->

问题:

192.168.0.187:16000 [pid: 2986|app: 0|req: 31842/64002] 192.168.0.156 () {32 vars in 404 bytes} [Thu Nov 12 18:27:57 2015] GET /api/v1.0 => generated 14 bytes in 1028 msecs (HTTP/1.0 200) 2 headers in 71 bytes (2 switches on core 0)

Thu Nov 12 18:27:54 2015 - *** uWSGI listen queue of socket "127.0.0.1:6000" (fd: 3) full !!! (101/100) ***

分析:

以这个错误为基础,查询了下相关资料,应该是系统级别参数的问题,具体可以参考 linux man page listen(2).

lzz注: 简单的理解就是每个监听的socket,在没有accept之前,等待处理的socket队列长度,linux(至少在centos6.6中)默认是128,在我这个编译的uwsgi中默认是100,也就是说没有调整系统参数之前,最高也就是128。

那么怎样才能把队列的长度调整变长呢?

* 必须调整系统参数,使其生效 * 必须调整uwsgi配置,然后重启应用

解决:

修改系统参数,编辑 /etc/sysctl.conf, 添加,

#对于一个经常处理新连接的高负载 web服务环境来说,默认的  太小了
net.core.somaxconn =
​#表示SYN队列的长度,默认为1024,加大队列长度为8192,可以容纳更多等待连接的网络连接数
net.ipv4.tcp_max_syn_backlog =
#网卡设备将请求放入队列的长度
net.core.netdev_max_backlog =

使用 sysctl -p 重新加载参数。

uwsgi调整,编辑 /etc/uwsgi_iksdb.ini, 添加,

listen=

重启应用,加载配置。

②/var/log/carder/nginx/error.log ->

问题:

2015/11/11 10:39:01 [emerg] 2260#0: bind() to 0.0.0.0:20000 failed (13: Permission denied)

解决:

关掉或配置selinux。

问题:

2015/11/12 18:46:03 [alert] 30272#0: setrlimit(RLIMIT_NOFILE, 32768) failed (1: Operation not permitted)

分析:

nginx.conf 中配置的 worker_rlimit_nofile 32768; 不能生效,需要调整系统参数。

解决:

In /etc/sysctl.conf or a conf file in /etc/sysconfig.d
fs.file-max = 1000000

and run /etc/sysctl -p /etc/sysctl.conf
in /etc/security/limits.conf
www-data soft nofile 500000
www-data hard nofile 800000
( assuming nginx is running as www-data ).

问题:

2015/11/12 19:11:38 [alert] 2271#0: setrlimit(RLIMIT_NOFILE, 32768) failed (13: Permission denied)

分析:

遇到这种 Permission denied 的看来一般是selinux的问题。

解决:

关掉或配置selinux。

问题:

2015/11/13 11:50:26 [alert] 2243#0: 1024 worker_connections are not enough

~$ http_load -parallel 1000 -fetches 10000 urls

...

http://192.168.0.187:16000/api/v1.0/snode: byte count wrong
10000 fetches, 1000 max parallel, 5.16988e+06 bytes, in 16.1539 seconds
516.988 mean bytes/connection
619.046 fetches/sec, 320039 bytes/sec
msecs/connect: 24.4066 mean, 1009.83 max, 0.016 min
msecs/first-response: 1510.02 mean, 2920.64 max, 0.142 min
790 bad byte counts
HTTP response codes:
  code 200 -- 9210
  code 500 -- 206

解决:编辑修改/etc/nginx/ngxin.conf,

events {
worker_connections ;
}

③/var/log/carder/nginx/iksdb/error.log ->

问题:

2015/11/11 11:35:16 [crit] 2258#0: *3 connect() to 127.0.0.1:6000 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: iksdbservices.vvshare.info, request: "GET /api/v1.0/customer HTTP/1.1", upstream: "uwsgi://127.0.0.1:6000", host: "127.0.0.1:16000"

解决:

关闭或配置selinux

问题:

2015/11/12 12:07:34 [alert] 2265#0: *2012 socket() failed (24: Too many open files) while connecting to upstream, client: 192.168.0.156, server: iksdbservices.vvshare.info, request: "GET /api/v1.0 HTTP/1.0", upstream: "uwsgi://127.0.0.1:6000", host: "192.168.0.187:16000"

解决:

调整系统参数

问题:

2015/11/12 12:07:42 [crit] 2265#0: accept4() failed (24: Too many open files)

解决:

调整系统参数

问题:

2015/11/12 12:08:00 [error] 2265#0: *15937 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.156, server: iksdbservices.vvshare.info, request: "GET /api/v1.0 HTTP/1.0", upstream: "uwsgi://127.0.0.1:6000", host: "192.168.0.187:16000"

解决:

调整系统参数

问题:

2015/11/12 12:14:47 [error] 2265#0: *36669 upstream prematurely closed connection while reading response header from upstream, client: 192.168.0.156, server: iksdbservices.vvshare.info, request: "GET /api/v1.0 HTTP/1.0", upstream: "uwsgi://127.0.0.1:6000", host: "192.168.0.187:16000"

解决:

调整系统参数

问题:

2015/11/12 12:20:10 [error] 2265#0: *50893 upstream timed out (110: Connection timed out) while connecting to upstream, client: 192.168.0.156, server: iksdbservices.vvshare.info, request: "GET /api/v1.0 HTTP/1.0", upstream: "uwsgi://127.0.0.1:6000", host: "192.168.0.187:16000"

解决:

调整系统参数

问题:

2015/11/13 10:47:29 [alert] 2235#0: *959 1024 worker_connections are not enough while connecting to upstream, client: 192.168.0.156, server: iksdbservices.vvshare.info, request: "GET /api/v1.0 HTTP/1.0", upstream: "uwsgi://127.0.0.1:6000", host: "192.168.0.187:16000"

解决:

编辑配置nginx.conf

参考:

CentOS 6.0 semanage: http://blog.csdn.net/pengwupeng2008/article/details/14451113

Nginx配置性能优化: http://blog.csdn.net/xifeijian/article/details/20956605

【uwsgi】 listen queue of socket (fd: 3) 错误分析: http://blog.csdn.net/orangleliu/article/details/48531759

Increase “Open Files Limit”: https://rtcamp.com/tutorials/linux/increase-open-files-limit/

Re: increasing open files limit: https://forum.nginx.org/read.php?2,248426,248427

socket: Too many open files (24) apache bench lighttpd: http://stackoverflow.com/questions/1504577/socket-too-many-open-files-24-apache-bench-lighttpd

Re: worker_connections is not enough while connecting to upstream: https://forum.nginx.org/read.php?2,2896,2900

DBAPI部署的更多相关文章

  1. airflow部署

    官网: http://airflow.apache.org/installation.html 原理: https://www.cnblogs.com/cord/p/9450910.html 安装: ...

  2. [原]CentOS7.2部署node-mapnik

    转载请注明表作者think8848及出处(http://think8848.cnblogs.com) node-mapnik依赖项中要求g++ >= 5, toolchain (>= GL ...

  3. 使用Visual Studio 2015 开发ASP.NET MVC 5 项目部署到Mono/Jexus

    最新的Mono 4.4已经支持运行asp.net mvc5项目,有的同学听了这句话就兴高采烈的拿起Visual Studio 2015创建了一个mvc 5的项目,然后部署到Mono上,浏览下发现一堆错 ...

  4. 通过Jexus 部署 dotnetcore版本MusicStore 示例程序

    ASPNET Music Store application 是一个展示最新的.NET 平台(包括.NET Core/Mono等)上使用MVC 和Entity Framework的示例程序,本文将展示 ...

  5. 结合Jexus + Kestrel 部署 asp.net core 生产环境

    ASP.NET Core 是微软的全新的框架.这一框架的目标 ︰ 跨平台 针对云应用优化 解除 System.Web 的依赖. 获得下面三个方面的优势,你可以把它认为是一个C# 版本的NodeJS: ...

  6. 4.Windows Server2012 R2里面部署 MVC 的网站

    网站部署之~Windows Server | 本地部署:http://www.cnblogs.com/dunitian/p/4822808.html#iis 后期会在博客首发更新:http://dnt ...

  7. Win10 IIS本地部署MVC网站时不能运行?

    异常处理汇总-服 务 器 http://www.cnblogs.com/dunitian/p/4522983.html 部署后出现这个错误: 打开文件目录后发现是可以看见目录的,静态页面也是可以打开的 ...

  8. 再部署一个 instance 和 Local Network - 每天5分钟玩转 OpenStack(131)

    上一节部署了 cirros-vm1 到 first_local_net,今天我们将再部署 cirros-vm2 到同一网络,并创建 second_local_net. 连接第二个 instance 到 ...

  9. 将 instance 部署到 OVS Local Network - 每天5分钟玩转 OpenStack(130)

    上一节创建了 OVS 本地网络 first_local_net,今天我们会部署一个 instance 到该网络并分析网络结构.launch 一个 instance,选择 first_local_net ...

随机推荐

  1. php读取zip文件(删除文件,提取文件,增加文件)实例

    <?php /* php 从zip压缩文件中提取文件 */ $zip = new ZipArchive; if ($zip->open('jQuery五屏上下滚动焦点图代码.zip') = ...

  2. js动态增加html页面元素

    问题:   <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2 ...

  3. Python之路【第十六篇】:Django【基础篇】

    Python之路[第十六篇]:Django[基础篇]   Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了O ...

  4. “REST”——Representational State Transfer(表述性状态转移)

    Representational State Transfer http://www.infoq.com/cn/articles/understanding-restful-style/#anch10 ...

  5. VS2008 Windows Form项目安装包生成详解

    2008 Windows Form项目的发布对有经验的程序员来说,可能不值一提,但对很多新手来说却不知道如何操作,因为在很多关于Visual Studio的书籍中也没有相关介绍,权威如<C# 2 ...

  6. mgo中DBRef-数据添加测试

    2014-1-25 在设计mongo数据库时遇到这样一个问题,日志信息表需要引用人员信息表的数据.如果是结构化数据库,基本上不用想太多的东西.由于刚接触非结构化数据库,按着书上的理解由于日志数量较多, ...

  7. Substance 6 设置 watermark(水印)

    http://www.qumake.com/articles/2011/04/18/1303094833690.html ——————————————————————————————————————— ...

  8. IBindCtx接口定义

    IBindCtx接口定义

  9. CString转换成char*

    CString转换成char* :charSource = (char*)strSource.GetBuffer(0); 法2:charSource = (char*)strSource.GetBuf ...

  10. [华清远见]FPGA公益培训

    本套视频教程为华清远见 网络公益培训活动,主讲人:姚远老师,华清远见高级讲师. ------------------------------------------------------------ ...