SlideShare a Scribd company logo
1 of 14
项目部 Linux 服务器部署标准
Comsenz Project Department Linux
   Server Deployment Standard
             版本: 5.1.2
            Version: 5.1.2


 适用操作系统: CentOS 5.2-x86_64


    发布日期: 2009 年 07 月 1 日
 Distribution Date: September 1, 2009
            By Comsenz Victor
一、系统约定
软件源代码包存放位置                         /usr/local/src
源码包编译安装位置(prefix)                  /
                                   usr/local/software_name ( software_na
                                   me 为软件名)
脚本以及维护程序存放位置                       /usr/local/sbin
MySQL 数据库位置                        /data/mysql(默认为/var/lib/mysql,可
                                   按情况设置,此处/data 分区为最大的
                                   分区)
Apache 网站根目录                       /data/www/wwwroot ( 可 按 情 况 设 置 ,
                                   此处/data 分区为最大的分区)
Apache 虚拟主机日志根目录                   /data/www/logs(可按情况设置,此处
                                   /data 分区为最大的分区)
Apache 运行账户                        www:www



二、系统环境部署及调整
1. 检查系统是否正常

     # more /var/log/messages   (检查有无系统级错误信息)

     # dmesg (检查硬件设备是否有错误信息)

     # ifconfig(检查网卡设置是否正确)

     # ping www.163.com    (检查网络是否正常)
al
2. 关闭不需要的服务
     # ntsysv
     以下仅列出需要启动的服务,未列出的服务一律推荐关闭:
       atd
       crond
     irqbalance
     microcode_ctl
     network
     portmap
     sendmail
     sshd
     syslog


3. 重新启动系统
# init 6


4. 配置 vim
 # vi /root/.bashrc

 在 alias mv='mv -i' 下面添加一行:alias vi='vim' 保存退出。
 # echo 'syntax on' > /root/.vimrc
 # source /root/.bashrc


5. 使用 yum 对系统进行更新并且安装必要软件包
    yum update –y

   安装 ntpd 以校正时间
  yum install ntp –y
注:如果安装的不是最新的操作系统版本,在连接公网的条件下,建议使用
yum 对系统更新。
    yum -y install libpng libpng-devel libjpeg libjpeg-devel gd gd-devel libxml2
libxml2-devel libmcrypt libmcrypt-devel compat-* pam-devel*


6. 定时校正服务器时钟,定时与中国国家授时中心授时服务器同步
 # crontab -e
   加入一行:
   1 */6 * * * ntpdate 210.72.145.44 > /dev/null 2>&1
注:以上为公网条件下;若在内网则需要自己搭建时间同步服务器。


7. 源码编译安装所需包 (Source)
 (1) GD2
        cd /usr/local/src
        tar xzvf gd-2.0.34.tar.gz
        cd gd-2.0.34
        ./configure --prefix=/usr/local/gd2
        make && make install

 (2) LibXML2
         cd /usr/local/src
         tar zxvf libxml2-2.6.32.tar.gz
         cd libxml2-2.6.32
         ./configure --prefix=/usr/local/libxml2
         make && make install
(3) LibMcrypt
        cd /usr/local/src
        tar xjvf libmcrypt-2.5.8.tar.bz2
        cd libmcrypt-2.5.8
        ./configure --prefix=/usr/local/libmcrypt
        make && make install


 (4) Apache 日志截断程序
       cd /usr/local/src
       tar xzvf cronolog-1.7.0-beta.tar.gz
       cd cronolog-1.7.0-beta
       ./configure --prefix=/usr/local/cronolog
       make && make install


8. 升级 OpenSSL 和 OpenSSH
        cd /usr/local/src
        tar zxvf openssl-0.9.8h.tar.gz
        cd openssl-0.9.8h
        ./config --prefix=/usr/local/openssl
        make && make install
        cd ..

        tar zxvf openssh-5.1p1.tar.gz
        cd openssh-5.1p1
        ./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 协议

    vi /etc/ssh/sshd_config:
    Protocol 2,1
    改为:
    Protocol 2


    ( 2)禁用服务器端 GSSAPI
    找到以下两行,并将它们注释:
    GSSAPIAuthentication yes
    GSSAPICleanupCredentials yes
( 3)禁用 DNS 域名反解
   找到:
   #UseDNS yes
   改为:
   UseDNS no


   ( 4)禁用客户端 GSSAPI
   vi /etc/ssh/ssh_config
   找到:
   GSSAPIAuthentication yes
   将这行注释掉。


   最后,确认修改正确后重新启动 SSH 服务
   service sshd restart
   ssh -v

   确认 OpenSSH 以及 OpenSSL 版本正确。




三、编译安装 L.A.M.P 环境

1. 下载软件
   cd /usr/local/src
   httpd-2.2.11.tar.gz
   mysql-5.1.34-linux-x86_64-icc-glibc23.tar.gz
   php-5.2.8.tar.bz2
   eaccelerator-0.9.5.3.tar.bz2
   memcache-2.2.3.tgz
   ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz



2. 安装 MySQL
   tar xzvf mysql-5.1.34-rc-linux-x86_64-icc-glibc23.tar.gz
   mv mysql-5.1.34-rc-linux-x86_64-icc-glibc23 /usr/local/
   ln –s /usr/local/mysql-5.1.34-rc-linux-x86_64-icc-glibc23 /usr/local/mysql
   useradd mysql -s /sbin/nologin
   chown -R mysql:root /usr/local/mysql/
   cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chown root:root /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 3 mysqld on
cp ./support-files/my-huge.cnf /etc/my.cnf
mv /usr/local/mysql/data /data/mysql
chown -R mysql:mysql /data/mysql/
vi /etc/my.cnf 修改以下内容:


           在            [mysqld]          段       增     加   或   修       改   :
           datadir                            =                     /data/mysql
           skip-innodb
           wait-timeout                               =                     5
           max_connections                              =                 512
           max_connect_errors                         =              10000000
           thread_concurrency         =           CPU       个       数       ×2

           将 log-bin 注释(如果需要使用 mysql 的主从备份功能,需要 log-

           bin 参数打开,不能注释)
bin/mysqladmin -u root password 'password_for_root'
(注:password_for_root 为 mysql 的 root 帐户的密码,用户自行设定)


针对大型用户 mysql 优化的参数设置 (供参考 ):


[mysqld]
port        = 3306
socket      = /tmp/mysql.sock

datadir = /data/mysql
skip-locking
skip-name-resolve
skip-innodb
skip-symbolic-links
local-infile=0

low_priority_updates=1
back_log = 300
   key_buffer = 256M
   max_allowed_packet = 16M
   thread_stack = 128K
   table_cache = 1024
   sort_buffer_size = 4M
   read_buffer_size = 256K
   join_buffer_size = 4M
   record_buffer = 2M
   read_rnd_buffer_size = 4M
   myisam_sort_buffer_size = 64M
   thread_cache_size = 64
   query_cache_size = 32M
   tmp_table_size = 196M
   max_connections = 1600
   max_connect_errors = 10000000000000
   wait_timeout = 5
   thread_concurrency=16

   long_query_time = 1
   log-slow-queries = /data/mysql/slow.log


3. 编译安装 Apache
  cd /usr/local/src
  tar xjvf httpd-2.2.11.tar.bz2
  cd httpd-2.2.11
  ./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

 在编译安装 PHP 之前,我们首先关闭 selinux,以免编译时出现错误。
   vi /etc/selinux/config

   找到:SELINUX=enforcing

   改为:SELINUX=disabled


  echo '0' > /selinux/enforce
开始安装编译 PHP:


   cd /usr/local/src
   tar xjvf php-5.2.8.tar.bz2
   cd php-5.2.8
   ./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-
   mysql-sock=/tmp --with-libxml-dir=/usr/local/libxml2 --with-gd --with-jpeg-dir --
   with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-curl --with-
   mcrypt=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-ftp
   --enable-mbstring       --enable-sockets   --enable-exif    --enable-zend-multibyte
   --disable-ipv6 --disable-cgi
   make && make install
   cp php.ini-dist /usr/local/php/etc/php.ini



5. 安装 Eaccelerator


   cd /usr/local/src
   tar jxvf eaccelerator-0.9.5.3.tar.bz2
   cd eaccelerator-0.9.5.3
   /usr/local/php/bin/phpize
   ./configure                 --enable-eaccelerator=shared           --with-php-
   config=/usr/local/php/bin/php-config --with-eaccelerator-shared-memory --with-
   eaccelerator-sessions --with-eaccelerator-content-caching
   make && make install
   mkdir /usr/local/php/ext
   cp modules/eaccelerator.so /usr/local/php/ext/


    安装为 Zend 扩展
   vi /usr/local/php/etc/php.ini
   插入
   zend_extension="/usr/local/php/ext/eaccelerator.so"
   eaccelerator.shm_size="16"
   eaccelerator.cache_dir="/tmp/eaccelerator"
   eaccelerator.enable="1"
   eaccelerator.optimizer="1"
   eaccelerator.check_mtime="1"
   eaccelerator.debug="0"
   eaccelerator.filter=""
eaccelerator.shm_max="0"
   eaccelerator.shm_ttl="0"
   eaccelerator.shm_prune_period="0"
   eaccelerator.shm_only="0"
   eaccelerator.compress="1"
   eaccelerator.compress_level="9"

   mkdir /tmp/eaccelerator
   chmod 0777 /tmp/eaccelerator


6. 安装 memcache 扩展


   cd /usr/local/src/
   tar zxvf memcache-2.2.3.tgz
   cd memcache-2.2.3
   /usr/local/php/bin/phpize
   ./configure --with-php-config=/usr/local/php/bin/php-config
   make && make install
   cp modules/memcache.so /usr/local/php/ext/


7. 安装 Zend Optimizer
   cd /usr/local/src
   tar xzvf ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz
   ./ ZendOptimizer-3.3.3-linux-glibc23-x86_64/install.sh

   安装过程中需要指定 php.ini 的路径即/usr/local/php/etc

   最后暂时先不要选择重启 Apache。


8. 整合 Apache 与 PHP
   修改 PHP 配置文件:
    vi /usr/local/php/etc/php.ini
   找到:
   extension_dir = "./"
   改为:
   extension_dir = "/usr/local/php/ext"

   找到:
   ;extension=php_zip.dll
   在该行下添加
   extension=memcache.so
修改完成后保存退出。

  修改 Apache 配置文件:
  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>

  找到:
  User daemon
  Group daemon
改为:
User www
  Group www

  找到:
  <Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
  </Directory>


将其中的 Deny from all 改为 Allow from all


  找到:
  #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 个扩展配置文件中的设置请按照相关原则进行合理配置!


   修改完成后保存退出。


   添加 www 用户,用来运行 Apache
    useradd www


   重启 Apache
    /usr/local/apache2/bin/apachectl restart


   根据虚拟主机中网站路径的设置(例如 /data/www/wwwroot),测试是否配
置成功
  cd /data/www/wwwroot
  vi phpinfo.php

   <?php
     phpinfo ( );
   ?>
   退出并保存。


   访问 http://IP 地址/phpinfo.php,检查 phpinfo 中的各项信息是否正确。
  注:有时无法访问是因为系统开启了防火墙,建议关闭,设置自己的防火
墙策略(例如“三 服务器安全设置”中的设置),或者使用硬件防火墙。




9. 提升 PHP 安全性

 在 php.ini 中进行设置提升 PHP 安全性。

 vi /etc/php.ini、


 找到并修改以下几处设置为:
upload_tmp_dir = /tmp

 expose_php = Off

 display_errors = Off

    disable_functions                                                                  =
phpinfo,putenv,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_ope
n,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,s
ymlink,popepassthru,stream_socket_server


10. 提升 Apache 安全性及优化


  进入 Apache 配置文件目录/usr/local/apache2/conf/extra
   cd /usr/local/apache2/conf/extra

             编       译            部        分       配        置        文       件        :
   vi httpd-mpm.conf

  找到并更更改以下内容:

  <IfModule mpm_prefork_module>
  ServerLimit 1024
  StartServers    5
  MinSpareServers     5
  MaxSpareServers    10
  MaxClients      640
  MaxRequestsPerChild 0
    </IfModule>


  注:添加 ServerLimit 这行参数,根据网站的访问量相应的调整 ServerLimit

和 MaxClients 两项参数,MaxClients 值不能大于 ServerLimit 的值。


   vi httpd-default.conf

  KeepAlive Off
  注:此处默认为 Off,用户可根据前端负载均衡器的配置中是否保持会话连接
来选择开启或关闭,建议一般用户设置为 Off


  修改以下参数为:

  ServerTokens Prod

     ServerSignature off


     修改以上 PHP 与 Apache 相关设置后需要重启 Apache 服务器。


三、服务器安全性设置
1. 设置系统防火墙
     vi /usr/local/sbin/fw.sh

    将以下脚本命令粘贴到 fw.sh 文件中。
#!/bin/bash

# Stop iptables service first
service iptables stop

# Load FTP Kernel modules
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp

# Inital chains default policy
/sbin/iptables -F -t filter
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT ACCEPT

# Enable Native Network Transfer
/sbin/iptables -A INPUT -i lo -j ACCEPT

# Accept Established Connections
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# ICMP Control
/sbin/iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT

# WWW Service
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# FTP Service
/sbin/iptables -A INPUT -p tcp --dport 21 -j ACCEPT

# SSH Service
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT

    chmod 755 /usr/local/sbin/fw.sh
    echo '/usr/local/sbin/fw.sh' >> /etc/rc.local
    /usr/local/sbin/fw.sh

More Related Content

What's hot

Hadoop平台搭建
Hadoop平台搭建Hadoop平台搭建
Hadoop平台搭建Liyang Tang
 
Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Yiwei Ma
 
Lamp安全全攻略
Lamp安全全攻略Lamp安全全攻略
Lamp安全全攻略Da Zhao
 
Centos下安装apache + subversion
Centos下安装apache + subversionCentos下安装apache + subversion
Centos下安装apache + subversionYiwei Ma
 
Sery lvs+keepalived
Sery lvs+keepalivedSery lvs+keepalived
Sery lvs+keepalivedcolderboy17
 
Unixtoolbox zh cn
Unixtoolbox zh cnUnixtoolbox zh cn
Unixtoolbox zh cnxdboy2006
 
南投替代役整理組數位典藏報告
南投替代役整理組數位典藏報告南投替代役整理組數位典藏報告
南投替代役整理組數位典藏報告Bo-Yi Wu
 
九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)heima911
 
Mysql proxy cluster
Mysql proxy clusterMysql proxy cluster
Mysql proxy clusterYiwei Ma
 
Introduction to FreeBSD commands
Introduction to FreeBSD commandsIntroduction to FreeBSD commands
Introduction to FreeBSD commands郁凱 黃
 
Installation and configuration 11g r2 asm using job role separation(grid & or...
Installation and configuration 11g r2 asm using job role separation(grid & or...Installation and configuration 11g r2 asm using job role separation(grid & or...
Installation and configuration 11g r2 asm using job role separation(grid & or...Zhaoyang Wang
 
Linux network monitoring hands-on pratice
Linux network monitoring hands-on praticeLinux network monitoring hands-on pratice
Linux network monitoring hands-on praticeKenny (netman)
 
Mysql展示功能与源码对应
Mysql展示功能与源码对应Mysql展示功能与源码对应
Mysql展示功能与源码对应zhaolinjnu
 
CentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 ZendCentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 Zendwensheng wei
 
Apache+php+mysql在Linux下的安装与配置
Apache+php+mysql在Linux下的安装与配置Apache+php+mysql在Linux下的安装与配置
Apache+php+mysql在Linux下的安装与配置wensheng wei
 

What's hot (18)

Hadoop平台搭建
Hadoop平台搭建Hadoop平台搭建
Hadoop平台搭建
 
Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)
 
Lamp安全全攻略
Lamp安全全攻略Lamp安全全攻略
Lamp安全全攻略
 
Centos下安装apache + subversion
Centos下安装apache + subversionCentos下安装apache + subversion
Centos下安装apache + subversion
 
Sery lvs+keepalived
Sery lvs+keepalivedSery lvs+keepalived
Sery lvs+keepalived
 
Linuxguide4f2e
Linuxguide4f2eLinuxguide4f2e
Linuxguide4f2e
 
Unixtoolbox zh cn
Unixtoolbox zh cnUnixtoolbox zh cn
Unixtoolbox zh cn
 
南投替代役整理組數位典藏報告
南投替代役整理組數位典藏報告南投替代役整理組數位典藏報告
南投替代役整理組數位典藏報告
 
九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)
 
Mysql proxy cluster
Mysql proxy clusterMysql proxy cluster
Mysql proxy cluster
 
Introduction to FreeBSD commands
Introduction to FreeBSD commandsIntroduction to FreeBSD commands
Introduction to FreeBSD commands
 
unixtoolbox_zh_CN
unixtoolbox_zh_CNunixtoolbox_zh_CN
unixtoolbox_zh_CN
 
Installation and configuration 11g r2 asm using job role separation(grid & or...
Installation and configuration 11g r2 asm using job role separation(grid & or...Installation and configuration 11g r2 asm using job role separation(grid & or...
Installation and configuration 11g r2 asm using job role separation(grid & or...
 
Linux network monitoring hands-on pratice
Linux network monitoring hands-on praticeLinux network monitoring hands-on pratice
Linux network monitoring hands-on pratice
 
Mysql展示功能与源码对应
Mysql展示功能与源码对应Mysql展示功能与源码对应
Mysql展示功能与源码对应
 
CentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 ZendCentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 Zend
 
Apache+php+mysql在Linux下的安装与配置
Apache+php+mysql在Linux下的安装与配置Apache+php+mysql在Linux下的安装与配置
Apache+php+mysql在Linux下的安装与配置
 
MySQL aio
MySQL aioMySQL aio
MySQL aio
 

Viewers also liked

How to write a post in more than one language on your Facebook page (Infograp...
How to write a post in more than one language on your Facebook page (Infograp...How to write a post in more than one language on your Facebook page (Infograp...
How to write a post in more than one language on your Facebook page (Infograp...Stéphane Baudin
 
Research Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and ScienceResearch Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and Scienceinventy
 
Growth and Magnetic properties of MnGeP2 thin films
Growth and Magnetic properties of MnGeP2 thin filmsGrowth and Magnetic properties of MnGeP2 thin films
Growth and Magnetic properties of MnGeP2 thin filmsinventy
 
Business cases are not a dark art: the science behind the numbers
Business cases are not a dark art: the science behind the numbersBusiness cases are not a dark art: the science behind the numbers
Business cases are not a dark art: the science behind the numberssharedserviceslink.com
 
The five core processes: Service transition
The five core processes: Service transitionThe five core processes: Service transition
The five core processes: Service transitionRhy Carloy Basalo
 
Presentación de proyectos
Presentación de proyectos Presentación de proyectos
Presentación de proyectos Lorena Jimenez
 
CNIT 121: 17 Remediation Introduction (Part 1)
CNIT 121: 17 Remediation Introduction (Part 1)CNIT 121: 17 Remediation Introduction (Part 1)
CNIT 121: 17 Remediation Introduction (Part 1)Sam Bowne
 
Practical Malware Analysis Ch12
Practical Malware Analysis Ch12Practical Malware Analysis Ch12
Practical Malware Analysis Ch12Sam Bowne
 
Puberty, Sexuality, and Relationships: The Road to Adulthood for Adolescents...
Puberty, Sexuality, and Relationships:  The Road to Adulthood for Adolescents...Puberty, Sexuality, and Relationships:  The Road to Adulthood for Adolescents...
Puberty, Sexuality, and Relationships: The Road to Adulthood for Adolescents...Accelify
 

Viewers also liked (15)

Resumen
Resumen Resumen
Resumen
 
Biotechnology In Malaysia
Biotechnology In MalaysiaBiotechnology In Malaysia
Biotechnology In Malaysia
 
How to write a post in more than one language on your Facebook page (Infograp...
How to write a post in more than one language on your Facebook page (Infograp...How to write a post in more than one language on your Facebook page (Infograp...
How to write a post in more than one language on your Facebook page (Infograp...
 
Research Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and ScienceResearch Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and Science
 
Growth and Magnetic properties of MnGeP2 thin films
Growth and Magnetic properties of MnGeP2 thin filmsGrowth and Magnetic properties of MnGeP2 thin films
Growth and Magnetic properties of MnGeP2 thin films
 
Test1
Test1Test1
Test1
 
Business cases are not a dark art: the science behind the numbers
Business cases are not a dark art: the science behind the numbersBusiness cases are not a dark art: the science behind the numbers
Business cases are not a dark art: the science behind the numbers
 
The five core processes: Service transition
The five core processes: Service transitionThe five core processes: Service transition
The five core processes: Service transition
 
Presentación de proyectos
Presentación de proyectos Presentación de proyectos
Presentación de proyectos
 
Nanotechnology in the Food Sector_2015
Nanotechnology in the Food Sector_2015Nanotechnology in the Food Sector_2015
Nanotechnology in the Food Sector_2015
 
CNIT 121: 17 Remediation Introduction (Part 1)
CNIT 121: 17 Remediation Introduction (Part 1)CNIT 121: 17 Remediation Introduction (Part 1)
CNIT 121: 17 Remediation Introduction (Part 1)
 
Practical Malware Analysis Ch12
Practical Malware Analysis Ch12Practical Malware Analysis Ch12
Practical Malware Analysis Ch12
 
Factores de produccion
Factores de produccionFactores de produccion
Factores de produccion
 
Zonas economicas en mexico
Zonas economicas en mexicoZonas economicas en mexico
Zonas economicas en mexico
 
Puberty, Sexuality, and Relationships: The Road to Adulthood for Adolescents...
Puberty, Sexuality, and Relationships:  The Road to Adulthood for Adolescents...Puberty, Sexuality, and Relationships:  The Road to Adulthood for Adolescents...
Puberty, Sexuality, and Relationships: The Road to Adulthood for Adolescents...
 

Similar to X64服务器 lamp服务器部署标准 new

8, lamp
8, lamp8, lamp
8, lampted-xu
 
5, system admin
5, system admin5, system admin
5, system adminted-xu
 
linux安装以及LAMP 环境安装详细
linux安装以及LAMP 环境安装详细linux安装以及LAMP 环境安装详细
linux安装以及LAMP 环境安装详细colderboy17
 
Mysql proxy+mysql-mmm
Mysql proxy+mysql-mmmMysql proxy+mysql-mmm
Mysql proxy+mysql-mmmYiwei Ma
 
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)acqua young
 
Install Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 LInstall Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 Lheima911
 
九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)heima911
 
unix toolbox 中文版
unix toolbox 中文版unix toolbox 中文版
unix toolbox 中文版Jie Bao
 
Apache安装配置mod security
Apache安装配置mod securityApache安装配置mod security
Apache安装配置mod securityHuang Toby
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结Yiwei Ma
 
Altibase管理培训 安装篇
Altibase管理培训 安装篇Altibase管理培训 安装篇
Altibase管理培训 安装篇小新 制造
 
Openshift by mtchang
Openshift by mtchangOpenshift by mtchang
Openshift by mtchangChang Mt
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡cachowu
 
Linux基础
Linux基础Linux基础
Linux基础zhuqling
 
尚观Linux研究室 linux驱动程序全解析
尚观Linux研究室   linux驱动程序全解析尚观Linux研究室   linux驱动程序全解析
尚观Linux研究室 linux驱动程序全解析hangejnu
 
Dbabc.net 利用heartbeat + drbd搭建my sql高可用环境
Dbabc.net 利用heartbeat + drbd搭建my sql高可用环境Dbabc.net 利用heartbeat + drbd搭建my sql高可用环境
Dbabc.net 利用heartbeat + drbd搭建my sql高可用环境dbabc
 

Similar to X64服务器 lamp服务器部署标准 new (18)

8, lamp
8, lamp8, lamp
8, lamp
 
5, system admin
5, system admin5, system admin
5, system admin
 
linux安装以及LAMP 环境安装详细
linux安装以及LAMP 环境安装详细linux安装以及LAMP 环境安装详细
linux安装以及LAMP 环境安装详细
 
Mysql proxy+mysql-mmm
Mysql proxy+mysql-mmmMysql proxy+mysql-mmm
Mysql proxy+mysql-mmm
 
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
 
Install Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 LInstall Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 L
 
Asm+aix
Asm+aixAsm+aix
Asm+aix
 
九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)
 
unix toolbox 中文版
unix toolbox 中文版unix toolbox 中文版
unix toolbox 中文版
 
Apache安装配置mod security
Apache安装配置mod securityApache安装配置mod security
Apache安装配置mod security
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结
 
Altibase管理培训 安装篇
Altibase管理培训 安装篇Altibase管理培训 安装篇
Altibase管理培训 安装篇
 
Openshift by mtchang
Openshift by mtchangOpenshift by mtchang
Openshift by mtchang
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡
 
LinuxGuide4F2E
LinuxGuide4F2ELinuxGuide4F2E
LinuxGuide4F2E
 
Linux基础
Linux基础Linux基础
Linux基础
 
尚观Linux研究室 linux驱动程序全解析
尚观Linux研究室   linux驱动程序全解析尚观Linux研究室   linux驱动程序全解析
尚观Linux研究室 linux驱动程序全解析
 
Dbabc.net 利用heartbeat + drbd搭建my sql高可用环境
Dbabc.net 利用heartbeat + drbd搭建my sql高可用环境Dbabc.net 利用heartbeat + drbd搭建my sql高可用环境
Dbabc.net 利用heartbeat + drbd搭建my sql高可用环境
 

More from Yiwei Ma

Cibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconCibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconYiwei Ma
 
Cibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconCibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconYiwei Ma
 
Taobao casestudy-yufeng-qcon
Taobao casestudy-yufeng-qconTaobao casestudy-yufeng-qcon
Taobao casestudy-yufeng-qconYiwei Ma
 
Alibaba server-zhangxuseng-qcon
Alibaba server-zhangxuseng-qconAlibaba server-zhangxuseng-qcon
Alibaba server-zhangxuseng-qconYiwei Ma
 
Zhongxing practice-suchunshan-qcon
Zhongxing practice-suchunshan-qconZhongxing practice-suchunshan-qcon
Zhongxing practice-suchunshan-qconYiwei Ma
 
Taobao practice-liyu-qcon
Taobao practice-liyu-qconTaobao practice-liyu-qcon
Taobao practice-liyu-qconYiwei Ma
 
Thoughtworks practice-hukai-qcon
Thoughtworks practice-hukai-qconThoughtworks practice-hukai-qcon
Thoughtworks practice-hukai-qconYiwei Ma
 
Ufida design-chijianqiang-qcon
Ufida design-chijianqiang-qconUfida design-chijianqiang-qcon
Ufida design-chijianqiang-qconYiwei Ma
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qconYiwei Ma
 
Netflix web-adrian-qcon
Netflix web-adrian-qconNetflix web-adrian-qcon
Netflix web-adrian-qconYiwei Ma
 
Google arch-fangkun-qcon
Google arch-fangkun-qconGoogle arch-fangkun-qcon
Google arch-fangkun-qconYiwei Ma
 
Cibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconCibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconYiwei Ma
 
Alibaba arch-jiangtao-qcon
Alibaba arch-jiangtao-qconAlibaba arch-jiangtao-qcon
Alibaba arch-jiangtao-qconYiwei Ma
 
Twitter keynote-evan-qcon
Twitter keynote-evan-qconTwitter keynote-evan-qcon
Twitter keynote-evan-qconYiwei Ma
 
Netflix keynote-adrian-qcon
Netflix keynote-adrian-qconNetflix keynote-adrian-qcon
Netflix keynote-adrian-qconYiwei Ma
 
Facebook keynote-nicolas-qcon
Facebook keynote-nicolas-qconFacebook keynote-nicolas-qcon
Facebook keynote-nicolas-qconYiwei Ma
 
Domainlang keynote-eric-qcon
Domainlang keynote-eric-qconDomainlang keynote-eric-qcon
Domainlang keynote-eric-qconYiwei Ma
 
Devjam keynote-david-qcon
Devjam keynote-david-qconDevjam keynote-david-qcon
Devjam keynote-david-qconYiwei Ma
 
Baidu keynote-wubo-qcon
Baidu keynote-wubo-qconBaidu keynote-wubo-qcon
Baidu keynote-wubo-qconYiwei Ma
 
淘宝线上线下性能跟踪体系和容量规划-Qcon2011
淘宝线上线下性能跟踪体系和容量规划-Qcon2011淘宝线上线下性能跟踪体系和容量规划-Qcon2011
淘宝线上线下性能跟踪体系和容量规划-Qcon2011Yiwei Ma
 

More from Yiwei Ma (20)

Cibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconCibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qcon
 
Cibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconCibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qcon
 
Taobao casestudy-yufeng-qcon
Taobao casestudy-yufeng-qconTaobao casestudy-yufeng-qcon
Taobao casestudy-yufeng-qcon
 
Alibaba server-zhangxuseng-qcon
Alibaba server-zhangxuseng-qconAlibaba server-zhangxuseng-qcon
Alibaba server-zhangxuseng-qcon
 
Zhongxing practice-suchunshan-qcon
Zhongxing practice-suchunshan-qconZhongxing practice-suchunshan-qcon
Zhongxing practice-suchunshan-qcon
 
Taobao practice-liyu-qcon
Taobao practice-liyu-qconTaobao practice-liyu-qcon
Taobao practice-liyu-qcon
 
Thoughtworks practice-hukai-qcon
Thoughtworks practice-hukai-qconThoughtworks practice-hukai-qcon
Thoughtworks practice-hukai-qcon
 
Ufida design-chijianqiang-qcon
Ufida design-chijianqiang-qconUfida design-chijianqiang-qcon
Ufida design-chijianqiang-qcon
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qcon
 
Netflix web-adrian-qcon
Netflix web-adrian-qconNetflix web-adrian-qcon
Netflix web-adrian-qcon
 
Google arch-fangkun-qcon
Google arch-fangkun-qconGoogle arch-fangkun-qcon
Google arch-fangkun-qcon
 
Cibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qconCibank arch-zhouweiran-qcon
Cibank arch-zhouweiran-qcon
 
Alibaba arch-jiangtao-qcon
Alibaba arch-jiangtao-qconAlibaba arch-jiangtao-qcon
Alibaba arch-jiangtao-qcon
 
Twitter keynote-evan-qcon
Twitter keynote-evan-qconTwitter keynote-evan-qcon
Twitter keynote-evan-qcon
 
Netflix keynote-adrian-qcon
Netflix keynote-adrian-qconNetflix keynote-adrian-qcon
Netflix keynote-adrian-qcon
 
Facebook keynote-nicolas-qcon
Facebook keynote-nicolas-qconFacebook keynote-nicolas-qcon
Facebook keynote-nicolas-qcon
 
Domainlang keynote-eric-qcon
Domainlang keynote-eric-qconDomainlang keynote-eric-qcon
Domainlang keynote-eric-qcon
 
Devjam keynote-david-qcon
Devjam keynote-david-qconDevjam keynote-david-qcon
Devjam keynote-david-qcon
 
Baidu keynote-wubo-qcon
Baidu keynote-wubo-qconBaidu keynote-wubo-qcon
Baidu keynote-wubo-qcon
 
淘宝线上线下性能跟踪体系和容量规划-Qcon2011
淘宝线上线下性能跟踪体系和容量规划-Qcon2011淘宝线上线下性能跟踪体系和容量规划-Qcon2011
淘宝线上线下性能跟踪体系和容量规划-Qcon2011
 

X64服务器 lamp服务器部署标准 new

  • 1. 项目部 Linux 服务器部署标准 Comsenz Project Department Linux Server Deployment Standard 版本: 5.1.2 Version: 5.1.2 适用操作系统: CentOS 5.2-x86_64 发布日期: 2009 年 07 月 1 日 Distribution Date: September 1, 2009 By Comsenz Victor
  • 2. 一、系统约定 软件源代码包存放位置 /usr/local/src 源码包编译安装位置(prefix) / usr/local/software_name ( software_na me 为软件名) 脚本以及维护程序存放位置 /usr/local/sbin MySQL 数据库位置 /data/mysql(默认为/var/lib/mysql,可 按情况设置,此处/data 分区为最大的 分区) Apache 网站根目录 /data/www/wwwroot ( 可 按 情 况 设 置 , 此处/data 分区为最大的分区) Apache 虚拟主机日志根目录 /data/www/logs(可按情况设置,此处 /data 分区为最大的分区) Apache 运行账户 www:www 二、系统环境部署及调整 1. 检查系统是否正常 # more /var/log/messages (检查有无系统级错误信息) # dmesg (检查硬件设备是否有错误信息) # ifconfig(检查网卡设置是否正确) # ping www.163.com (检查网络是否正常) al 2. 关闭不需要的服务 # ntsysv 以下仅列出需要启动的服务,未列出的服务一律推荐关闭: atd crond irqbalance microcode_ctl network portmap sendmail sshd syslog 3. 重新启动系统
  • 3. # init 6 4. 配置 vim # vi /root/.bashrc 在 alias mv='mv -i' 下面添加一行:alias vi='vim' 保存退出。 # echo 'syntax on' > /root/.vimrc # source /root/.bashrc 5. 使用 yum 对系统进行更新并且安装必要软件包 yum update –y 安装 ntpd 以校正时间 yum install ntp –y 注:如果安装的不是最新的操作系统版本,在连接公网的条件下,建议使用 yum 对系统更新。 yum -y install libpng libpng-devel libjpeg libjpeg-devel gd gd-devel libxml2 libxml2-devel libmcrypt libmcrypt-devel compat-* pam-devel* 6. 定时校正服务器时钟,定时与中国国家授时中心授时服务器同步 # crontab -e 加入一行: 1 */6 * * * ntpdate 210.72.145.44 > /dev/null 2>&1 注:以上为公网条件下;若在内网则需要自己搭建时间同步服务器。 7. 源码编译安装所需包 (Source) (1) GD2 cd /usr/local/src tar xzvf gd-2.0.34.tar.gz cd gd-2.0.34 ./configure --prefix=/usr/local/gd2 make && make install (2) LibXML2 cd /usr/local/src tar zxvf libxml2-2.6.32.tar.gz cd libxml2-2.6.32 ./configure --prefix=/usr/local/libxml2 make && make install
  • 4. (3) LibMcrypt cd /usr/local/src tar xjvf libmcrypt-2.5.8.tar.bz2 cd libmcrypt-2.5.8 ./configure --prefix=/usr/local/libmcrypt make && make install (4) Apache 日志截断程序 cd /usr/local/src tar xzvf cronolog-1.7.0-beta.tar.gz cd cronolog-1.7.0-beta ./configure --prefix=/usr/local/cronolog make && make install 8. 升级 OpenSSL 和 OpenSSH cd /usr/local/src tar zxvf openssl-0.9.8h.tar.gz cd openssl-0.9.8h ./config --prefix=/usr/local/openssl make && make install cd .. tar zxvf openssh-5.1p1.tar.gz cd openssh-5.1p1 ./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 协议 vi /etc/ssh/sshd_config: Protocol 2,1 改为: Protocol 2 ( 2)禁用服务器端 GSSAPI 找到以下两行,并将它们注释: GSSAPIAuthentication yes GSSAPICleanupCredentials yes
  • 5. ( 3)禁用 DNS 域名反解 找到: #UseDNS yes 改为: UseDNS no ( 4)禁用客户端 GSSAPI vi /etc/ssh/ssh_config 找到: GSSAPIAuthentication yes 将这行注释掉。 最后,确认修改正确后重新启动 SSH 服务 service sshd restart ssh -v 确认 OpenSSH 以及 OpenSSL 版本正确。 三、编译安装 L.A.M.P 环境 1. 下载软件 cd /usr/local/src httpd-2.2.11.tar.gz mysql-5.1.34-linux-x86_64-icc-glibc23.tar.gz php-5.2.8.tar.bz2 eaccelerator-0.9.5.3.tar.bz2 memcache-2.2.3.tgz ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz 2. 安装 MySQL tar xzvf mysql-5.1.34-rc-linux-x86_64-icc-glibc23.tar.gz mv mysql-5.1.34-rc-linux-x86_64-icc-glibc23 /usr/local/ ln –s /usr/local/mysql-5.1.34-rc-linux-x86_64-icc-glibc23 /usr/local/mysql useradd mysql -s /sbin/nologin chown -R mysql:root /usr/local/mysql/ cd /usr/local/mysql
  • 6. ./scripts/mysql_install_db --user=mysql cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld chown root:root /etc/rc.d/init.d/mysqld chmod 755 /etc/rc.d/init.d/mysqld chkconfig --add mysqld chkconfig --level 3 mysqld on cp ./support-files/my-huge.cnf /etc/my.cnf mv /usr/local/mysql/data /data/mysql chown -R mysql:mysql /data/mysql/ vi /etc/my.cnf 修改以下内容: 在 [mysqld] 段 增 加 或 修 改 : datadir = /data/mysql skip-innodb wait-timeout = 5 max_connections = 512 max_connect_errors = 10000000 thread_concurrency = CPU 个 数 ×2 将 log-bin 注释(如果需要使用 mysql 的主从备份功能,需要 log- bin 参数打开,不能注释) bin/mysqladmin -u root password 'password_for_root' (注:password_for_root 为 mysql 的 root 帐户的密码,用户自行设定) 针对大型用户 mysql 优化的参数设置 (供参考 ): [mysqld] port = 3306 socket = /tmp/mysql.sock datadir = /data/mysql skip-locking skip-name-resolve skip-innodb skip-symbolic-links local-infile=0 low_priority_updates=1
  • 7. back_log = 300 key_buffer = 256M max_allowed_packet = 16M thread_stack = 128K table_cache = 1024 sort_buffer_size = 4M read_buffer_size = 256K join_buffer_size = 4M record_buffer = 2M read_rnd_buffer_size = 4M myisam_sort_buffer_size = 64M thread_cache_size = 64 query_cache_size = 32M tmp_table_size = 196M max_connections = 1600 max_connect_errors = 10000000000000 wait_timeout = 5 thread_concurrency=16 long_query_time = 1 log-slow-queries = /data/mysql/slow.log 3. 编译安装 Apache cd /usr/local/src tar xjvf httpd-2.2.11.tar.bz2 cd httpd-2.2.11 ./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 在编译安装 PHP 之前,我们首先关闭 selinux,以免编译时出现错误。 vi /etc/selinux/config 找到:SELINUX=enforcing 改为:SELINUX=disabled echo '0' > /selinux/enforce
  • 8. 开始安装编译 PHP: cd /usr/local/src tar xjvf php-5.2.8.tar.bz2 cd php-5.2.8 ./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- mysql-sock=/tmp --with-libxml-dir=/usr/local/libxml2 --with-gd --with-jpeg-dir -- with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-curl --with- mcrypt=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-sockets --enable-exif --enable-zend-multibyte --disable-ipv6 --disable-cgi make && make install cp php.ini-dist /usr/local/php/etc/php.ini 5. 安装 Eaccelerator cd /usr/local/src tar jxvf eaccelerator-0.9.5.3.tar.bz2 cd eaccelerator-0.9.5.3 /usr/local/php/bin/phpize ./configure --enable-eaccelerator=shared --with-php- config=/usr/local/php/bin/php-config --with-eaccelerator-shared-memory --with- eaccelerator-sessions --with-eaccelerator-content-caching make && make install mkdir /usr/local/php/ext cp modules/eaccelerator.so /usr/local/php/ext/ 安装为 Zend 扩展 vi /usr/local/php/etc/php.ini 插入 zend_extension="/usr/local/php/ext/eaccelerator.so" eaccelerator.shm_size="16" eaccelerator.cache_dir="/tmp/eaccelerator" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter=""
  • 9. eaccelerator.shm_max="0" eaccelerator.shm_ttl="0" eaccelerator.shm_prune_period="0" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9" mkdir /tmp/eaccelerator chmod 0777 /tmp/eaccelerator 6. 安装 memcache 扩展 cd /usr/local/src/ tar zxvf memcache-2.2.3.tgz cd memcache-2.2.3 /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make && make install cp modules/memcache.so /usr/local/php/ext/ 7. 安装 Zend Optimizer cd /usr/local/src tar xzvf ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz ./ ZendOptimizer-3.3.3-linux-glibc23-x86_64/install.sh 安装过程中需要指定 php.ini 的路径即/usr/local/php/etc 最后暂时先不要选择重启 Apache。 8. 整合 Apache 与 PHP 修改 PHP 配置文件: vi /usr/local/php/etc/php.ini 找到: extension_dir = "./" 改为: extension_dir = "/usr/local/php/ext" 找到: ;extension=php_zip.dll 在该行下添加 extension=memcache.so
  • 10. 修改完成后保存退出。 修改 Apache 配置文件: 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> 找到: User daemon Group daemon 改为: User www Group www 找到: <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Deny from all </Directory> 将其中的 Deny from all 改为 Allow from all 找到: #Include conf/extra/httpd-mpm.conf #Include conf/extra/httpd-info.conf #Include conf/extra/httpd-vhosts.conf #Include conf/extra/httpd-default.conf
  • 11. 去掉前面的“#”号,取消注释。 注意:以上 4 个扩展配置文件中的设置请按照相关原则进行合理配置! 修改完成后保存退出。 添加 www 用户,用来运行 Apache useradd www 重启 Apache /usr/local/apache2/bin/apachectl restart 根据虚拟主机中网站路径的设置(例如 /data/www/wwwroot),测试是否配 置成功 cd /data/www/wwwroot vi phpinfo.php <?php phpinfo ( ); ?> 退出并保存。 访问 http://IP 地址/phpinfo.php,检查 phpinfo 中的各项信息是否正确。 注:有时无法访问是因为系统开启了防火墙,建议关闭,设置自己的防火 墙策略(例如“三 服务器安全设置”中的设置),或者使用硬件防火墙。 9. 提升 PHP 安全性 在 php.ini 中进行设置提升 PHP 安全性。 vi /etc/php.ini、 找到并修改以下几处设置为:
  • 12. upload_tmp_dir = /tmp expose_php = Off display_errors = Off disable_functions = phpinfo,putenv,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_ope n,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,s ymlink,popepassthru,stream_socket_server 10. 提升 Apache 安全性及优化   进入 Apache 配置文件目录/usr/local/apache2/conf/extra    cd /usr/local/apache2/conf/extra     编 译 部 分 配 置 文 件 :    vi httpd-mpm.conf 找到并更更改以下内容: <IfModule mpm_prefork_module> ServerLimit 1024 StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 640 MaxRequestsPerChild 0 </IfModule>   注:添加 ServerLimit 这行参数,根据网站的访问量相应的调整 ServerLimit 和 MaxClients 两项参数,MaxClients 值不能大于 ServerLimit 的值。    vi httpd-default.conf   KeepAlive Off 注:此处默认为 Off,用户可根据前端负载均衡器的配置中是否保持会话连接
  • 13. 来选择开启或关闭,建议一般用户设置为 Off   修改以下参数为:   ServerTokens Prod ServerSignature off 修改以上 PHP 与 Apache 相关设置后需要重启 Apache 服务器。 三、服务器安全性设置 1. 设置系统防火墙 vi /usr/local/sbin/fw.sh 将以下脚本命令粘贴到 fw.sh 文件中。 #!/bin/bash # Stop iptables service first service iptables stop # Load FTP Kernel modules /sbin/modprobe ip_conntrack_ftp /sbin/modprobe ip_nat_ftp # Inital chains default policy /sbin/iptables -F -t filter /sbin/iptables -P INPUT DROP /sbin/iptables -P OUTPUT ACCEPT # Enable Native Network Transfer /sbin/iptables -A INPUT -i lo -j ACCEPT # Accept Established Connections /sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # ICMP Control /sbin/iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT # WWW Service /sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  • 14. # FTP Service /sbin/iptables -A INPUT -p tcp --dport 21 -j ACCEPT # SSH Service /sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT chmod 755 /usr/local/sbin/fw.sh echo '/usr/local/sbin/fw.sh' >> /etc/rc.local /usr/local/sbin/fw.sh