基於CentOS構建高性能的LAMP平臺

基於CentOS構建高性能的LAMP平臺
大綱:
一、系統安裝
二、編譯安裝基本環境
三、配置虛擬主機及基本性能調優
四、基本安全設置
五、附錄及相關介紹


一、系統安裝
1. 分區
   /boot 100M左右
   SWAP  物理內存的2倍(如果你的物理內存大於4G以上,分配4G即可)
   /            15G
   /usr/local 20G (用於安裝軟件 )
   /data 剩餘所有空間


2. 系統初始化腳本 (根據具體需求關閉不需要的服務 )
#vi init.sh
-------------------cut begin-------------------------------------------
#welcome
cat << EOF
+--------------------------------------------------------------+
|         === Welcome to Centos System init ===                |
+--------------http://www.linuxtone.org------------------------+
+----------------------Author:NetSeek--------------------------+
EOF


#disable ipv6
cat << EOF
+--------------------------------------------------------------+
|         === Welcome to Disable IPV6 ===                      |
+--------------------------------------------------------------+
EOF
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
/sbin/chkconfig --level 35 ip6tables off
echo "ipv6 is disabled!"


#disable selinux
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
echo "selinux is disabled,you must reboot!"


#vim
sed -i "8 s/^/alias vi='vim'/" /root/.bashrc
echo 'syntax on' > /root/.vimrc


#zh_cn
sed -i -e 's/^LANG=.*/LANG="zh_CN.GB18030"/'   /etc/sysconfig/i18n


#tunoff services
#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
|         === Welcome to Tunoff services ===                   |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------
for i in `ls /etc/rc3.d/S*`
do
              CURSRV=`echo $i|cut -c 15-`


echo $CURSRV
case $CURSRV in
          crond | irqbalance | microcode_ctl | network | random | sendmail | ssh d | syslog | local | mysql d )
      echo "Base services, Skip!"
      ;;
      *)
          echo "change $CURSRV to off"
          chkconfig --level 235 $CURSRV off
          service $CURSRV stop
      ;;
esac
done
-------------------cut end-------------------------------------------
#sh init.sh (執行上面保存的腳本,之後重啓)
二、編譯安裝基本環境


1. 安裝準備
   1) 系統約定
    軟件源代碼包存放位置        /usr/local/src
    源碼包編譯安裝位置(prefix)        /usr/local/software_name
    腳本以及維護程序 存放位置        /usr/local/sbin
    MySQL 數據庫 位置        /data/mysql/data(可按情況設置)
    Apache 網站根目錄        /data/www/wwwroot(可按情況設置)
    Apache 虛擬主機日誌 根目錄        /data/www/logs(可按情況設置)
    Apache 運行 賬戶        www:www  (useradd -d /data/www/;chown www.www /data/www/wwwroot)


  2) 系統環境部署及調整
   檢查系統是否正常
   # tail -n100 /var/log/messages        (檢查有無系統級錯誤信息)
   # dmesg (檢查硬件設備是否有錯誤信息)
   # ifconfig(檢查網卡設置是否正確)
   # ping www.linuxtone.org         (檢查網絡 是否正常)


  3) 使用 yum 程序安裝所需開發包(以下爲標準的 RPM 包名稱)
   #rpm --import  http://mirror.centos .org/centos/RPM-GPG-KEY-CentOS-5
   #yum install ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel \
    ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel \
    gettext-devel  pam-devel kernel






  4) 定時校正服務器 時鐘,定時與中國 國家授時中心授時服務器同步
   # crontab -e
   加入一行:
   15 3 * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1


2. 編譯安裝軟件包
   源碼編譯安裝所需包(Source)
   1) GD2
       # cd /usr/local/src
       # tar xvf gd-2.0.35.tar.gz
       # cd gd-2.0.35
       # ./configure --prefix=/usr/local/gd2
       # make
       # make install


       補充:安裝GD庫錯誤解決方法 configure.ac:64: error: possibly undefined macro: AM_ICONV
       [root@xxt401 gd-2.0.35]# make install


        cd . && /bin/sh /tmp/jpeg-6b/gd-2.0.35/config/missing –run aclocal-1.9 -I config
        aclocal:configure.ac:64: warning: macro `AM_ICONV’ not found in library
        cd . && /bin/sh /tmp/jpeg-6b/gd-2.0.35/config/missing –run automake-1.9 –foreign
        cd . && /bin/sh /tmp/jpeg-6b/gd-2.0.35/config/missing –run autoconf
        configure.ac:64: error: possibly undefined macro: AM_ICONV
        If this token and others are legitimate, please use m4_pattern_allow.
        See the Autoconf documentation.
        make: *** [configure] 錯誤 1


        把報錯信息“configure.ac:64: error: possibly undefined macro: AM_ICONV”拿到google裏搜索,得到“But you need to have gettext”沒有gettext這個包。




        到 http://www.gnu.org/software/gettext/ 下載了gettext-0.17.tar.gz
        #wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.1.1.tar.gz
        #cp /usr/lib/libattr.* /lib/ #(這個在轉載的文章裏沒說,是因爲make的時候報錯說沒有libattr.la這個文件,所以要複製過去)
        #tar xzf gettext-0.17.tar.gz
        #cd gettext-0.17
        #./configure
        #make
        #make install


        經過以上操作,回去安裝gd 就沒有問題了


   2) LibXML2
       下載地址:http://ftp.gnome.org/pub/GNOME/sources/libxml2


       # cd /usr/local/src
       # wget http://ftp.acc.umu.se/pub/GNOME/sources/libxml2/2.6/libxml2-2.6.30.tar.gz
       # tar xvf libxml2-2.6.29.tar.bz2
       # cd libxml2-2.6.29
       # ./configure --prefix=/usr/local/libxml2
       # make
       # make install


   3) libxslt
      下載地址:http://ftp.acc.umu.se/pub/GNOME/sources/libxslt/


      # cd /usr/local/src
      # wget http://ftp.acc.umu.se/pub/GNOME/sources/libxslt/1.1/libxslt-1.1.22.tar.gz
      # tar xvf libxslt-1.1.22.tar.gz
      # cd libxslt-1.1.22
      # ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
      # make
      # make install


   4) freetype
      下載地址:http://sourceforge.net/projects/freetype/files/freetype2/2.4.5/


      # cd /usr/local/src
      # wget http://sourceforge.net/projects/freetype/files/freetype2/2.4.5/freetype-2.4.5.tar.gz/download
      # tar xvf freetype-2.4.5
      # cd freetype-2.4.5
      # ./configure --prefix=/usr/local/freetype
      # make
      # make install




   5) LibMcrypt
      下載地址:http://sourceforge.net/projects/mcrypt/files/Libmcrypt/
      # cd /usr/local/src
      # wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
      # tar xvf libmcrypt-2.5.8.tar.bz2
      # cd libmcrypt-2.5.8
      # ./configure --prefix=/usr/local/libmcrypt
      # make
      # make install


      編譯libltdl,如果沒有編譯libltdl,在編輯php時添加的“–with-mcrypt”選項可能會有如下的錯誤:
      cannot find -lltdl
      collect2: ld returned 1 exit status
      make: *** [libphp5.la] Error 1


      libltdl在libmcrypt軟件包中就有,具體過程:


      # cd libltdl
      # ./configure -enable-ltdl-install
      # make
      # make install




    6)Curl
      下載地址:http://curl.haxx.se/download/
      # cd /usr/local/src
      # wget http://curl.haxx.se/download/curl-7.21.7.tar.gz
      # tar xvf curl-7.21.7.tar.gz
      # cd curl-7.21.7
      # ./configure --prefix=/usr/local/curl
      # make
      # make install




   7) Apache日誌截斷程序
     下載地址:http://cronolog.org/download/index.html
     # cd /usr/local/src
     # wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
     # tar xvf cronolog-1.6.2.tar.gz
     # cd cronolog-1.6.2
     # ./configure --prefix=/usr/local/cronolog
     # make
     # make install


3. 升級OpenSSL和OpenSSH
    下載地址:http://www.openssl.org/source/
    # cd /usr/local/src
    # wget http://www.openssl.org/source/openssl-0.9.8r.tar.gz
    # tar xvf openssl-1.0.0d.tar.gz
    # cd openssl-1.0.0d
    # ./config --prefix=/usr/local/openssl
    # make
    # make test
    # make install
    # cd ..
    # tar xvf openssh-5.0p1.tar.gz
    # cd  openssh-5.0p1
    # ./configure  \
        "--prefix=/usr" \
        "--with-pam" \
        "--with-zlib" \
        "--sysconfdir=/etc/ssh" \
        "--with-ssl-dir=/usr/local/openssl" \
        "--with-md5-passwords"
    # make
    # make install


  1) 禁用 SSH V1 協議
  找到#Protocol 2,1改爲:Protocol 2


  2) 禁用服務器端GSSAPI
  找到以下兩行,並將它們註釋:
  GSSAPIAuthentication yes
  GSSAPICleanupCredentials yes


  3) 禁用 DNS 名稱解析
找到:#UseDNS yeas改爲:UseDNS no


  4)禁用客戶端 GSSAPI
  # vi /etc/ssh/ssh_config 找到:GSSAPIAuthentication yes 將這行註釋掉。
  最後,確認修改正確後重新啓動 SSH 服務
  # service sshd restart
  # ssh -v
  確認 OpenSSH 以及 OpenSSL 版本正確。


以上SSH配置可利用以下腳本自動修改:
-------------------cut begin-------------------------------------------
#init_ssh
ssh_cf="/etc/ssh/sshd_config"
sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf
sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf
#client
sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf
echo "ssh is init is ok.............."
-------------------cut end---------------------------------------------
三、編譯安裝A.M.P環境


1.下載軟件編譯安裝
  1)下載軟件
    # cd /usr/local/src
    httpd-2.2.8.tar.gz
    mysql-5.0.51b.tar.gz
    php-5.2.6.tar.bz2
    ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz


  2) 安裝MySQL
    查看分析你的CPU型號:
    http://gentoo-wiki.com/Safe_Cflags 查找您的GCC編譯參數.
    確定系統CPU類型:
    # cat /proc/cpuinfo | grep "model name"
    執行後會看到系統中CPU的具體型號,記下CPU型號。
    Mysql下載地址:http://www.mysql.com/downloads/mysql/


    # wget http://mysql.byungsoo.net/Downloads/MySQL-5.1/mysql-5.1.48.tar.gz
    # tar xvf mysql-5.1.48.tar.gz
    # cd mysql-5.1.48
    # vi mysql.sh
-------------------cut begin-------------------------------------------
CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=core2 -mtune=generic -O2 -pipe"
CXXFLAGS="${CFLAGS}"
./configure \
         "--prefix=/usr/local/mysql" \
         "--localstatedir=/data/mysql/data" \
         "--with-comment=Source" \
         "--with-server-suffix=-LinuxTone" \
         "--with-mysqld-user=mysql" \
         "--without-debug" \
         "--with-big-tables" \
         "--with-charset=utf8" \
         "--with-collation=utf8_chinese_ci" \
         "--with-extra-charsets=all" \
         "--with-pthread" \
         "--enable-static" \
         "--enable-thread-safe-client" \
         "--with-client-ldflags=-all-static" \
         "--with-mysqld-ldflags=-all-static" \
         "--enable-assembler" \
         "--without-isam" \
         "--without-innodb" \
         "--with-plugins=all" \
         "--without-ndb-debug"
make && make install
mkdir -p /data/mysql/data
useradd mysql -d /data/mysql -s /sbin/nologin
/usr/local/mysql/bin/mysql_install_db --user=mysql
cd /usr/local/mysql
chown -R root:mysql .
chown -R mysql /data/mysql/data
cp share/mysql/my-huge.cnf /etc/my.cnf
cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
/etc/rc.d/init.d/mysqld start


cd /usr/local/mysql/bin
for i in *; do ln -s /usr/local/mysql/bin/$i /usr/bin/$i; done


-------------------cut end---------------------------------------------
#sh mysql.sh 即可開始編譯.


   3) 編譯安裝Apache
   下載地址: http://httpd.apache.org/download.cgi
   包路徑: http://apache.etoak.com//httpd/httpd-2.2.19.tar.gz


   # cd /usr/local/src
   # wget http://apache.etoak.com//httpd/httpd-2.2.19.tar.gz
   # tar xvf httpd-2.2.19.tar.gz
   # cd httpd-2.2.19
   ./configure \
       "--prefix=/usr/local/apache2" \
       "--with-included-apr" \
       "--enable-so" \
       "--enable-deflate=shared" \
       "--enable-expires=shared" \
       "--enable-rewrite=shared" \
       "--enable-static-support" \
       "--disable-userdir"
   make
   make install
   echo '/usr/local/apache2/bin/apachectl start' >> /etc/rc.local
4.)編譯安裝PHP
    # cd /usr/local/src
    # tar xjvf php-5.2.6.tar.bz2
    # cd php-5.2.6
         ./configure \
         "--prefix=/usr/local/php" \
         "--with-apxs2=/usr/local/apache2/bin/apxs" \
         "--with-config-file-path=/usr/local/php/etc" \
         "--with-mysql=/usr/local/mysql" \
         "--with-pdo-mysql=/usr/local/mysql" \
         "--with-mysqli=/usr/local/mysql/bin/mysql_config" \
         "--with-libxml-dir=/usr/local/libxml2" \
         "--with-curl" \
         "--with-gd=/usr/local/gd2" \
         "--with-jpeg-dir" \
         "--with-png-dir" \
         "--with-bz2" \
         "--with-freetype-dir" \
         "--with-iconv-dir" \
         "--with-zlib-dir " \
         "--with-openssl=/usr" \
         "--with-mcrypt=/usr/local/libmcrypt" \
         "--enable-soap" \
         "--enable-gd-native-ttf" \
         "--enable-ftp" \
         "--enable-mbstring" \
         "--enable-exif" \
         "--disable-ipv6" \
         "--disable-cgi" \
         "--disable-cli"          #禁掉ipv6,禁掉cli模式,提升速度和安全性.請根據具體需求定製相關的編譯數.
  make
  make install
  mkdir /usr/local/php/etc
  cp php.ini-dist /usr/local/php/etc/php.ini
5)Xcache的安裝.
  #tar xvf xcache-1.2.2.tar.gz
  #/usr/local/php/bin/phpize
   ./configure --enable-xcache --enable-xcache-coverager --with-php-config=/usr/local/php/bin/php-config \
   --enable-inline-optimization --disable-debug
#vi /usr/local/php/etc/php.ini (將以下內容加入php.ini最後面)
-------------------cut begin-------------------------------------------
[xcache-common]
zend_extension      = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so


[xcache.admin]
xcache.admin.user   = "admin"
;如何生成md5密碼: echo -n "password"| md5sum
xcache.admin.pass   = "035d849226a8a10be1a5e0fec1f0f3ce"  #密碼爲52netseek


[xcache]
; Change xcache.size to tune the size of the opcode cache
xcache.size         = 24M
xcache.shm_scheme   = "mmap"
xcache.count        = 4
xcache.slots        = 8K
xcache.ttl          = 0
xcache.gc_interval  = 0


; Change xcache.var_size to adjust the size of variable cache
xcache.var_size     = 8M
xcache.var_count    = 1
xcache.var_slots    = 8K
xcache.var_ttl      = 0
xcache.var_maxttl   = 0
xcache.var_gc_interval =     300
xcache.test         = Off
xcache.readonly_protection = On
xcache.mmap_path    = "/tmp/xcache"
xcache.coredump_directory =   ""
xcache.cacher       = On
xcache.stat         = On
xcache.optimizer    = Off


[xcache.coverager]
xcache.coverager    = On
xcache.coveragedump_directory = ""
-------------------cut end---------------------------------------------
6) 安裝Zend Optimizer
    # cd /usr/local/src
    # tar xzf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
    # cd ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/
    根據PHP的版本選擇,如我的版本是5.2.17,所以選擇5_2_x_comp/目錄下的ZendOptimizer.so
    # cp 5_2_x_comp/ZendOptimizer.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
    # vim /usr/local/php/etc/php.ini
    在文件末尾添加:
    [Zend]
    zend_optimizer.optimization_level=1023
    zend_optimizer.encoder_loader=1
    zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ZendOptimizer.so"
    找到extension_dir='./'
    修改爲:extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"


    安裝Zend Optimizer過程的最後不要選擇重啓Apache。
7) 安裝Memcached及Memcache
    Linux下Memcache服務器端的安裝
    服務器端主要是安裝memcache服務器端,目前的最新版本是 memcached-v1.4.6。
    下載:http://memcached.org/
    另外,Memcache用到了libevent這個庫用於Socket的處理,所以還需要安裝libevent,libevent的最新版本是libevent-1.3。(如果你的系統已經安裝了libevent,可以不用安裝)
    官網:http://www.monkey.org/~provos/libevent/
    下載:http://www.monkey.org/~provos/libevent-1.3.tar.gz
    a.先安裝libevent。這個東西在配置時需要指定一個安裝路徑,即
    # tar zxvf libevent-1.2.tar.gz
    # cd libevent-1.2
    # ./configure --prefix=/usr/local/libevent
    # make
    # make install


    測試:
    # ls -al /usr/lib | grep libevent
    lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent-1.2.so.1 -> libevent-1.2.so.1.0.3
    -rwxr-xr-x 1 root root 263546 11?? 12 17:38 libevent-1.2.so.1.0.3
    -rw-r–r– 1 root root 454156 11?? 12 17:38 libevent.a
    -rwxr-xr-x 1 root root 811 11?? 12 17:38 libevent.la
    lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent.so -> libevent-1.2.so.1.0.3
    還不錯,都安裝上了。


    b.再安裝memcached,只是需要在配置時需要指定libevent的安裝路徑即
    # cd /tmp
    # tar zxvf memcached-1.2.0.tar.gz
    # cd memcached-1.2.0
    # ./configure --with-libevent=/usr/local/libevent
    # make
    # make install


    啓動Memcache的服務器端:
    # /usr/local/bin/memcached -d -m 500 -u root -l 127.0.0.1 -p 12000 -c 256 -P /tmp/memcached.pid


    -d選項是啓動一個守護進程,
    -m是分配給Memcache使用的內存數量,單位是MB,我這裏是10MB,
    -u是運行Memcache的用戶,我這裏是root,
    -l是監聽的服務器IP地址,如果有多個地址的話,我這裏指定了服務器的IP地址192.168.0.200,
    -p是設置Memcache監聽的端口,我這裏設置了12000,最好是1024以上的端口,
    -c選項是最大運行的併發連接數,默認是1024,我這裏設置了256,按照你服務器的負載量來設定,
    -P是設置保存Memcache的pid文件,我這裏是保存在 /tmp/memcached.pid,


    c.安裝memcache
    tar vxzf memcache-2.2.1.tgz
    cd memcache-2.2.1
    /usr/local/php/bin/phpize
    ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
    make
    make install


    上述安裝完後會有類似這樣的提示:


   Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/
   把php.ini中的extension_dir ="./"修改爲
   extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/"
   添加一行來載入memcache擴展:extension=memcache.so


   如果要結束Memcache進程,執行:
   # kill 'cat /tmp/memcached.pid'
   也可以啓動多個守護進程,不過端口不能重複




2. 整合Apache與PHP及系統初化配置.
   1)整合Apache與PHP
    # vi /usr/local/apache2/conf/httpd.conf
    找到:
    AddType application/x-gzip .gz .tgz
    在該行下面添加
    AddType application/x-httpd-php .php


   找到:
   <IfModule dir_module>
       DirectoryIndex index.html
   </IfModule>
   將該行改爲
   <IfModule dir_module>
        DirectoryIndex index.html index.htm index.php
   </IfModule>


找到:
#Include conf/extra/httpd-mpm.conf
#Include conf/extra/httpd-info.conf
#Include conf/extra/httpd-vhosts.conf  (虛擬主機配置文件存放目錄.)
#Include conf/extra/httpd-default.conf
去掉前面的"#"號,取消註釋。
注意:以上 4 個擴展配置文件中的設置請按照相關原則進行合理配置!


修改完成後保存退出。
# /usr/local/apache2/bin/apachectl restart


  2)查看確認L.A.M.P環境信息、提升 PHP 安全性
   在網站根目錄放置 info.php 腳本,檢查phpinfo中的各項信息是否正確。
   <?php
   phpinfo();
   ?>


   確認 PHP 能夠正常工作後,在 php.ini 中進行設置提升 PHP 安全性,禁掉危險的函數.
   # vi /etc/php.ini找到:disable_functions =設置爲:phpinfo,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server


3)腳本自動完成初始化配置(以上配置可以用腳本自動化完成)
#cat init_apache_php.sh
-------------------cut begin-------------------------------------------
#!/bin/bash
#Written by :NetSeek http://www.linuxtone.org
#init_httpd.conf
http_cf="/usr/local/apache2/conf/httpd.conf"
sed -i -e "s/User daemon/User www/" -i -e "s/Group daemon/Group www/" $http_cf
sed -i -e '121 s/^/#/' -i -e '122 s/^/#/' $http_cf
sed -i 's#DirectoryIndex index.html# DirectoryIndex index.php index.html index.htm#/g'  $http_cf
sed -i -e '374 s/^#//g' -i -e '389 s/^#//g' -i -e '392 s/^#//g' -i -e '401 s/^#//g' $http_cf
#init_php(PHP安全設置及隱藏PHP版本)
php_cf="/usr/local/lib/php.ini"
sed -i '205 s#;open_basedir =#open_basedir = /data/www/wwwroot:/tmp#g' $php_cf
sed -i '210 s#disable_functions =#disable_functions = phpinfo,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server#g' $php_cf
sed -i '/expose_php/s/On/Off/' $php_cf
sed -i '/display_errors/s/On/Off/' $php_cf
-------------------cut end-------------------------------------------


三、配置虛擬主機及基本性能調優
1) 配置虛擬主機:
#vi /usr/local/apache2/conf/extra/httpd-vhosts.conf
NameVirtualHost *:80


<VirtualHost *:80>
     ServerAdmin [email protected]
     DocumentRoot "/data/www/wwwroot/linuxtone.org"
     ServerName www.linuxtone.org
     ServerAlias bbs.linxutone.org
     ErrorLog "logs/dummy-host.example.com-error_log"
     CustomLog "|/usr/sbin/cronolog /data/logs/access_www.linuxtone.org.%Y%m%d" combined
</VirtualHost>
2).基本性能調優參考:(更多的調優相關文章請關注:http://bbs.linuxtone.org/index.html 性能調優相關的貼子)
#vi /usr/local/apache2/conf/extra/httpd-default.conf
Timeout 15
KeepAlive Off
MaxKeepAliveRequests 50
KeepAliveTimeout 5
UseCanonicalName Off
AccessFileName .htaccess
ServerTokens Prod
ServerSignature Off
HostnameLookups Off
#vi /usr/local/apache2/conf/extra/httpd-mpm.conf
<IfModule mpm_prefork_module>
     ServerLimit         2000
     StartServers          10
     MinSpareServers       10
     MaxSpareServers      15
     MaxClients          2000
     MaxRequestsPerChild   10000
</IfModule>
3).Apache日誌處理相關問題彙總貼(http://bbs.linuxtone.org/thread-102-1-1.html )
   利用awstats分析網站日誌:http://bbs.linuxtone.org/thread-56-1-1.html


   忽略不需要的日誌配置參考具體請據據具體問題分析:
   LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
   #下面加入如下內容:
    # filter the localhost visit
     SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog
     # filter some special directories
     SetEnvIf Request_URI "^ZendPlatform.*[code]
     # filter the localhost visit
     SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog
     # filter some special directories
     SetEnvIf Request_URI "^ZendPlatform.*[        DISCUZ_CODE_9        ]quot; dontlog
     SetEnvIf Request_URI \.healthcheck\.html$ dontlog
     SetEnvIf Remote_Addr "::1" dontlog
     SetEnvIf Request_URI "\.getPing.php[        DISCUZ_CODE_9        ]quot; dontlog
     SetEnvIf Request_URI "^/error\.html[        DISCUZ_CODE_9        ]quot; dontlog
     SetEnvIf Request_URI "\.gif[        DISCUZ_CODE_9        ]quot; dontlog
     SetEnvIf Request_URI "\.jpg[        DISCUZ_CODE_9        ]quot; dontlog
     SetEnvIf Request_URI "\.css[        DISCUZ_CODE_9        ]quot; dontlog
quot; dontlog
    SetEnvIf Request_URI \.healthcheck\.html$ dontlog
    SetEnvIf Remote_Addr "::1" dontlog
    SetEnvIf Request_URI "\.getPing.php[        DISCUZ_CODE_9        ]quot; dontlog
    SetEnvIf Request_URI "^/error\.html[        DISCUZ_CODE_9        ]quot; dontlog
    SetEnvIf Request_URI "\.gif[        DISCUZ_CODE_9        ]quot; dontlog
    SetEnvIf Request_URI "\.jpg[        DISCUZ_CODE_9        ]quot; dontlog
    SetEnvIf Request_URI "\.css[        DISCUZ_CODE_9        ]quot; dontlog
[/code]4). Apache防盜鏈(Apache防盜鏈相關問題彙總:http://bbs.linuxtone.org/thread-101-1-1.html )
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
    RewriteRule \.(gif|jpg)$ http://網站域名/nolink.png [R,L]
四、基本安全設置
  1)iptables 封鎖相關端口(推薦讀CU白金大哥的兩小時玩轉iptables)
  2)SSH全安(修改SSH端口限制來源IP登陸,或者參考http://bbs.linuxtone.org/thread-106-1-1.html )
  3)Linux防Arp攻擊策略(http://bbs.linuxtone.org/thread-41-1-1.html )
  4)注意(還是那句老話:安全工作從細節做起!)


五、附錄及相關介紹
  1)參考文檔(感謝):
    Discuz!公司Nanu先生文章的相關鏈接:
    http://bbs.linuxpk.com/thread-13325-1-2.html
    http://www.discuz.net/thread-722804-1-1.html
    配置全能WEB(05年文章參考):http://bbs.linuxpk.com/thread-437-1-2.html
    LinuxTone.Org(Apache相關問題專題貼):http://bbs.linuxtone.org/thread-88-1-1.html
    感謝網友eddiechen提出相關問題!




在原有的基礎上有所修正。


發佈了44 篇原創文章 · 獲贊 3 · 訪問量 26萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章