LNMP安装配置手册

LNMP安装配置手册

变更记录

日期

版本

修改原因/内容

修改人

审核

批准

2010-6-15

1.0

创建文档

查明

2010-6-17

1.1

增加PDO模块

查明

2010-10-21

1.2

增加nginx启动脚本

查明

2010-11-01

1.3

安装xwindows、OpenOffice、unoconv和swftools等

查明

目  录

1前言 4

1.1目的 4

1.2适用范围 4

1.3术语和缩略语 4

2系统安装配置 4

2.1服务器硬件要求说明 4

2.2系统软件环境和安装配置说明 4

2.2.1安装支持库 5

2.2.2安装mysqlsphinx 9

2.2.3安装postgresql数据库 24

2.2.4安装php及其扩展 24

2.2.5安装nginx 37

2.2.6其他软件安装 47

1前言

1.1目的

      

1.2适用范围

      

1.3术语和缩略语

      

2系统安装配置

2.1服务器硬件要求说明

服务器硬件最低配置要求

CPU: 3GHz

二级缓存:2M

内存:2G

硬盘:120G

带宽:5M

2.2系统软件环境和安装配置说明

centos5.4+nginx0.7.67+mysql5.1.34+php5.3.0+csft3.1+memcached1.4.5+httpcws1.0.0+freetds0.82+oracleclient10.2.0.4+vsftpd2.0.5

2.2.1安装支持库

tar xzvf 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 ../../

rm -rf libmcrypt-2.5.8

tar xzvf mhash-0.9.1.tar.gz
cd mhash-0.9.1/
./configure
make
make install
cd ../

rm -rf mhash-0.9.1

cp /usr/local/lib/libmcrypt.* /usr/lib
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

tar xzvf mcrypt-2.6.7.tar.gz
cd mcrypt-2.6.7/
./configure
make
make install
cd ../

rm -rf mcrypt-2.6.7

tar xzvf libiconv-1.13.tar.gz

cd libiconv-1.13

./configure --prefix=/usr
make
make install
cd ../

rm -rf libiconv-1.13

rpm –qa | grep zlib

tar xzvf zlib-1.2.3.tar.gz

cd zlib-1.2.3

./configure --prefix=/usr/local/zlib

make

make install

cd ../

rm –rf zlib-1.2.3

tar xzvf libtool-2.2.6b.tar.gz

cd libtool-2.2.6b

./configure –prefix=/usr

make

make install

cd ..

rm –rf libtool-2.2.6b

tar xzvf gettext-0.17.tar.gz
cd gettext-0.17/
./configure
make && make install
cd ../

rm –rf gettext-0.17

tar xzvf freetype-2.3.7.tar.gz
cd freetype-2.3.7/
./configure
make && make install
cd ../

rm –rf freetype-2.3.7
tar xzvf libpng-1.2.33.tar.gz
cd libpng-1.2.33/
./configure
make && make install
cd ../

rm –rf libpng-1.2.33
mkdir -pv /usr/local/lib/jpeg6/{,bin,lib,include,man/{,man1},man1}

mkdir /usr/local/man/man1
tar xzvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
vi configure
#.libtool改成/usr/bin/libtool
./configure --enable-static --enable-shared
make && make install
cd ../

rm –rf jpeg-6b
tar xzvf gd-2.0.35.tar.gz
cd gd-2.0.35/
./configure --prefix=/usr/local/gd --with-freetype --with-png --with-jpeg

rm –rf libtool

ln –s /usr/bin/libtool .
make
make install
cd ../

rm –rf gd-2.0.35

tar xzvf termcap-1.3.1.tar.gz

cd termcap-1.3.1/

./configure

make

make install

cd ../

rm -rf termcap-1.3.1

tar xzvf libxml2-2.6.32.tar.gz

cd libxml2-2.6.32/

./configure

make

make install

cd ../

tar xzvf openssl-0.9.8k.tar.gz

cd openssl-0.9.8k/

./config

make

make install

cd ../

unzip curl-7.16.2.zip

cd curl-7.16.2/

./configure

make

make install

cd ../

tar zxvf pcre-8.00.tar.gz
cd pcre-8.00/
./configure
make

make install
cd ../

2.2.2安装mysqlsphinx

2.2.2.1安装mysql

tar xzvf mysql-5.1.34.tar.gz
cd mysql-5.1.34

./configure --prefix=/usr/local/webserver/mysql --with-innodb --without-debug --with-unix-socket-path=/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --with-pthread --enable-thread-safe-client
make

make install

cd ..

groupadd mysql

useradd –g mysql –d /usr/local/webserver/mysql mysql


chmod +w /usr/local/webserver/mysql

cp mysql-5.1.34/support-files/my-medium.cnf /usr/local/webserver/mysql/my.cnf
cp –R mysql-5.1.34/support-files/mysql.server /usr/local/webserver/mysql/support-files

chown -R mysql.mysql /usr/local/webserver/mysql

vi /usr/local/webserver/mysql/my.cnf 编辑以下内容

[mysqld]

ft_min_word_len=1

#skip-federated

mysql帐号创建数据表

su mysql

/usr/local/webserver/mysql/bin/mysql_install_db --defaults-file=/usr/local/webserver/mysql/my.cnf --basedir=/usr/local/webserver/mysql --datadir=/usr/local/webserver/mysql/data --user=mysql --pid-file=/usr/local/webserver/mysql/mysqld.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock

启动服务

/usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/usr/local/webserver/mysql/my.cnf &

设置root账户密码

/usr/local/webserver/mysql/bin/mysqladmin –u root password ‘mysql’

/usr/local/webserver/mysql/bin/mysql -uroot -p

mysql>grant all on *.* to 'root'@'%' identified by 'mysql' with grant option;  //设置远程访问账号

随机启动

vi /etc/rc.local (/etc/rc.d/rc.local) 添加以下内容
/bin/sh -c 'cd /usr/local/webserver/mysql; ./bin/mysqld_safe --user=mysql &'

(或:cp /usr/local/webserver/mysql/support-files/mysql.server /etc/init.d/mysql

chmod +x /etc/init.d/mysql

chkconfig --level 345 mysql on)

或者使用启动脚本

vi /usr/local/webserver/mysql/share/mysql/mysql.server 修改以下内容

datadir=/usr/local/webserver/mysql/data

pid_file=$datadir/`/bin/hostname`.pid

/usr/local/webserver/mysql/share/mysql/mysql.server start|stop|restart|reload

导入数据并设置账号

CREATE DATABASE `sphinx` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `sphinx_counter` (

  `id` tinyint(1) NOT NULL,

  `lasttime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',

  PRIMARY KEY (`id`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `sphinx_wims` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `sid` int(11) NOT NULL,

  `title` varchar(200) NOT NULL,

  `content` text,

  `filetype` varchar(50) DEFAULT NULL,

  `project` varchar(250) DEFAULT NULL,

  `area` varchar(250) DEFAULT NULL,

  `category` text,

  `comment` text,

  `createtime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',

  `status` tinyint(1) NOT NULL DEFAULT '1',

  PRIMARY KEY (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

导入数据,并创建数据库sphinx的账号

2.2.2.2安装sphinx的中文升级版csft

安装中文分词mmseg

tar xzvf mmseg-3.1.tar.gz

cd mmseg-3.1/

./configure –prefix=/usr/local/webserver/mmseg

make

make install

cd ../

tar xzvf csft-3.1.tar.gz

cd csft-3.1

./configure --prefix=/usr/local/webserver/csft --with-mysql=/usr/local/webserver/mysql --with-mysql-includes=/usr/local/webserver/mysql/include/mysql --with-mysql-libs=/usr/local/webserver/mysql/lib/mysql --with-mmseg=/usr/local/webserver/mmseg --with-mmseg-includes=/usr/local/webserver/mmseg/include/mmseg --with-mmseg-libs=/usr/local/webserver/mmseg/lib

sed -i 's#-lm -lz -lexpat  -L/usr/local/lib -lpthread#& -liconv#' src/Makefile

make

make install

cd ..

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

cd mmseg-3.1/data

/usr/local/webserver/mmseg/bin/mmseg -u unigram.txt

cp unigram.txt.uni /usr/local/webserver/csft/uni.lib

vi /usr/local/webserver/csft/mmseg.ini 添加以下内容

[mmseg]

merge_number_and_ascii=1;

number_and_ascii_joint=.-;

compress_space=0;

seperate_number_ascii=1;

vi /usr/local/webserver/csft/etc/csft.conf 添加以下内容

source main

{

type = mysql

sql_host = localhost

sql_user = sphinx

sql_pass = sphinx

sql_db = sphinx

sql_port = 3306

sql_sock                                = /tmp/mysql.sock

sql_query_pre = SET NAMES utf8

sql_query_pre = REPLACE INTO sphinx_counter SELECT 1, MAX(createtime) FROM sphinx_wims

sql_query_range = SELECT MIN(id),MAX(id) FROM sphinx_wims WHERE status=1 and createtime<=\

                                                  (SELECT lasttime FROM sphinx_counter WHERE id=1)

sql_query = \

SELECT id,sid,projectid,title,content,filetype,project,area,category,comment,createtime,status FROM sphinx_wims \

WHERE id>=$start and id<=$end and status=1

sql_range_step = 1000

sql_attr_uint = status

sql_attr_uint = projectid

sql_attr_timestamp = createtime

sql_ranged_throttle = 100

}

source delta:main

{

sql_ranged_throttle = 100

sql_query_pre = SET NAMES utf8

sql_query_range = SELECT MIN(id),MAX(id) FROM sphinx_wims WHERE status=1 and createtime>\

                                                  (SELECT lasttime FROM sphinx_counter WHERE id=1)

sql_query                               = \

SELECT id,sid, projectid,title,content,filetype,project,area,category,comment,createtime,status FROM sphinx_wims \

         WHERE id>=$start and id<=$end and status=1

}

index main

{

source = main

path = /usr/local/webserver/csft/var/data/main

docinfo = extern

mlock = 0

morphology = none

min_word_len = 1

charset_type = zh_cn.utf-8

charset_dictpath = /usr/local/webserver/csft

charset_table  = \

U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, \

A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, \

U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, \

U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, \

U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, \

U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, \

U+0116->U+0117,U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, \

U+011D,U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, \

U+0134->U+0135,U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, \

U+013C,U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, \

U+0143->U+0144,U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, \

U+014B,U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, \

U+0152->U+0153,U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, \

U+0159,U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, \

U+0160->U+0161,U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, \

U+0167,U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, \

U+016E->U+016F,U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, \

U+0175,U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, \

U+017B->U+017C,U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, \

U+0430..U+044F,U+05D0..U+05EA, U+0531..U+0556->U+0561..U+0586, U+0561..U+0587, \

U+0621..U+063A, U+01B9,U+01BF, U+0640..U+064A, U+0660..U+0669, U+066E, U+066F, \

U+0671..U+06D3, U+06F0..U+06FF,U+0904..U+0939, U+0958..U+095F, U+0960..U+0963, \

U+0966..U+096F, U+097B..U+097F,U+0985..U+09B9, U+09CE, U+09DC..U+09E3, U+09E6..U+09EF, \

U+0A05..U+0A39, U+0A59..U+0A5E,U+0A66..U+0A6F, U+0A85..U+0AB9, U+0AE0..U+0AE3, \

U+0AE6..U+0AEF, U+0B05..U+0B39,U+0B5C..U+0B61, U+0B66..U+0B6F, U+0B71, U+0B85..U+0BB9, \

U+0BE6..U+0BF2, U+0C05..U+0C39,U+0C66..U+0C6F, U+0C85..U+0CB9, U+0CDE..U+0CE3, \

U+0CE6..U+0CEF, U+0D05..U+0D39, U+0D60,U+0D61, U+0D66..U+0D6F, U+0D85..U+0DC6, \

U+1900..U+1938, U+1946..U+194F, U+A800..U+A805,U+A807..U+A822, U+0386->U+03B1, \

U+03AC->U+03B1, U+0388->U+03B5, U+03AD->U+03B5,U+0389->U+03B7, U+03AE->U+03B7, \

U+038A->U+03B9, U+0390->U+03B9, U+03AA->U+03B9,U+03AF->U+03B9, U+03CA->U+03B9, \

U+038C->U+03BF, U+03CC->U+03BF, U+038E->U+03C5,U+03AB->U+03C5, U+03B0->U+03C5, \

U+03CB->U+03C5, U+03CD->U+03C5, U+038F->U+03C9,U+03CE->U+03C9, U+03C2->U+03C3, \

U+0391..U+03A1->U+03B1..U+03C1,U+03A3..U+03A9->U+03C3..U+03C9, U+03B1..U+03C1, \

U+03C3..U+03C9, U+0E01..U+0E2E,U+0E30..U+0E3A, U+0E40..U+0E45, U+0E47, U+0E50..U+0E59, \

U+A000..U+A48F, U+4E00..U+9FBF,U+3400..U+4DBF, U+20000..U+2A6DF, U+F900..U+FAFF, \

U+2F800..U+2FA1F, U+2E80..U+2EFF,U+2F00..U+2FDF, U+3100..U+312F, U+31A0..U+31BF, \

U+3040..U+309F, U+30A0..U+30FF,U+31F0..U+31FF, U+AC00..U+D7AF, U+1100..U+11FF, \

U+3130..U+318F, U+A000..U+A48F,U+A490..U+A4CF 

min_prefix_len = 0

min_infix_len = 0

ngram_len = 1

ngram_chars = \

U+4E00..U+9FBF, U+3400..U+4DBF, U+20000..U+2A6DF, U+F900..U+FAFF, \

U+2F800..U+2FA1F, U+2E80..U+2EFF, U+2F00..U+2FDF, U+3100..U+312F, U+31A0..U+31BF, \

U+3040..U+309F, U+30A0..U+30FF, U+31F0..U+31FF, U+AC00..U+D7AF, U+1100..U+11FF, \

U+3130..U+318F, U+A000..U+A48F, U+A490..U+A4CF

html_strip = 1

}

index delta:main

{

source                   = delta

path = /usr/local/webserver/csft/var/data/delta

morphology = none

}

indexer

{

mem_limit = 256M

}

searchd

{

listen = 3312

log = /usr/local/webserver/csft/var/log/searchd.log

query_log = /usr/local/webserver/csft/var/log/query.log

read_timeout = 5

max_children = 30

pid_file = /usr/local/webserver/csft/var/log/searchd.pid

max_matches = 10000

seamless_rotate = 1

preopen_indexes = 0

unlink_old = 1

}

启动sphinx前,先确认你已经建立相关数据库并且将127.0.0.1 localhost写入到/etc/hosts

建立主索引

/usr/local/webserver/csft/bin/indexer --config /usr/local/webserver/csft/etc/csft.conf --all

开启守护进程

/usr/local/webserver/csft/bin/searchd --config /usr/local/webserver/csft/etc/csft.conf

并将之添加到/etc/rc.local中,随机启动守护进程

或者使用启动脚本

vi /etc/init.d/csft 添加以下内容

#!/bin/sh

#

# csft - this script starts and stops the csft daemin

#

# chkconfig:   - 85 15

# description:  Sphinx is an full-text seatch server,\

#               csft is its chinese edition

# processname: searchd

# config:      /usr/local/webserver/csft/etc/csft.conf

# pidfile:     /usr/local/webserver/csft/var/log/searchd.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

csft="/usr/local/webserver/csft/bin/searchd"

prog=$(basename $csft)

CSFT_CONF_FILE="/usr/local/webserver/csft/etc/csft.conf"

lockfile=/var/lock/subsys/csft

start() {

    [ -x $csft ] || exit 5

    [ -f $CSFT_CONF_FILE ] || exit 6

    echo -n $"Starting $prog: "

    daemon $csft --config $CSFT_CONF_FILE

    retval=$?

    echo

    [ $retval -eq 0 ] && touch $lockfile

    return $retval

}

stop() {

    echo -n $"Stopping $prog: "

    killproc $prog -QUIT

    retval=$?

    echo

    [ $retval -eq 0 ] && rm -f $lockfile

    return $retval

}

restart() {

    stop

    start

}

reload() {

    configtest || return $?

    echo -n $"Reloading $prog: "

    killproc $csft -HUP

    RETVAL=$?

    echo

}

force_reload() {

    restart

}

rh_status() {

    status $prog

}

rh_status_q() {

    rh_status >/dev/null 2>&1

}

case "$1" in

    start)

        rh_status_q && exit 0

        $1

        ;;

    stop)

        rh_status_q || exit 0

        $1

        ;;

    restart)

        $1

        ;;

    reload)

        rh_status_q || exit 7

        $1

        ;;

    force-reload)

        force_reload

        ;;

    status)

        rh_status

        ;;

condrestart|try-restart)

        rh_status_q || exit 0

        ;;

    *)

        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"

        exit 2

esac

chmod +x /etc/init.d/csft

service csft start|stop|restart|reload

定时建立增量索引,合并主索引和增量索引

crontab -e

5,20,35,50 9-18 * * 1-5 /usr/local/webserver/csft/bin/indexer --rotate --config /usr/local/webserver/csft/etc/csft.conf delta 2>&1

6,21,36,51 9-18 * * 1-5 /usr/local/webserver/csft/bin/indexer --merge main delta --merge-dst-range deleted 0 0 --rotate 2>&1

2.2.2.3重新编译安装mysql,增加sphinx引擎

tar xzvf csft-3.1.tar.gz

tar xzvf mysql-5.1.34.tar.gz
cd mysql-5.1.34

cp –R ../csft-3.1/mysqlse storage/sphinx

sh BUILD/autorun.sh
./configure --prefix=/usr/local/webserver/mysql --with-plugins=sphinx --with-innodb --without-debug --with-unix-socket-path=/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --with-pthread --enable-thread-safe-client
make

make install

cd ..

重新启动服务

/usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/usr/local/webserver/mysql/my.cnf &

检查sphinx引擎是否成功安装

/usr/local/webserver/mysql/bin/mysql -uroot –p

mysql>show engines; //检查sphinx引擎是否安装成功

2.2.2.4数据库读写分离,从库安装及主从库同步配置(可选)

cd mysql-5.1.34
./configure --prefix=/usr/local/webserver/mysql3307 --with-innodb --without-debug --with-unix-socket-path=/tmp/mysql3307.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --with-pthread --enable-thread-safe-client
make && make install

cd ..

chmod +w /usr/local/webserver/mysql3307

cp mysql-5.1.34/support-files/my-medium.cnf /usr/local/webserver/mysql3307/my.cnf
cp –R mysql-5.1.34/support-files/mysql.server /usr/local/webserver/mysql3307/support-files

chown -R mysql.mysql /usr/local/webserver/mysql3307

主库配置

vi /usr/local/webserver/mysql/my.cnf 编辑以下内容

[mysqld]

log-bin=mysql-bin

server-id        = 1

binlog_do_db    = cc_phpcms

binlog_do_db    = cc_phpbb

/usr/local/webserver/mysql/bin/mysql -uroot –p

mysql> flush tables with read lock; //锁定主库的数据表,解锁unlock tables;

mysql> grant select,file,replication slave on *.* to backup@localhost identified by 'backup'; //设置备份库访问账号

mysql>show master status\G; //检查主库同步配置

从库配置

vi /usr/local/webserver/mysql3307/my.cnf编辑以下内容

[client]

port            = 3307

socket          = /tmp/mysql3307.sock

[mysqld]

port            = 3307

socket          = /tmp/mysql3307.sock

ft_min_word_len=1

#skip-federated

server-id       = 2

master-host     =   127.0.0.1

master-user     =   backup

master-password =   backup

master-port     =  3306

replicate-do-db =  cc_phpcms

replicate-do-db =  cc_phpbb

log-slave-updates

skip-slave-start

master-connect-retry=10

mysql帐号创建数据表

su mysql

/usr/local/webserver/mysql3307/bin/mysql_install_db --defaults-file=/usr/local/webserver/mysql3307/my.cnf --basedir=/usr/local/webserver/mysql3307 --datadir=/usr/local/webserver/mysql3307/data --user=mysql --pid-file=/usr/local/webserver/mysql3307/mysqld.pid --skip-locking --port=3307 --socket=/tmp/mysql3307.sock

启动服务(最后的&表示在后台运行)

/usr/local/webserver/mysql3307/bin/mysqld_safe --defaults-file=/usr/local/webserver/mysql3307/my.cnf &

设置root账户密码

/usr/local/webserver/mysql3307/bin/mysqladmin –u root password ‘mysql’

启动关闭同步服务

/usr/local/webserver/mysql3307/bin/mysql -uroot –p

mysql>change master to

mysql>master_host=’127.0.0.1’,

mysql>master_user=’backup’,

mysql>master_password=’backup’,

mysql>master_port=3307;

mysql> start slave; //启动同步服务,关闭服务stop slave

mysql>show slave status\G; //检查从库同步配置,Slave_IO_Running和Slave_SQL_Running须都为YES

随机启动

vi /etc/rc.local (/etc/rc.d/rc.local) 添加以下内容
/bin/sh -c 'cd /usr/local/webserver/mysql3307; ./bin/mysqld_safe --user=mysql &'

2.2.3安装postgresql数据库

tar xzvf postgresql-8.4.1.tar.gz

cd postgresql-8.4.1

/usr/local/webserver/php/bin/phpize

./configure --prefix=/usr/local/webserver/pgsql --without-readline

make

make install

cd ..

useradd postgres

mkdir /usr/local/webserver/pgsql/data

chown postgres.postgres /usr/local/webserver/pgsql/data

su postgres

初始化数据库

/usr/local/webserver/pgsql/bin/initdb -D /usr/local/webserver/pgsql/data

修改密码

/usr/local/webserver/pgsql/bin/psql -U postgres

postgres=# alter user postgres with password 'pgsql';

启动数据库

/usr/local/webserver/pgsql/bin/postgres -D /usr/local/webserver/pgsql/data &

并加入/etc/rc.local随机启动

2.2.4安装php及其扩展

2.2.4.1安装PHP

tar xzvf php-5.2.6.tar.gz
gzip -cd php-5.2.6-fpm-0.5.9.diff.gz | patch -d php-5.2.6 -p1
cd php-5.2.6/

./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql with-pgsql=/usr/local/webserver/pgsql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir=/usr --with-freetype-dir --with-jpeg-dir --with-png-dir  --with-mcrypt --with-gd=/usr/local/gd --with-zlib-dir=/usr/local/zlib --with-libxml-dir --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 --enable-ftp --enable-gd-native-ttf --with-openssl --with-ldap (--with-mssql=/usr/local/webserver/freetds)

(chcon -t textrel_shlib_t /usr/local/gd/lib/libgd.so.2.0.0)

sed -i 's#-lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt#& -liconv#' Makefile
make
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../

2.2.4.2安装扩展模块

图形库ImageMagickPHP扩展MagickWand

tar xjvf ImageMagick-6.5.8-10.tar.bz2

cd ImageMagick-6.5.8-10

./configure –prefix=/usr/local/imagemagick

make

make install

cd ..

tar xjvf MagickWandForPHP-1.0.8.tar.bz2

cd MagickWandForPHP-1.0.8

/usr/local/webserver/php/bin/phpize

./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-magickwand=/usr/local/imagemagick

make

make install

cd ..

加速和zend解密zendoptimizer

tar xzvf ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz

cd ZendOptimizer-3.3.0a-linux-glibc21-i386

./install.sh

php.ini文件路径:/usr/local/webserver/php/etc/

加速器eaccelerator(加速性能优于zendoptimzer,与其有冲突)

tar xjvf eaccelerator-0.9.6.tar.bz2
cd eaccelerator-0.9.6/
/usr/local/webserver/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

mkdir -p /usr/local/webserver/php/eaccelerator_cache

加速器APC(与eAccelerator二选一)

tar xzvf APC-3.1.3p1.tgz
cd APC-3.1.3p1/
/usr/local/webserver/php/bin/phpize
./configure --enable-apc-enable --enable-apc-mmap --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

memcache是分布式内存对象缓存系统memcached的php客户端扩展

memcached安装

tar xzvf libevent-1.4.3-stable.tar.gz

cd libevent-1.4.3-stable

./configure --prefix=/usr

make

make install

cd ..

tar xzvf memcached-1.4.5.tar.gz

cd memcached-1.4.5

./configure --prefix=/usr

make

make install

cd ..

启动memcached服务

/usr/bin/memcached -d -m64 -l127.0.0.1 -p11211 –uroot

并将之加入到/etc/rc.local中,随机启动

tar xzvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

配置php.ini后,使用memcache-test.php测试安装是否成功

中文分词scws(可选)

tar jxvf scws-1.0.1.tar.bz2

cd scws-1.0.1

./configure --prefix=/usr/local/webserver/scws

make

make install

/usr/local/webserver/scws/bin/scws –h

cd ..

tar jxvf dictutf8tar.bz2

tar jxvf dictgbktar.bz2

mv dict.*.xdb rules.*.ini /usr/local/webserver/scws/etc/

cd scws-1.0.1/phpext

/usr/local/webserver/php/bin/phpize

./configure --with-scws=/usr/local/webserver/scws --with-php-config=/usr/local/webserver/php/bin/php-config

make 

make install

cd ../../

中文分词httpcws

tar xzvf httpcws-1.0.0-i386-bin.tar.gz

mv httpcws-1.0.0-i386-bin /usr/local/webserver/httpcws

启动

ulimit –SHn 65535

/usr/local/webserver/httpcws/httpcws -d -x /usr/local/webserver/httpcws/dict/

并将之加入到/etc/rc.local中,随机启动

使用方法

GET: http://127.0.0.1:1985/?w=输入的文本(URL长度限制,文本为GBK编码,最好采用urlencode编码)

POST: curl –d 输入的文本 http://127.0.0.1:1985(长度无限制,文本为GBK编码,最好采用urlencode编码)

MSSqlServer客户端freetds

tar xzvf freetds-stable.tgz

cd freetds-0.82

./configure --prefix=/usr/local/webserver/freetds --with-tdsver=8.0 --enable-msdblib

make

make install

cd ..

touch /usr/local/webserver/freetds/include/tds.h

touch /usr/local/webserver/freetds/lib/libtds.a

vi /usr/local/webserver/freetds/etc/freetds.conf 添加以下内容(SqlServer数据库服务器IP地址为192.168.0.6)

[192.168.0.6]

host = 192.168.0.6

        port = 1433

        tds version = 8.0

        client charset = UTF-8

使用--with-mssql=/usr/local/webserver/freetds,重新编译安装php

Oracle客户端

rpm -ivh oracle-instantclient-basic-10.2.0.4-1.i386.rpm oracle-instantclient-devel-10.2.0.4-1.i386.rpm oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm

echo "/usr/lib/oracle/10.2.0.4/client/lib/" > /etc/ld.so.conf.d/oracle_client.conf

/sbin/ldconfig

rpm -qa | grep libaio (如果没有libaio, yum install libaio)

tar xzvf oci8-1.3.5.tgz

cd oci8-1.3.5

/usr/local/webserver/php/bin/phpize

CFLAGS="-I/usr/include/oracle/10.2.0.4/client/"
CXXFLAGS="-I/usr/include/oracle/10.2.0.4/client/"

./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-oci8=instantclient,/usr/lib/oracle/10.2.0.4/client/lib

make

make install

cd ..

bitset扩展

tar xzvf bitset-1.0.tgz

cd bitset-1.0

/usr/local/webserver/php/bin/phpize

./configure --with-php-config=/usr/local/webserver/php/bin/php-config

make

make install

cd ..

PDO数据库mysql扩展

tar xzvf PDO_MYSQL-1.0.2.tgz

cd PDO_MYSQL-1.0.2

/usr/local/webserver/php/bin/phpize

./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-mysql=/usr/local/webserver/mysql

make

make install

cd ..

PDO数据库pgsql扩展

tar xzvf PDO_PGSQL-1.0.2.tgz

cd PDO_PGSQL-1.0.2

/usr/local/webserver/php/bin/phpize

./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-pgsql=/usr/local/webserver/pgsql

make

make install

cd ..

vi /usr/local/webserver/php/etc/php.ini 编辑以下内容

extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"

output_buffering = On

date.timezone = Asia/Chongqing

[magickwand]

extension=magickwand.so

[zend_optimizer]

;zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.0

;zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.0

;zend_optimizer.version=3.3.0a

;zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so

;zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so

[eAccelerator]

extension="eaccelerator.so"

eaccelerator.shm_size="128"

eaccelerator.cache_dir="/usr/local/webserver/php/eaccelerator_cache"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="300"

eaccelerator.shm_prune_period="120"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

[apc]

;extension = apc.so

;apc.enabled = 1

;apc.cache_by_default = on

;apc.shm_segments = 1

;apc.shm_size = 64

;apc.ttl = 7200

;apc.user_ttl = 7200

;apc.num_files_hint = 0

;apc.write_lock = on

[memcache]

extension = memcache.so

[scws]

;extension = scws.so

;scws.default.charset = utf8

;scws.default.fpath = /usr/local/webserver/scws/etc

[oracle]

extension = oci8.so

[bitset]

extension = bitset.so

[pdo_mysql]

extension = pdo_mysql.so

[pdo_pgsql]

extension = pdo_pgsql.so

2.2.4.3配置和启动

groupadd www

useradd –g www www

php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi

如果安装 Nginx + PHP 用于程序调试,请将以下的<value name="display_errors">0</value>改为<value name="display_errors">1</value>,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页

mv /usr/local/webserver/php/etc/php-fpm.conf /usr/local/webserver/php/etc/php-fpm.conf.bak

vi /usr/local/webserver/php/etc/php-fpm.conf 添加以下内容

<?xml version="1.0" ?>

<configuration>

  All relative paths in this config are relative to php's install prefix

  <section name="global_options">

    Pid file

    <value name="pid_file">/usr/local/webserver/php/logs/php-fpm.pid</value>

    Error log file

    <value name="error_log">/usr/local/webserver/php/logs/php-fpm.log</value>

    Log level

    <value name="log_level">notice</value>

    When this amount of php processes exited with SIGSEGV or SIGBUS ...

    <value name="emergency_restart_threshold">10</value>

    ... in a less than this interval of time, a graceful restart will be initiated.

    Useful to work around accidental curruptions in accelerator's shared memory.

    <value name="emergency_restart_interval">1m</value>

    Time limit on waiting child's reaction on signals from master

    <value name="process_control_timeout">5s</value>

    Set to 'no' to debug fpm

    <value name="daemonize">yes</value>

  </section>

  <workers>

    <section name="pool">

      Name of pool. Used in logs and stats.

      <value name="name">default</value>

      Address to accept fastcgi requests on.

      Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'

      <value name="listen_address">127.0.0.1:9000</value>

      <value name="listen_options">

        Set listen(2) backlog

        <value name="backlog">-1</value>

        Set permissions for unix socket, if one used.

        In Linux read/write permissions must be set in order to allow connections from web server.

        Many BSD-derrived systems allow connections regardless of permissions.

        <value name="owner"></value>

        <value name="group"></value>

        <value name="mode">0666</value>

      </value>

      Additional php.ini defines, specific to this pool of workers.

      <value name="php_defines">

        <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>

        <value name="display_errors">1</value>

      </value>

      Unix user of processes

        <value name="user">www</value>

      Unix group of processes

        <value name="group">www</value>

      Process manager settings

      <value name="pm">

        Sets style of controling worker process count.

        Valid values are 'static' and 'apache-like'

        <value name="style">static</value>

        Sets the limit on the number of simultaneous requests that will be served.

        Equivalent to Apache MaxClients directive.

        Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi

        Used with any pm_style.

        <value name="max_children">128</value>

        Settings group for 'apache-like' pm style

        <value name="apache_like">

          Sets the number of server processes created on startup.

          Used only when 'apache-like' pm_style is selected

          <value name="StartServers">20</value>

          Sets the desired minimum number of idle server processes.

          Used only when 'apache-like' pm_style is selected

          <value name="MinSpareServers">5</value>

          Sets the desired maximum number of idle server processes.

          Used only when 'apache-like' pm_style is selected

          <value name="MaxSpareServers">35</value>

        </value>

      </value>

      The timeout (in seconds) for serving a single request after which the worker process will be terminated

      Should be used when 'max_execution_time' ini option does not stop script execution for some reason

      '0s' means 'off'

      <value name="request_terminate_timeout">0s</value>

      The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file

      '0s' means 'off'

      <value name="request_slowlog_timeout">0s</value>

      The log file for slow requests

      <value name="slowlog">logs/slow.log</value>

      Set open file desc rlimit

      <value name="rlimit_files">51200</value>

      Set max core size rlimit

      <value name="rlimit_core">0</value>

      Chroot to this directory at the start, absolute path

      <value name="chroot"></value>

      Chdir to this directory at the start, absolute path

      <value name="chdir"></value>

      Redirect workers' stdout and stderr into main error log.

      If not set, they will be redirected to /dev/null, according to FastCGI specs

      <value name="catch_workers_output">yes</value>

      How much requests each process should execute before respawn.

      Useful to work around memory leaks in 3rd party libraries.

      For endless request processing please specify 0

      Equivalent to PHP_FCGI_MAX_REQUESTS

      <value name="max_requests">10240</value>

      Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.

      Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)

      Makes sense only with AF_INET listening socket.

      <value name="allowed_clients">127.0.0.1</value>

      Pass environment variables like LD_LIBRARY_PATH

      All $VARIABLEs are taken from current environment

      <value name="environment">

        <value name="HOSTNAME">$HOSTNAME</value>

        <value name="PATH">/usr/local/bin:/usr/bin:/bin</value>

        <value name="TMP">/tmp</value>

        <value name="TMPDIR">/tmp</value>

        <value name="TEMP">/tmp</value>

        <value name="OSTYPE">$OSTYPE</value>

        <value name="MACHTYPE">$MACHTYPE</value>

        <value name="MALLOC_CHECK_">2</value>

      </value>

    </section>

  </workers>

</configuration>

启动php-cgi进程,监听127.0.0.19000端口,进程数为128(如果内存小于3GB,可以只开启64个进程)

ulimit -SHn 51200
/usr/local/webserver/php/sbin/php-fpm start   (start|stop|quit|restart|reload|logrotate)

并将之加入到/etc/rc.local中,随机启动

2.2.5安装nginx

tar xzvf nginx-0.7.67.tar.gz
cd nginx-0.7.67/
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
make

make install
cd ../

创建Nginx日志目录

mkdir -p /var/log/nginx
chmod +w /var/log/nginx
chown -R www.www /var/log/nginx


mkdir -p /usr/local/webserver/www
chmod +w /usr/local/webserver/www
chown -R www.www /usr/local/webserver/www

创建Nginx配置文件

mv /usr/local/webserver/nginx/conf/nginx.conf /usr/local/webserver/nginx/conf/nginx.conf.bak
vi /usr/local/webserver/nginx/conf/nginx.conf 添加以下内容

user www www;

worker_processes 8;

error_log /var/log/nginx/nginx_error.log crit;

pid /usr/local/webserver/nginx/nginx.pid;

worker_rlimit_nofile 51200;

events

{

  use epoll;

  worker_connections 51200;

}

http

{

  include       mime.types;

  default_type  application/octet-stream;

  add_header    X-UA-Compatible 'IE=EmulateIE7';

  server_names_hash_bucket_size 128;

  client_header_buffer_size 32k;

  large_client_header_buffers 4 32k;

  sendfile on;

  tcp_nopush on;

  keepalive_timeout 60;

  tcp_nodelay on;

  fastcgi_connect_timeout 300;

  fastcgi_send_timeout 300;

  fastcgi_read_timeout 300;

  fastcgi_buffer_size 64k;

  fastcgi_buffers 4 64k;

  fastcgi_busy_buffers_size 128k;

  fastcgi_temp_file_write_size 128k;

  gzip on;

  gzip_min_length  1k;

  gzip_buffers     4 16k;

  gzip_http_version 1.0;

  gzip_comp_level 2;

  gzip_types       text/plain application/x-javascript text/css application/xml;

  gzip_vary on;

  client_max_body_size 10m;

  server

  {

    listen       80;

    server_name  localhost;

    index index.html index.htm index.php;

    root  /usr/local/webserver/www;

    location ~ .*\.(php|php5)?$

    {

      fastcgi_pass  127.0.0.1:9000;

      fastcgi_index index.php;

      include fcgi.conf;

    }

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

    {

      expires      30d;

    }

    location ~ .*\.(js|css)?$

    {

      expires      1h;

    }

    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for';

    access_log  /var/log/nginx/access.log  access;

  }

  server

  {

    listen       80;

    server_name  pma.yinhoo.dev mantis.yinhoo.dev;

    index index.html index.htm index.php;

    if ($host ~* ^([^\.]*)\.yinhoo\.dev$) {

      set $name $1;

    }

    root  /usr/local/webserver/www/$name;

    location ~ .*\.(php|php5)?$

    {

      fastcgi_pass  127.0.0.1:9000;

      fastcgi_index index.php;

      include fcgi.conf;

    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

    {

      expires      30d;

    }

    location ~ .*\.(js|css)?$

    {

      expires      1h;

    }

  }

  server

  {

    listen  8080;

    server_name  localhost;

    location / {

      stub_status on;

      access_log   off;

    }

  }

}

vi /usr/local/webserver/nginx/conf/fcgi.conf 添加以下内容

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

检查配置文件是否正确

/usr/local/webserver/nginx/sbin/nginx –t

启动Nginx

ulimit -SHn 51200
/usr/local/webserver/nginx/sbin/nginx

并将之加入到/etc/rc.local中,随机启动

查看Nginx主进程号

ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'

杀掉nginx进程

kill -HUP `cat /usr/local/webserver/nginx/nginx.pid`

killall nginx

或者使用启动脚本

vi /etc/init.d/nginx 添加以下内容

#!/bin/sh

#

# nginx - this script starts and stops the nginx daemin

#

# chkconfig:   - 85 15

# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \

#               proxy and IMAP/POP3 proxy server

# processname: nginx

# config:      /usr/local/webserver/nginx/conf/nginx.conf

# pidfile:     /usr/local/webserver/nginx/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/webserver/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/webserver/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {

    [ -x $nginx ] || exit 5

    [ -f $NGINX_CONF_FILE ] || exit 6

    echo -n $"Starting $prog: "

    daemon $nginx -c $NGINX_CONF_FILE

    retval=$?

    echo

    [ $retval -eq 0 ] && touch $lockfile

    return $retval

}

stop() {

    echo -n $"Stopping $prog: "

    killproc $prog -QUIT

    retval=$?

    echo

    [ $retval -eq 0 ] && rm -f $lockfile

    return $retval

}

restart() {

    configtest || return $?

    stop

    start

}

reload() {

    configtest || return $?

    echo -n $"Reloading $prog: "

    killproc $nginx -HUP

    RETVAL=$?

    echo

}

force_reload() {

    restart

}

configtest() {

  $nginx -t -c $NGINX_CONF_FILE

}

rh_status() {

    status $prog

}

rh_status_q() {

    rh_status >/dev/null 2>&1

}

case "$1" in

    start)

        rh_status_q && exit 0

        $1

        ;;

    stop)

        rh_status_q || exit 0

        $1

        ;;

    restart|configtest)

        $1

        ;;

    reload)

        rh_status_q || exit 7

        $1

        ;;

    force-reload)

        force_reload

        ;;

    status)

        rh_status

        ;;

    condrestart|try-restart)

        rh_status_q || exit 0

        ;;

    *)

        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

        exit 2

esac

chmod +x /etc/init.d/nginx

service nginx start|stop|restart|reload

优化Linux内核参数

vi /etc/sysctl.conf

kernel.shmmax = 134217728

在末尾增加以下内容

net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000    65000

使配置立即生效

/sbin/sysctl –p

编写每天定时切割Nginx日志的脚本

vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh 输入以下内容

#!/bin/bash
# This script run at 00:00

# The Nginx logs path
logs_path="/usr/local/webserver/nginx/logs/"

mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`

设置crontab,每天凌晨00:00切割nginx访问日志

crontab –e

0 0 * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

2.2.6其他软件安装

2.2.6.1安装vsftpd服务

yum install vsftpd

vi /etc/vsftpd/vsftpd.conf 编辑以下内容

anonymous_enable=NO

passwd ftp (密码为ftp)

mkdir /usr/local/svn/apache/htdocs/wims

chown -R ftp.ftp /usr/local/svn/apache/htdocs/wims

mkdir /var/ftp/wims

chown –R ftp.ftp /var/ftp/wims

建立虚拟目录

mount --bind /usr/local/svn/apache/htdocs/wims /var/ftp/wims

并加入随机执行脚本(/etc/rc.local)

重启vsftpd服务

service vsftpd restart

随机启动

2.2.6.2服务器运行状况监测

chmod a+x /usr/local/webserver/www/wims/bin/check.sh

crontab –e 添加定时任务

55 */4 * * * /usr/local/webserver/www/wims/bin/check.sh

2.2.6.3全文搜索数据抓取

crontab –e 添加定时任务

0,15,30,45 9-18 * * 1-5 /usr/local/webserver/php/bin/php /usr/local/webserver/www/wims/bin/grab.php > /usr/local/webserver/www/wims/bin/grab.log

2.2.6.3安装xwindows

使用光盘作为本地源yum安装xwindows

首先挂载光盘或镜像

mount –t iso9660 –o loop /dev/cdrom /mnt/cdrom

mount –t iso9660 –o loop CentOS-xxx.iso /mnt/cdrom

然后修改本地源

vi /etc/yum.repos.d/CentOS-Media.repo 修改以下内容

[c5-media]

name=CentOS-$releasever - Media

baseurl=file:///mnt/cdrom/

        file:///media/CentOS/

        file:///media/cdrom/

        file:///media/cdrecorder/

gpgcheck=1

enabled=0

#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-5

yum安装

yum --disablerepo=\* --enablerepo=c5-media groupinstall "GNOME Desktop Environment"

若出现错误:Error: Missing Dependency: libgaim.so.0 is needed by package nautilus-sendto

yum --disablerepo=\* --enablerepo=c5-media install yum-utils

yumdownloader --disablerepo=\* --enablerepo=c5-media nautilus-sendto

cd /mnt/cdrom/CentOS/

rpm -Uvh --nodeps nautilus-sendto-0.7-5.fc6.i386.rpm

测试启动

startx

SSH连接显示中文

vi /etc/sysconfig/i18n 添加以下内容

LANG="zh_CN.GB18030"

LANGUAGE="zh_CN.GB18030:zh_CN.GBK:zh_CN.GB2312:zh_CN"

SUPPORTED="zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en"

SYSFONT="lat0-sun16"

使用光盘作为本地源yum安装vncserver

yum --disablerepo=\* --enablerepo=c5-media install vnc-server

配置vncserver

vi /etc/sysconfig/vncservers 修改以下内容

VNCSERVERS="2:root"

VNCSERVERARGS[2]="-geometry 800x600"

vncpasswd 设置密码(centos)

vi ~/.vnc/xstartup 修改以下内容

gnome-session &

#twm &

vi /etc/sysconfig/iptables 添加访问端口(netstat –nltp | grep vnc)

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5902 -j ACCEPT

service iptables start 重启防火墙

启动服务

service vncserver start

使用vncviewer作为客户端

Host:192.168.1.110:2

2.2.6.4安装转化工具(openoffice/unoconv/swftools/mencoder)

xwindows下安装OpenOffice

tar xzvf OOo_3.0.0_LinuxIntel_install_wJRE_zh-cn.tar.gz

cd OOO300_m9_native_packed-1_zh-CN.9358/

./setup

出现图形安装界面,选择自定义安装方式,选择Python-UNO Bridge组件

启动脚本

vi /etc/init.d/openoffice 添加以下内容

#!/bin/bash

# openoffice.org headless server script

#

# chkconfig: 2345 80 30

# description: headless openoffice server script

# processname: openoffice

SOFFICE_PATH=/usr/lib/openoffice.org3/program/soffice

XVFB_PATH=/usr/bin/Xvfb

case "$1" in

        start)

                export DISPLAY=:5.0

                $XVFB_PATH :5 -screen scrn 1024x768x24 &

                $SOFFICE_PATH -headless -nologo -display:5 -nofirststartwizard -accept="socket,host=127.0.0.1,port=8100;urp;StarOffice.ServiceManager" &                    

                echo "Starting OpenOffice headless server"

                ;;

        stop)

                echo "Stopping OpenOffice headless server."

                pkill soffice &

                pkill Xvfb &

                exit 1

                ;;

        *)

                echo "Usage: $0 {start|stop}"

                exit 1

                ;;

esac

exit 0

chmod +x /etc/init.d/openoffice

chkconfig --add openoffice

service openoffice start|stop 随机启动

安装unoconv(可选)

vi ~/.bash_profile 添加以下内容

export DISPLAY=localhost:1

source ~/.bash_profile 使其立即生效

tar xjvf unoconv-0.4.tar.bz2

cd unoconv-0.4

make install

安装swftools

tar xzvf swftools-0.9.1.tar.gz

cd swftools-0.9.1

./configure --prefix=/usr/local/webserver/swftools

make

make install

cd ..

安装mencoder(mplayer)+ffmpeg

vi /etc/ld.so.conf 添加以下内容

/usr/local/lib

/usr/lib

ldconfig

rpm –qa | grep gcc libtool ogg vorbis ruby(系统自带)

tar xjvf faad2-2.7.tar.bz2

cd faad2-2.7

./configure --enable-shared

make && make install

cd ..

rm –rf faad2-2.7

tar xjvf x264-snapshot-20101104-2245.tar.bz2

cd x264-snapshot-20101104-2245

./configure --enable-shared --disable-asm

make && make install

cd ..

rm -rf x264-snapshot-20101104-2245

tar xzvf openjpeg_v1_3.tar.gz

make && make install

cd ..

rm -rf OpenJPEG_v1_3

tar xzvf libtheora-1.1.0.tar.gz

cd libtheora-1.1.0

./configure --enable-shared

make && make install

cd ..

rm -rf libtheora-1.1.0

tar xzvf xvidcore-1.1.0.tar.gz

cd xvidcore-1.1.0/build/generic

./configure --enable-shared

make && make install

cd ../../..

rm -rf xvidcore-1.1.0

tar xzvf yamdi-1.4.tar.gz

cd yamdi-1.4

gcc yamdi.c -o yamdi -O2 -Wall  -D_FILE_OFFSET_BITS=647

cp yamdi /usr/bin/

cd ..

rm -rf yamdi-1.4

tar xzvf lame-398-2.tar.gz

cd lame-398-2

./configure –enable-shared

make && make install

cd ..

rm -rf lame-398-2

tar xzvf flvtool2-1.0.6.tgz

cd flvtool2-1.0.6

ruby setup.rb config

ruby setup.rb setup

ruby setup.rb install

cd ..

rm -rf flvtool2-1.0.6

tar xzvf libdts-0.0.2.tar.gz

cd libdts-0.0.2

./configure –enable-shared

make && make install

cd ..

rm -rf libdts-0.0.2

ldconfig

tar xjvf ffmpeg-export-snapshot.tar.bz2

cd ffmpeg-export-2010-11-05

./configure --enable-shared --enable-libvorbis --enable-memalign-hack --enable-gpl --enable-libx264 --enable-libopenjpeg --enable-libtheora --enable-libxvid --enable-libmp3lame --enable-nonfree --enable-postproc --enable-avfilter --enable-swscale --disable-yasm

make && make install

cd ..

rm -rf ffmpeg-export-2010-11-05

tar xjvf ffmpeg-php-0.6.0.tbz2

cd ffmpeg-php-0.6.0

/usr/local/webserver/php/bin/phpize

./configure --with-php-config=/usr/local/webserver/php/bin/php-config

vi ffmpeg_frame.c 修改以下内容

: %s/PIX_FMT_RGBA32/PIX_FMT_RGB32/g

make && make install

cd ..

rm -rf ffmpeg-php-0.6.0

tar xjvf essential-20071007.tar.bz2

mv essential-20071007 /usr/local/lib/codecs

chmod –R 755 /usr/local/lib/codecs

unzip windows-essential-20071007.zip

mv windows-essential-20071007 /usr/local/lib/wincodecs

chmod –R 755 /usr/local/lib/wincodecs

tar xzvf MPlayer-1.0rc3.tar.gz

cd MPlayer-1.0rc3

./configure --prefix=/usr/local/mplayer --enable-freetype --codecsdir=/usr/local/lib/codecs --win32codecsdir=/usr/local/lib/wincodecs --language=zh_CN

make && make install

cd ..

rm -rf MPlayer-1.0rc3

转化命令

/usr/local/mplayer/bin/mencoder file.avi -o file.swf -of lavf -oac mp3lame -lameopts abr:br=32:mode=3 -ovc lavc -lavcopts vcodec=flv:acodec=mp3:vbitrate=150:abitrate=16:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -srate 22050 -vf scale=350:-3 -sws 2

2.2.6.5文件服务器上安装apache+php+mysql

安装PHP

cd php-5.2.6

./configure --prefix=/usr/local/svn/php --with-mysql=/usr/local/webserver/mysql/ --with-apxs2=/usr/local/svn/apache/bin/apxs --enable-force-cgi-redirect

make

make install

cp php.ini-dist /usr/local/svn/php/lib/php.ini

cd ..

安装inotifytools-php

tar xzvf inotifytools-php.tar.gz

cd inotifytools-php

/usr/local/svn/php/bin/phpize

./configure --with-php-config=/usr/local/svn/php/bin/php-config

make && make install

cd ..

vi /usr/local/webserver/php/etc/php.ini 编辑以下内容

extension_dir="/usr/local/svn/php/lib/php/extensions/no-debug-non-zts-20060613/"

[inotify]

extension=inotify.so

vi /usr/local/svn/apache/conf/httpd.conf 添加以下内容

LoadModule php5_module        modules/libphp5.so

..

AddType application/x-httpd-php .php .phtml
AddType applicatoin/x-httpd-php-source .phps

重启apache服务

/usr/local/svn/apache/bin/apachectl restart

tar xzvf inotify-tools-3.14.tar.gz

cd inotify-tools-3.14

./configure

make && make install

lsb_release

2.2.6.6文档转化

crontab –e 添加定时任务

0 */6 * * 1-5 /usr/local/svn/php/bin/php /usr/local/webserver/www/wims/bin/convert.php > /usr/local/webserver/www/wims/bin/convert.log

脚本程序以root身份调研外部命令,使用super(可选)

tar xzvf super-3.30.0-tar.gz

cd super-3.30.0

./configure

make && make install

cd ..

rm –rf super-3.30.0

配置super

vi /usr/local/etc/super.tab 添加以下内容

converter /usr/local/svn/apache/htdocs/wims/bin/converter.py www,wimser

测试

su wimser

super converter file.pdf file.swf

你可能感兴趣的:(LNMP安装配置手册)