设为首页 收藏本站
查看: 942|回复: 0

LNMP安装配置手册

[复制链接]

尚未签到

发表于 2015-11-16 10:27:21 | 显示全部楼层 |阅读模式
  
  
  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&#43;FF10..U&#43;FF19->0..9, 0..9, U&#43;FF41..U&#43;FF5A->a..z, U&#43;FF21..U&#43;FF3A->a..z, \
  A..Z->a..z, a..z, U&#43;0149, U&#43;017F, U&#43;0138, U&#43;00DF, U&#43;00FF, U&#43;00C0..U&#43;00D6->U&#43;00E0..U&#43;00F6, \
  U&#43;00E0..U&#43;00F6, U&#43;00D8..U&#43;00DE->U&#43;00F8..U&#43;00FE, U&#43;00F8..U&#43;00FE, U&#43;0100->U&#43;0101, U&#43;0101, \
  U&#43;0102->U&#43;0103, U&#43;0103, U&#43;0104->U&#43;0105, U&#43;0105, U&#43;0106->U&#43;0107, U&#43;0107, U&#43;0108->U&#43;0109, \
  U&#43;0109, U&#43;010A->U&#43;010B, U&#43;010B, U&#43;010C->U&#43;010D, U&#43;010D, U&#43;010E->U&#43;010F, U&#43;010F, \
  U&#43;0110->U&#43;0111, U&#43;0111, U&#43;0112->U&#43;0113, U&#43;0113, U&#43;0114->U&#43;0115, U&#43;0115, \
  U&#43;0116->U&#43;0117,U&#43;0117, U&#43;0118->U&#43;0119, U&#43;0119, U&#43;011A->U&#43;011B, U&#43;011B, U&#43;011C->U&#43;011D, \
  U&#43;011D,U&#43;011E->U&#43;011F, U&#43;011F, U&#43;0130->U&#43;0131, U&#43;0131, U&#43;0132->U&#43;0133, U&#43;0133, \
  U&#43;0134->U&#43;0135,U&#43;0135, U&#43;0136->U&#43;0137, U&#43;0137, U&#43;0139->U&#43;013A, U&#43;013A, U&#43;013B->U&#43;013C, \
  U&#43;013C,U&#43;013D->U&#43;013E, U&#43;013E, U&#43;013F->U&#43;0140, U&#43;0140, U&#43;0141->U&#43;0142, U&#43;0142, \
  U&#43;0143->U&#43;0144,U&#43;0144, U&#43;0145->U&#43;0146, U&#43;0146, U&#43;0147->U&#43;0148, U&#43;0148, U&#43;014A->U&#43;014B, \
  U&#43;014B,U&#43;014C->U&#43;014D, U&#43;014D, U&#43;014E->U&#43;014F, U&#43;014F, U&#43;0150->U&#43;0151, U&#43;0151, \
  U&#43;0152->U&#43;0153,U&#43;0153, U&#43;0154->U&#43;0155, U&#43;0155, U&#43;0156->U&#43;0157, U&#43;0157, U&#43;0158->U&#43;0159, \
  U&#43;0159,U&#43;015A->U&#43;015B, U&#43;015B, U&#43;015C->U&#43;015D, U&#43;015D, U&#43;015E->U&#43;015F, U&#43;015F, \
  U&#43;0160->U&#43;0161,U&#43;0161, U&#43;0162->U&#43;0163, U&#43;0163, U&#43;0164->U&#43;0165, U&#43;0165, U&#43;0166->U&#43;0167, \
  U&#43;0167,U&#43;0168->U&#43;0169, U&#43;0169, U&#43;016A->U&#43;016B, U&#43;016B, U&#43;016C->U&#43;016D, U&#43;016D, \
  U&#43;016E->U&#43;016F,U&#43;016F, U&#43;0170->U&#43;0171, U&#43;0171, U&#43;0172->U&#43;0173, U&#43;0173, U&#43;0174->U&#43;0175, \
  U&#43;0175,U&#43;0176->U&#43;0177, U&#43;0177, U&#43;0178->U&#43;00FF, U&#43;00FF, U&#43;0179->U&#43;017A, U&#43;017A, \
  U&#43;017B->U&#43;017C,U&#43;017C, U&#43;017D->U&#43;017E, U&#43;017E, U&#43;0410..U&#43;042F->U&#43;0430..U&#43;044F, \
  U&#43;0430..U&#43;044F,U&#43;05D0..U&#43;05EA, U&#43;0531..U&#43;0556->U&#43;0561..U&#43;0586, U&#43;0561..U&#43;0587, \
  U&#43;0621..U&#43;063A, U&#43;01B9,U&#43;01BF, U&#43;0640..U&#43;064A, U&#43;0660..U&#43;0669, U&#43;066E, U&#43;066F, \
  U&#43;0671..U&#43;06D3, U&#43;06F0..U&#43;06FF,U&#43;0904..U&#43;0939, U&#43;0958..U&#43;095F, U&#43;0960..U&#43;0963, \
  U&#43;0966..U&#43;096F, U&#43;097B..U&#43;097F,U&#43;0985..U&#43;09B9, U&#43;09CE, U&#43;09DC..U&#43;09E3, U&#43;09E6..U&#43;09EF, \
  U&#43;0A05..U&#43;0A39, U&#43;0A59..U&#43;0A5E,U&#43;0A66..U&#43;0A6F, U&#43;0A85..U&#43;0AB9, U&#43;0AE0..U&#43;0AE3, \
  U&#43;0AE6..U&#43;0AEF, U&#43;0B05..U&#43;0B39,U&#43;0B5C..U&#43;0B61, U&#43;0B66..U&#43;0B6F, U&#43;0B71, U&#43;0B85..U&#43;0BB9, \
  U&#43;0BE6..U&#43;0BF2, U&#43;0C05..U&#43;0C39,U&#43;0C66..U&#43;0C6F, U&#43;0C85..U&#43;0CB9, U&#43;0CDE..U&#43;0CE3, \
  U&#43;0CE6..U&#43;0CEF, U&#43;0D05..U&#43;0D39, U&#43;0D60,U&#43;0D61, U&#43;0D66..U&#43;0D6F, U&#43;0D85..U&#43;0DC6, \
  U&#43;1900..U&#43;1938, U&#43;1946..U&#43;194F, U&#43;A800..U&#43;A805,U&#43;A807..U&#43;A822, U&#43;0386->U&#43;03B1, \
  U&#43;03AC->U&#43;03B1, U&#43;0388->U&#43;03B5, U&#43;03AD->U&#43;03B5,U&#43;0389->U&#43;03B7, U&#43;03AE->U&#43;03B7, \
  U&#43;038A->U&#43;03B9, U&#43;0390->U&#43;03B9, U&#43;03AA->U&#43;03B9,U&#43;03AF->U&#43;03B9, U&#43;03CA->U&#43;03B9, \
  U&#43;038C->U&#43;03BF, U&#43;03CC->U&#43;03BF, U&#43;038E->U&#43;03C5,U&#43;03AB->U&#43;03C5, U&#43;03B0->U&#43;03C5, \
  U&#43;03CB->U&#43;03C5, U&#43;03CD->U&#43;03C5, U&#43;038F->U&#43;03C9,U&#43;03CE->U&#43;03C9, U&#43;03C2->U&#43;03C3, \
  U&#43;0391..U&#43;03A1->U&#43;03B1..U&#43;03C1,U&#43;03A3..U&#43;03A9->U&#43;03C3..U&#43;03C9, U&#43;03B1..U&#43;03C1, \
  U&#43;03C3..U&#43;03C9, U&#43;0E01..U&#43;0E2E,U&#43;0E30..U&#43;0E3A, U&#43;0E40..U&#43;0E45, U&#43;0E47, U&#43;0E50..U&#43;0E59, \
  U&#43;A000..U&#43;A48F, U&#43;4E00..U&#43;9FBF,U&#43;3400..U&#43;4DBF, U&#43;20000..U&#43;2A6DF, U&#43;F900..U&#43;FAFF, \
  U&#43;2F800..U&#43;2FA1F, U&#43;2E80..U&#43;2EFF,U&#43;2F00..U&#43;2FDF, U&#43;3100..U&#43;312F, U&#43;31A0..U&#43;31BF, \
  U&#43;3040..U&#43;309F, U&#43;30A0..U&#43;30FF,U&#43;31F0..U&#43;31FF, U&#43;AC00..U&#43;D7AF, U&#43;1100..U&#43;11FF, \
  U&#43;3130..U&#43;318F, U&#43;A000..U&#43;A48F,U&#43;A490..U&#43;A4CF
  min_prefix_len = 0
  min_infix_len = 0
  ngram_len = 1
  ngram_chars = \
  U&#43;4E00..U&#43;9FBF, U&#43;3400..U&#43;4DBF, U&#43;20000..U&#43;2A6DF, U&#43;F900..U&#43;FAFF, \
  U&#43;2F800..U&#43;2FA1F, U&#43;2E80..U&#43;2EFF, U&#43;2F00..U&#43;2FDF, U&#43;3100..U&#43;312F, U&#43;31A0..U&#43;31BF, \
  U&#43;3040..U&#43;309F, U&#43;30A0..U&#43;30FF, U&#43;31F0..U&#43;31FF, U&#43;AC00..U&#43;D7AF, U&#43;1100..U&#43;11FF, \
  U&#43;3130..U&#43;318F, U&#43;A000..U&#43;A48F, U&#43;A490..U&#43;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.
  [ &quot;$NETWORKING&quot; = &quot;no&quot; ] && exit 0
  
  csft=&quot;/usr/local/webserver/csft/bin/searchd&quot;
  prog=$(basename $csft)
  
  CSFT_CONF_FILE=&quot;/usr/local/webserver/csft/etc/csft.conf&quot;
  
  lockfile=/var/lock/subsys/csft
  
  start() {
  [ -x $csft ] || exit 5
  [ -f $CSFT_CONF_FILE ] || exit 6
  echo -n $&quot;Starting $prog: &quot;
  daemon $csft --config $CSFT_CONF_FILE
  retval=$?
  echo
  [ $retval -eq 0 ] && touch $lockfile
  return $retval
  }
  
  stop() {
  echo -n $&quot;Stopping $prog: &quot;
  killproc $prog -QUIT
  retval=$?
  echo
  [ $retval -eq 0 ] && rm -f $lockfile
  return $retval
  }
  
  restart() {
  stop
  start
  }
  
  reload() {
  configtest || return $?
  echo -n $&quot;Reloading $prog: &quot;
  killproc $csft -HUP
  RETVAL=$?
  echo
  }
  
  force_reload() {
  restart
  }
  
  rh_status() {
  status $prog
  }
  
  rh_status_q() {
  rh_status >/dev/null 2>&1
  }
  
  case &quot;$1&quot; 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 $&quot;Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}&quot;
  exit 2
  esac
  chmod &#43;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 &#43;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 &quot;/usr/lib/oracle/10.2.0.4/client/lib/&quot; > /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=&quot;-I/usr/include/oracle/10.2.0.4/client/&quot;
CXXFLAGS=&quot;-I/usr/include/oracle/10.2.0.4/client/&quot;
  ./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 = &quot;/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/&quot;
  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=&quot;eaccelerator.so&quot;
  eaccelerator.shm_size=&quot;128&quot;
  eaccelerator.cache_dir=&quot;/usr/local/webserver/php/eaccelerator_cache&quot;
  eaccelerator.enable=&quot;1&quot;
  eaccelerator.optimizer=&quot;1&quot;
  eaccelerator.check_mtime=&quot;1&quot;
  eaccelerator.debug=&quot;0&quot;
  eaccelerator.filter=&quot;&quot;
  eaccelerator.shm_max=&quot;0&quot;
  eaccelerator.shm_ttl=&quot;300&quot;
  eaccelerator.shm_prune_period=&quot;120&quot;
  eaccelerator.shm_only=&quot;0&quot;
  eaccelerator.compress=&quot;1&quot;
  eaccelerator.compress_level=&quot;9&quot;
  
  [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 &#43; PHP 用于程序调试,请将以下的<value name=&quot;display_errors&quot;>0</value>改为<value name=&quot;display_errors&quot;>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=&quot;1.0&quot; ?>
  <configuration>
  All relative paths in this config are relative to php's install prefix
  <section name=&quot;global_options&quot;>
  Pid file
  <value name=&quot;pid_file&quot;>/usr/local/webserver/php/logs/php-fpm.pid</value>
  Error log file
  <value name=&quot;error_log&quot;>/usr/local/webserver/php/logs/php-fpm.log</value>
  Log level
  <value name=&quot;log_level&quot;>notice</value>
  When this amount of php processes exited with SIGSEGV or SIGBUS ...
  <value name=&quot;emergency_restart_threshold&quot;>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=&quot;emergency_restart_interval&quot;>1m</value>
  Time limit on waiting child's reaction on signals from master
  <value name=&quot;process_control_timeout&quot;>5s</value>
  Set to 'no' to debug fpm
  <value name=&quot;daemonize&quot;>yes</value>
  </section>
  <workers>
  <section name=&quot;pool&quot;>
  Name of pool. Used in logs and stats.
  <value name=&quot;name&quot;>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=&quot;listen_address&quot;>127.0.0.1:9000</value>
  <value name=&quot;listen_options&quot;>
  Set listen(2) backlog
  <value name=&quot;backlog&quot;>-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=&quot;owner&quot;></value>
  <value name=&quot;group&quot;></value>
  <value name=&quot;mode&quot;>0666</value>
  </value>
  Additional php.ini defines, specific to this pool of workers.
  <value name=&quot;php_defines&quot;>
  <value name=&quot;sendmail_path&quot;>/usr/sbin/sendmail -t -i</value>
  <value name=&quot;display_errors&quot;>1</value>
  </value>
  Unix user of processes
  <value name=&quot;user&quot;>www</value>
  Unix group of processes
  <value name=&quot;group&quot;>www</value>
  Process manager settings
  <value name=&quot;pm&quot;>
  Sets style of controling worker process count.
  Valid values are 'static' and 'apache-like'
  <value name=&quot;style&quot;>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=&quot;max_children&quot;>128</value>
  Settings group for 'apache-like' pm style
  <value name=&quot;apache_like&quot;>
  Sets the number of server processes created on startup.
  Used only when 'apache-like' pm_style is selected
  <value name=&quot;StartServers&quot;>20</value>
  Sets the desired minimum number of idle server processes.
  Used only when 'apache-like' pm_style is selected
  <value name=&quot;MinSpareServers&quot;>5</value>
  Sets the desired maximum number of idle server processes.
  Used only when 'apache-like' pm_style is selected
  <value name=&quot;MaxSpareServers&quot;>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=&quot;request_terminate_timeout&quot;>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=&quot;request_slowlog_timeout&quot;>0s</value>
  The log file for slow requests
  <value name=&quot;slowlog&quot;>logs/slow.log</value>
  Set open file desc rlimit
  <value name=&quot;rlimit_files&quot;>51200</value>
  Set max core size rlimit
  <value name=&quot;rlimit_core&quot;>0</value>
  Chroot to this directory at the start, absolute path
  <value name=&quot;chroot&quot;></value>
  Chdir to this directory at the start, absolute path
  <value name=&quot;chdir&quot;></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=&quot;catch_workers_output&quot;>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=&quot;max_requests&quot;>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&#43;)
  Makes sense only with AF_INET listening socket.
  <value name=&quot;allowed_clients&quot;>127.0.0.1</value>
  Pass environment variables like LD_LIBRARY_PATH
  All $VARIABLEs are taken from current environment
  <value name=&quot;environment&quot;>
  <value name=&quot;HOSTNAME&quot;>$HOSTNAME</value>
  <value name=&quot;PATH&quot;>/usr/local/bin:/usr/bin:/bin</value>
  <value name=&quot;TMP&quot;>/tmp</value>
  <value name=&quot;TMPDIR&quot;>/tmp</value>
  <value name=&quot;TEMP&quot;>/tmp</value>
  <value name=&quot;OSTYPE&quot;>$OSTYPE</value>
  <value name=&quot;MACHTYPE&quot;>$MACHTYPE</value>
  <value name=&quot;MALLOC_CHECK_&quot;>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 &#43;w /var/log/nginx
chown -R www.www /var/log/nginx
  
mkdir -p /usr/local/webserver/www
chmod &#43;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] &quot;$request&quot; ' '$status $body_bytes_sent &quot;$http_referer&quot; ' '&quot;$http_user_agent&quot; $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 &quot;nginx: master process&quot; | grep -v &quot;grep&quot; | 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.
  [ &quot;$NETWORKING&quot; = &quot;no&quot; ] && exit 0
  
  nginx=&quot;/usr/local/webserver/nginx/sbin/nginx&quot;
  prog=$(basename $nginx)
  
  NGINX_CONF_FILE=&quot;/usr/local/webserver/nginx/conf/nginx.conf&quot;
  
  lockfile=/var/lock/subsys/nginx
  
  start() {
  [ -x $nginx ] || exit 5
  [ -f $NGINX_CONF_FILE ] || exit 6
  echo -n $&quot;Starting $prog: &quot;
  daemon $nginx -c $NGINX_CONF_FILE
  retval=$?
  echo
  [ $retval -eq 0 ] && touch $lockfile
  return $retval
  }
  
  stop() {
  echo -n $&quot;Stopping $prog: &quot;
  killproc $prog -QUIT
  retval=$?
  echo
  [ $retval -eq 0 ] && rm -f $lockfile
  return $retval
  }
  
  restart() {
  configtest || return $?
  stop
  start
  }
  
  reload() {
  configtest || return $?
  echo -n $&quot;Reloading $prog: &quot;
  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 &quot;$1&quot; 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 $&quot;Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}&quot;
  exit 2
  esac
  chmod &#43;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=&quot;/usr/local/webserver/nginx/logs/&quot;

mkdir -p ${logs_path}$(date -d &quot;yesterday&quot; &#43;&quot;%Y&quot;)/$(date -d &quot;yesterday&quot; &#43;&quot;%m&quot;)/
mv ${logs_path}access.log ${logs_path}$(date -d &quot;yesterday&quot; &#43;&quot;%Y&quot;)/$(date -d &quot;yesterday&quot; &#43;&quot;%m&quot;)/access_$(date -d &quot;yesterday&quot; &#43;&quot;%Y%m%d&quot;).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&#43;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 &quot;GNOME Desktop Environment&quot;
  若出现错误: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=&quot;zh_CN.GB18030&quot;
  LANGUAGE=&quot;zh_CN.GB18030:zh_CN.GBK:zh_CN.GB2312:zh_CN&quot;
  SUPPORTED=&quot;zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en&quot;
  SYSFONT=&quot;lat0-sun16&quot;
  
  使用光盘作为本地源yum安装vncserver
  yum --disablerepo=\* --enablerepo=c5-media install vnc-server
  配置vncserver
  vi /etc/sysconfig/vncservers 修改以下内容
  VNCSERVERS=&quot;2:root&quot;
  VNCSERVERARGS[2]=&quot;-geometry 800x600&quot;
  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 &quot;$1&quot; in
  start)
  export DISPLAY=:5.0
  $XVFB_PATH :5 -screen scrn 1024x768x24 &
  $SOFFICE_PATH -headless -nologo -display:5 -nofirststartwizard -accept=&quot;socket,host=127.0.0.1,port=8100;urp;StarOffice.ServiceManager&quot; &                    
  echo &quot;Starting OpenOffice headless server&quot;
  ;;
  stop)
  echo &quot;Stopping OpenOffice headless server.&quot;
  pkill soffice &
  pkill Xvfb &
  exit 1
  ;;
  *)
  echo &quot;Usage: $0 {start|stop}&quot;
  exit 1
  ;;
  esac
  exit 0
  chmod &#43;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)&#43;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&#43;php&#43;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=&quot;/usr/local/svn/php/lib/php/extensions/no-debug-non-zts-20060613/&quot;
  [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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-139823-1-1.html 上篇帖子: ubuntu 12.04 LNMP 配置 下篇帖子: 单一Nginx负载均衡+LNMP分布式架构
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表