search
HomeDatabaseMysql Tutorialnginx,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 名字 查寻软件源的相关信息
  1. yum install vim ?文本编辑器
  2. yum install python-setuptools ?python库安装工具 easy_install
  3. yum install mysql-server mysql ?mysql
  4. yum install make gcc gcc-c++ ?编译软件时用到的安装工具
  5. 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-devellibevent都有用,都装一下.

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

就是掉一下停,再调一下启..

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft