时间: 2012-04-29 / 分类: WEB后端编程 - 开发与实践 / 浏览次数: / 0 个评论 发表评论
CentOS5+Nginx-1.2.0+Php 5.2.17+MySQL 5.1.62+ZendOptimizer-3.3.9+eaccelerator-0.9.6.1+memcache…
WEB前端开发中的一些编程风格和书...
黄金分割与摄影构图
CSS Hack浏览器兼容IE6+IE7+IE8+IE9+FF
12条经典摄影技巧

新搭建了一个Linux服务器,以后命令基本都是运行通过的,做一下配置的备忘:
《LNMP服务器架构 5+-1.2.0+ 5.2.17+ 5.1.62+-3.3.9+-0.9.6.1+-2.2.6+_-1.0.2》[阿米酷]

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。
代表版本有:debian、centos、ubuntu、fedora、gentoo等。
[1]   Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
[2]   Mysql是一个小型关系型数据库管理系统。
[3]   Php是一种 HTML 内嵌式的语言,是一种在服务器端执行的嵌入HTML文档的脚本语言。
[4]   这四种软件均为免费软件,组合到一起,成为一个免费、高效的网站服务系统。

一 安装准备

关闭防火墙

service iptables stop

关闭 SELINUX, cp 命令直接覆盖,不需要提示

sed -i “s/SELINUX=enforcing/SELINUX=disabled/g” /etc/sysconfig/selinux

setenforce 0

sed -i “s/alias cp=’cp -i’/#alias cp=’cp -i’/g” ~/.bashrc

su –

下载的软件都放到 /wwwroot/data/soft

mkdir /wwwroot/data/soft/config -p

cd /wwwroot/data/soft

配置yum

wget http://blog.lrenwang.com/down/CentOS-Base.repo

cp   CentOS-Base.repo  /etc/yum.repos.d/

卸载httpd(rpm -q httpd 查看是否安装)

yum remove -y httpd

更新所需的安装包

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers patch zip

更新时区

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

下载lnmp所需的软件

wget http://nginx.org/download/nginx-1.2.0.tar.gz

wget http://www.php.net/get/php-5.2.17.tar.bz2/from/cn.php.net/mirror

wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz

wget ftp://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.1/mysql-5.1.58.tar.gz

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz

wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0

wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0

wget http://pecl.php.net/get/memcache-2.2.6.tgz

wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz

下载配置文件

cd config

wget http://blog.lrenwang.com/down/soft/config/my.cnf

wget http://blog.lrenwang.com/down/soft/config/php.ini

wget http://blog.lrenwang.com/down/soft/config/php-fpm.conf

wget http://blog.lrenwang.com/down/soft/config/nginx.conf

wget http://blog.lrenwang.com/down/soft/config/fcgi.conf

cd ../

二安装php5.2.17 mysql-5.1.58

1、编译安装PHP 5.2.17所需的支持库:

tar zxvf libiconv-1.13.tar.gz

cd libiconv-1.13/

./configure –prefix=/usr/local

make

make install

cd ../

 

tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8/

./configure

make

make install

/sbin/ldconfig

cd libltdl/

./configure –enable-ltdl-install

make

make install

cd ../../

 

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure

make

make install

cd ../

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la

ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8

ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a

ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la

ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so

ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

 

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

/sbin/ldconfig

./configure

make

make install

cd ../

 

 

2、编译安装mysql-5.1.58

/usr/sbin/groupadd mysql

/usr/sbin/useradd -g mysql mysql

tar zxvf mysql-5.1.58.tar.gz

cd mysql-5.1.58/

./configure –prefix=/usr/local//mysql/ –enable-assembler –with-charset=utf8 –with-extra-charsets=all –enable-thread-safe-client –with-big-tables –with-readline –with-ssl –with-embedded-server –enable-local-infile –with-plugins=innobase

 

make && make install

chmod +w /usr/local/lnmp/mysql

chown -R mysql:mysql /usr/local/lnmp/mysql

ln -s /usr/local/lnmp/mysql/lib/mysql/libmysqlclient.so.16 /usr/lib/

cd ../

mkdir /wwwroot/data/mysql/

cp config/my.cnf /wwwroot/data/mysql/my.cnf

chown mysql:mysql /wwwroot/data/mysql/

 

 

生成数据库 启动服务进程 修改密码

/usr/local/lnmp/mysql/bin/mysql_install_db –basedir=/usr/local/lnmp/mysql –datadir=/wwwroot/data/mysql/data –user=mysql

/usr/local/lnmp/mysql/bin/mysqld_safe –defaults-file=/wwwroot/data/mysql/my.cnf  &

/usr/local/lnmp/mysql/bin/mysqladmin -uroot password “123456” -p

 

进入mysql 查看状态(可以不做)

/usr/local/lnmp/mysql/bin/mysql -uroot -p123456

status

exit

 

3、编译安装PHP(FastCGI模式)

tar jxvf php-5.2.17.tar.bz2

gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1

cd php-5.2.17/

./configure –prefix=/usr/local/lnmp/php –with-config-file-path=/usr/local/lnmp/php/etc –with-mysql=/usr/local/lnmp/mysql –with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-ldap –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soap

make ZEND_EXTRA_LIBS=’-liconv’

make install

cd ../

cp config/php.ini /usr/local/lnmp/php/etc/php.ini

 

4、创建www用户和组,以及供amiku.cn使用的目录:

/usr/sbin/groupadd www

/usr/sbin/useradd -g www www

mkdir -p /wwwroot/data/www/amiku.cn

chmod +w /wwwroot/data/www/amiku.cn

chown -R www:www /wwwroot/data/www/amiku.cn

 

5、创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):

cp config/php-fpm.conf /usr/local/lnmp/php/etc/php-fpm.conf

 

 

6、启动php-cgi进程,监听127.0.0.1的9000端口,进程数为64(根据内存情况来定),用户为www:

ulimit -SHn 65535

/usr/local/lnmp/php/sbin/php-fpm start

 

三、安装Nginx1.2.0

1、安装Nginx所需的pcre库:

tar zxvf pcre-8.12.tar.gz

cd pcre-8.12/

./configure

make && make install

cd ../

 

2、安装Nginx

tar zxvf nginx-1.2.0.tar.gz

cd nginx-1.2.0/

./configure –user=www –group=www –prefix=/usr/local/lnmp/nginx –with-http_stub_status_module –with-http_ssl_module

make && make install

cd ../

 

 

3、创建Nginx日志目录

mkdir -p /wwwroot/data/logs

chmod +w /wwwroot/data/logs

chown -R www:www /wwwroot/data/logs

 

4、创建Nginx配置文件

cp config/nginx.conf /usr/local/lnmp/nginx/conf/nginx.conf

cp config/fcgi.conf /usr/local/lnmp/nginx/conf/fcgi.conf

 

5、启动Nginx

ulimit -SHn 65535

/usr/local/lnmp/nginx/sbin/nginx

 

四、配置开机自动启动Nginx + PHP +Mysql

echo “ulimit -SHn 65535” >> /etc/rc.d/rc.local

echo “/usr/local/lnmp/php/sbin/php-fpm start” >> /etc/rc.d/rc.local

echo “/usr/local/lnmp/nginx/sbin/nginx” >> /etc/rc.d/rc.local

echo “/usr/local/lnmp/mysql/bin/mysqld_safe –defaults-file=/wwwroot/data/mysql/my.cnf  &” >> /etc/rc.d/rc.local

 

chkconfig –level 2345 iptables off

 

常用命令

数据库

停止数据库

/usr/local/lnmp/mysql/bin/mysqladmin -uroot -p123456 shutdown

 

启动数据库

/usr/local/lnmp/mysql/bin/mysqld_safe –defaults-file=/wwwroot/data/mysql/my.cnf  &

 

php

/usr/local/lnmp/php/sbin/php-fpm start|stop|reload

 

nginx

开始

/usr/local/lnmp/nginx/sbin/nginx

 

停止

/usr/local/lnmp/nginx/sbin/nginx -s stop

 

平滑加载

/usr/local/lnmp/nginx/sbin/nginx -s reload

 

 

 

 

 

 

 

 

来自:http://blog.163.com/szy8706@yeah/blog/static/627131852011629455960/

 

 

 

 

 

# wget http://pecl.php.net/get/memcache-2.2.6.tgz

# wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2

# wget http://nchc.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2

 

# wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9--glibc23-i386.tar.gz

#wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

 

 

 

编译安装PHP5扩展

tar zxvf memcache-2.2.6.tgz
cd memcache-2.2.6
/usr/local/lnmp/php/bin/phpize

(

//在此处可能会出现错误“运行phpize时出现:Cannot find autoconf. Please check your autoconf installation”,这时需要安装m4和autoconf库,如下:
yum -y install m4
yum -y install autoconf

)

./configure –with-php-config=/usr/local/lnmp/php/bin/php-config
make && make install

cd ../
编译安装eaccelerator

tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
/usr/local/lnmp/php/bin/phpize
./configure  –enable-eaccelerator=shared –with-php-config=/usr/local/lnmp/php/bin/php-config
make && make install
cd ../

 

 

创建缓存目录

mkdir /wwwroot/data/eaccelerator

chmod 777 /wwwroot/data/eaccelerator

 

 

修改php.ini

vi /usr/local/lnmp/php/etc/php.ini

查找:extension_dir = “./”,修改为extension_dir = “/usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20060613/”

将 “output_buffering = Off” 修改为 ” output_buffering = On ”

文件末尾增加此行 extension = “memcache.so”

然后再增加以下内容到php.ini最尾部:

[eaccelerator]

zend_extension=”/usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”

eaccelerator.shm_size=”64″

eaccelerator.cache_dir=”/wwwroot/data/eaccelerator”

eaccelerator.enable=”1″

eaccelerator.optimizer=”1″

eaccelerator.check_mtime=”1″

eaccelerator.debug=”0″

eaccelerator.filter=””

eaccelerator.shm_max=”0″

eaccelerator.shm_ttl=”3600″

eaccelerator.shm_prune_period=”3600″

eaccelerator.shm_only=”0″

eaccelerator.compress=”1″

eaccelerator.compress_level=”9″

 

[root@server php-5.2.17]# /usr/local/lnmp/php/bin/php -v

PHP 5.2.17 (cli) (built: Jul  5 2011 13:29:58)

Copyright (c) 1997-2010 The PHP Group

Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator

 

 

安装PDO

tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
/usr/local/lnmp/php/bin/phpize
./configure –with-php-config=/usr/local/lnmp/php/bin/php-config –with-pdo-mysql=/usr/local/lnmp/mysql
make && make install

cd ../

 

 

安装ZendOptimizer-3.3.9

tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.9-linux-glibc23-i386
cp data/5_2_x_comp/ZendOptimizer.so /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20060613/

 

修改php.ini

vi /usr/local/lnmp/php/etc/php.ini

底部添加

extension = “pdo_mysql.so”

[Zend]

zend_extension=”/usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20060613/ZendOptimizer.so”

zend_optimizer.enable_loader = 1

zend_optimizer.optimization_level=0

zend_optimizer.disable_licensing=0

      站点地图 | 关于我 | 返回顶部
    Copyright © 2001-2013 { amiku.cn | zhangshunjin.com }. Powered by 

    阿米酷

    张顺金


    浙ICP备11002820号-1