nginx,uwsgi,web.py,memcached环境搭建
从最干净的环境安装 ? vim tmux mysql nginx uwsgi pylibmc 源里有的并且版本较新的直接yum装就可以了. yum里比较有用的指令包括 yum install 软件名 安装软件 yum search 名字 查询有关的软件信息 yum info 名字 查寻软件源的相关信息 yum install vim ?文
从最干净的环境安装 ?
- vim
- tmux
- mysql
- nginx
- uwsgi
- pylibmc
源里有的并且版本较新的直接yum装就可以了.
yum里比较有用的指令包括
- yum install 软件名 安装软件
- yum search 名字 查询有关的软件信息
- yum info 名字 查寻软件源的相关信息
-
yum install vim
?文本编辑器 -
yum install python-setuptools
?python库安装工具 easy_install -
yum install mysql-server mysql
?mysql -
yum install make gcc gcc-c++
?编译软件时用到的安装工具 -
yum install wget
?下载工具
基本软件安装完成,现在编一个最简单的软件练手.
安装 tmux
下载源码 http://tmux.sourceforge.net/
解压 tar -xvf tmux*.tar.gz
切换到tmux源码目录 cd tmux*
检测安装环境,生成make文件 ?./configure
最后一行报错:
configure: error: "libevent not found"
可以google一下这个错误也会有解决方法,不过感觉提示可以知道是libevent这个库没有安装
yum search
可以查看这些库的相关信息
yum search libevent
Matched: libevent libevent-devel.i686 : Header files, libraries and development documentation for: libevent libevent.i686 : Abstract asynchronous event notification library
估计libevent-devel
和libevent
都有用,都装一下.
yum install libevent libevent-devel
再./configure
这次提示的是
configure: error: “curses not found”
同上yum search
然后yum install
再./configure
, 没有提示error了,并且提示生成了make文件.
make make install
练手完毕,开始安装web环境需要的软件.
编译安装nginx,源里的nginx是7.X的,但是8.0的nginx才支持uwsgi,所以要自己编译.
先看一下这个网页里有nginx的依赖库,直接yum装一下就好了
yum -y install gcc gcc-c++ glibc glibc-devel glib2 glib2-devel autoconf libmcrypt libmcrypt-devel mhash mhash-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel libidn libidn-devel zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel mysql mysql-server mysql-devel
基本上该装的库都装了, 然后去官网下载稳定版本的库的源码.
然后
./configure make make install
如果需要自己定制编译参数的话可以看下面的文章:
- 1
- 2
这两篇文章讲了nginx的编译参数,和如何把nginx添加到系统的服务里,使用service启动和停止的方法,值得注意的是如果使用了自定义编译参数,需要更改nginx启动文件的相应的路径.
我的编译参数如下:
nginx: configure arguments: –prefix=/usr/sbin –sbin-path=/usr/sbin/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –pid-path=/var/run/nginx.pid –lock-path=/var/lock/subsys/nginx –http-log-path=/var/log/nginx/access.log
安装py库
easy_install web.py 不用说了 easy_install bpython 一个增强型的python命令行工具,代码提示很不错
安装uwsgi
uwsgi 下载 http://projects.unbit.it/uwsgi/wiki/WikiStart
make 出错, 安装python-devel
make 出错, python setup.py install
安装pylibmc
下面文章讲解了pylibmc的安装过程
link
libevent直接yum安装就可以了,记得安装libevent-devel,不用编译安装
libmemcached 5.0,需要如下编译参数,如果没有据说话报错,另外最好更改一下安装路径,因为so库默认会安装在/usr/local/lib/里,但是so库的查找路径默认没有这个文件夹,当然可以更改一下so的查找路径,有兴趣可以google一下,为了简单,这里直接改安装路径了
./configure –prefix /usr –disable-64bit CFLAGS=”-O3 -march=i686″ –prefix=/usr
下载pylibmc的源码,是上面那个c库的py封装,据说可用性比较强 pylibmc 1.2.0
这个库直接运行python setup.py install
就可以了,如果没有出错就安装完成了
安装好以下,在源码路径下有runtest.py,可以测试一下是否安装成功了, 但是测试的时候要确保memcached处于运行状态.
如果提示一下错误按一下nose就可以了
Traceback (most recent call last): File “./runtests.py”, line 15, in import nose ImportError: No module named nose
最后按一下py的mysql库easy_install MySQL-python
之后就是mysql添加用户的配置了 mysql
之后是配置的工作
首先找到nginx的配置文件nginx.conf, 如果是编译安装的话,同级目录下会有一个default的拷贝,所以放心改就是了.
去掉里面的server块,然后include自己的server配置文件.
如我的配置文件/home/user/conf/nginx.conf
就把
server{ listen 80; …………………… }
替换为
include /home/user/conf/nginx.conf;
自己的server配置文件内容如下:
server{ listen 80; server_name localhost; root /home/hao/code/webpy/; location / { index index.html; uwsgi_pass 127.0.0.1:9090; include uwsgi_params; } }
uwsgi程序监听在9090端口, index.py文件内容如下:
import web urls = ( ‘/(.*)’, ‘hello’ ) app = web.application(urls, globals()) class hello: def GET(self, name): if not name: name = ‘World’ return ‘Hello, ‘ + name + ‘!’ application = app.wsgifunc()
注意不是app.run()
uwsgi的启动参数可以去官网看,http://projects.unbit.it/uwsgi/wiki/Doc
下面附带自己的启停脚本
start.sh
要记得chmode +x start.sh,给予执行权限.
#!/bin/bash rm log/*.log uwsgi -s :9090 -w index -p 4 -t 10 -M –limit-as 128 -d log/uwsgi.log –harakiri-verbose –listen 10 #–disable-logging memcached -d -vv > log/memcached.11211.log 2>&1 memcached -d -p 11212 -u 11212 -vv > log/memcached.11212.log 2>&1
删除log文件,uwsgi启动监听在9090端口,并且起两个memcached服务器
stop.sh 要记得chmode +x stop.sh,给予执行权限
#!/bin/bash killall -9 uwsgi killall -9 memcached
很粗暴,杀死所有相关进程
restart.sh 同上
#!/bin/bash ./stop.sh ./start.sh
就是掉一下停,再调一下启..
原文地址:nginx,uwsgi,web.py,memcached环境搭建, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

When the Nginx server goes down, you can perform the following troubleshooting steps: Check that the nginx process is running. View the error log for error messages. Check the syntax of nginx configuration. Make sure nginx has the permissions you need to access the file. Check file descriptor to open limits. Confirm that nginx is listening on the correct port. Add firewall rules to allow nginx traffic. Check reverse proxy settings, including backend server availability. For further assistance, please contact technical support.
