Chinaunix首页 | 论坛 | 博客
  • 博客访问: 228268
  • 博文数量: 57
  • 博客积分: 1149
  • 博客等级: 少尉
  • 技术积分: 584
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-29 11:35
文章分类

全部博文(57)

文章存档

2016年(1)

2014年(1)

2013年(2)

2012年(27)

2011年(26)

分类: LINUX

2011-11-04 16:33:45

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

1.下载软件编译安装
  1)下载软件
  1.   # cd /usr/local/src
  2.     httpd-2.2.8.tar.gz  
  3.     mysql-5.0.51b.tar.gz   
  4.     php-5.2.6.tar.bz2
  5.     ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
复制代码
2) 安装MySQL
    查看分析你的CPU型号:
     查找您的GCC编译参数.
    确定系统CPU类型:
    # cat /proc/cpuinfo | grep "model name"
    执行后会看到系统中CPU的具体型号,记下CPU型号。
  1.     # tar xvf mysql-5.0.51b.tar.gz   
  2.     # cd mysql-5.0.51b
  3.     # vi mysql.sh
  4. -------------------cut begin-------------------------------------------

  5. •CHOST="i686-pc-linux-gnu"

  6. •CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"

  7. •CXXFLAGS="${CFLAGS}"

  8. •./configure \

  9. •        "--prefix=/usr/local/mysql" \

  10. •        "--localstatedir=/data/mysql/data" \

  11. •        "--with-comment=Source" \

  12. •        "--with-server-suffix=-LinuxTone" \

  13. •        "--with-mysqld-user=mysql" \

  14. •        "--without-debug" \

  15. •        "--with-big-tables" \

  16. •        "--with-charset=utf8" \

  17. •        "--with-collation=utf8_chinese_ci" \

  18. •        "--with-extra-charsets=all" \

  19. •        "--with-pthread" \

  20. •        "--enable-static" \

  21. •        "--enable-thread-safe-client" \

  22. •        "--with-client-ldflags=-all-static" \

  23. •        "--with-mysqld-ldflags=-all-static" \

  24. •        "--enable-assembler" \

  25. •        "--without-isam" \

  26. •        "--without-innodb" \

  27. •        "--without-ndb-debug"

  28. •make && make install

  29. •mkdir -p /data/mysql/data

  30. •useradd mysql -d /data/mysql -s /sbin/nologin

  31. •/usr/local/mysql/bin/mysql_install_db --user=mysql

  32. •cd /usr/local/mysql

  33. •chown -R root:mysql .

  34. •chown -R mysql /data/mysql/data

  35. •cp share/mysql/my-huge.cnf /etc/my.cnf

  36. •cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld

  37. •chmod 755 /etc/rc.d/init.d/mysqld

  38. •chkconfig --add mysqld

  39. •/etc/rc.d/init.d/mysqld start



  40. •cd /usr/local/mysql/bin

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

复制代码
•-------------------cut end---------------------------------------------
复制代码#sh mysql.sh 即可开始编译.
  1.   3) 编译安装Apache
  2. # cd /usr/local/src
  3. # tar xvf httpd-2.2.8.tar.gz  
  4. # cd httpd-2.2.8
  5. ./configure \

  6. •        "--prefix=/usr/local/apache2" \

  7. •        "--with-included-apr" \

  8. •        "--enable-so" \

  9. •        "--enable-deflate=shared" \

  10. •        "--enable-expires=shared" \

  11. •        "--enable-rewrite=shared" \

  12. •        "--enable-static-support" \

  13. •        "--disable-userdir"

  14. •make

  15. •make install

  16. •echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local
复制代码
复制代码4.)编译安装PHP
  1.     # cd /usr/local/src
  2.     # tar xjvf php-5.2.6.tar.bz2
  3.     # cd php-5.2.6
  4. ./configure \

  5. •        "--prefix=/usr/local/php" \

  6. •        "--with-apxs2=/usr/local/apache2/bin/apxs" \

  7. •        "--with-config-file-path=/usr/local/php/etc" \

  8. •        "--with-mysql=/usr/local/mysql" \

  9. •        "--with-libxml-dir=/usr/local/libxml2" \

  10. •        "--with-gd=/usr/local/gd2" \

  11. •        "--with-jpeg-dir" \

  12. •        "--with-png-dir" \

  13. •        "--with-bz2" \

  14. •        "--with-freetype-dir" \

  15. •        "--with-iconv-dir" \

  16. •        "--with-zlib-dir " \

  17. •        "--with-openssl=/usr/local/openssl" \

  18. •        "--with-mcrypt=/usr/local/libmcrypt" \

  19. •        "--enable-soap" \

  20. •        "--enable-gd-native-ttf" \

  21. •        "--enable-ftp" \

  22. •        "--enable-mbstring" \

  23. •        "--enable-exif" \

  24. •        "--disable-ipv6" \

  25. •        "--disable-cgi" \

  26. •        "--disable-cli"           #禁掉ipv6,禁掉cli模式,提升速度和安全性.请根据具体需求定制相关的编译数.

  27. •make

  28. •make install

  29. •mkdir /usr/local/php/etc

  30. •cp php.ini-dist /usr/local/php/etc/php.ini
复制代码
  1. 复制代码5)Xcache的安装.
  2.   #tar xvf xcache-1.2.2.tar.gz
  3.   #/usr/local/php/bin/phpize 

  4. •  ./configure --enable-xcache --enable-xcache-coverager --with-php-config=/usr/local/php/bin/php-config \

  5. •  --enable-inline-optimization --disable-debug
复制代码
复制代码#vi /usr/local/php/etc/php.ini (将以下内容加入php.ini最后面)
-------------------cut begin-------------------------------------------
  1. •[xcache-common]

  2. •zend_extension      = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so



  3. •[xcache.admin]

  4. •xcache.admin.user   = "admin"

  5. •;如何生成md5密码: echo -n "password"| md5sum

  6. •xcache.admin.pass   = "035d849226a8a10be1a5e0fec1f0f3ce"  #密码为52netseek



  7. •[xcache]

  8. •; Change xcache.size to tune the size of the opcode cache

  9. •xcache.size         = 24M

  10. •xcache.shm_scheme   = "mmap"

  11. •xcache.count        = 4

  12. •xcache.slots        = 8K

  13. •xcache.ttl          = 0

  14. •xcache.gc_interval  = 0



  15. •; Change xcache.var_size to adjust the size of variable cache

  16. •xcache.var_size     = 8M

  17. •xcache.var_count    = 1

  18. •xcache.var_slots    = 8K

  19. •xcache.var_ttl      = 0

  20. •xcache.var_maxttl   = 0

  21. •xcache.var_gc_interval =     300

  22. •xcache.test         = Off

  23. •xcache.readonly_protection = On

  24. •xcache.mmap_path    = "/tmp/xcache"

  25. •xcache.coredump_directory =   ""

  26. •xcache.cacher       = On

  27. •xcache.stat         = On

  28. •xcache.optimizer    = Off



  29. •[xcache.coverager]

  30. •xcache.coverager    = On

  31. •xcache.coveragedump_directory = ""
复制代码
•-------------------cut end---------------------------------------------
复制代码6) 安装Zend Optimizer
  1.    # cd /usr/local/src
  2.     # tar xzvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
  3.     # ./ZendOptimizer-3.3.3-linux-glibc23-i386/install.sh
复制代码
安装Zend Optimizer过程的最后不要选择重启Apache。


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

   找到:

  1.        DirectoryIndex index.html
  2.    
  3.    将该行改为
  4.    
  5.         DirectoryIndex index.html index.htm index.php
  6.    
复制代码
找到:
  1. #Include conf/extra/httpd-mpm.conf
  2. #Include conf/extra/httpd-info.conf
  3. #Include conf/extra/httpd-vhosts.conf  (虚拟主机配置文件存放目录.)
  4. #Include conf/extra/httpd-default.conf
复制代码
去掉前面的“#”号,取消注释。
注意:以上 4 个扩展配置文件中的设置请按照相关原则进行合理配置!

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

  2)查看确认L.A.M.P环境信息、提升 PHP 安全性
   在网站根目录放置 info.php 脚本,检查phpinfo中的各项信息是否正确。
  1.    
  2.    phpinfo();
  3.    ?>
  4.    
复制代码
确认 PHP 能够正常工作后,在 php.ini 中进行设置提升 PHP 安全性,禁掉危险的函数.
   # vi /etc/php.ini找到:disable_functions =设置为:
  1. 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-------------------------------------------
  1. •#!/bin/bash

  2. •#Written by :NetSeek

  3. •#init_httpd.conf

  4. •http_cf="/usr/local/apache2/conf/httpd.conf"

  5. sed -i -e "s/User daemon/User www/" -i -e "s/Group daemon/Group www/" $http_cf

  6. •sed -i -e '121 s/^/#/' -i -e '122 s/^/#/' $http_cf

  7. •sed -i 's#DirectoryIndex index.html# DirectoryIndex index.php index.html index.htm#/g'  $http_cf

  8. •sed -i -e '374 s/^#//g' -i -e '389 s/^#//g' -i -e '392 s/^#//g' -i -e '401 s/^#//g' $http_cf

  9. •#init_php(PHP安全设置及隐藏PHP版本)

  10. •php_cf="/usr/local/php/etc/php.ini"

  11. •sed -i '205 s#;open_basedir =#open_basedir = /data/www/wwwroot:/tmp#g' $php_cf

  12. •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 

  13. •sed -i '/expose_php/s/On/Off/' $php_cf

  14. •sed -i '/display_errors/s/On/Off/' $php_cf
复制代码
•-------------------cut end-------------------------------------------
复制代码三、配置虚拟主机及基本性能调优
1) 配置虚拟主机:
  1. #vi /usr/local/apache2/conf/extra/httpd-vhosts.conf
  2. NameVirtualHost *:80





  3. •    ServerAdmin cnseek@gmail.com

  4. •    DocumentRoot "/data/www/wwwroot/linuxtone.org"

  5. •    ServerName

  6. •    ServerAlias bbs.linxutone.org

  7. •    ErrorLog "logs/dummy-host.example.com-error_log"

  8. •    CustomLog "|/usr/sbin/cronolog /data/logs/access_.%Y%m%d" combined 


  9. 复制代码2).基本性能调优参考:(更多的调优相关文章请关注:性能调优相关的贴子)
  10. #vi /usr/local/apache2/conf/extra/httpd-default.conf
  11. Timeout 15

  12. •KeepAlive Off

  13. •MaxKeepAliveRequests 50

  14. •KeepAliveTimeout 5

  15. •UseCanonicalName Off

  16. •AccessFileName .htaccess

  17. •ServerTokens Prod 

  18. •ServerSignature Off 

  19. •HostnameLookups Off
  20. 复制代码#vi /usr/local/apache2/conf/extra/httpd-mpm.conf


  21. •    ServerLimit         2000

  22. •    StartServers          10

  23. •    MinSpareServers       10

  24. •    MaxSpareServers      15

  25. •    MaxClients          2000

  26. •    MaxRequestsPerChild   10000

复制代码
复制代码3).Apache日志处理相关问题汇总贴()
   利用awstats分析网站日志:

   忽略不需要的日志配置参考具体请据据具体问题分析:
   LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
   #下面加入如下内容:
  1.     # filter the localhost visit

  2. •    SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog

  3. •    # filter some special directories

  4. •    SetEnvIf Request_URI "^ZendPlatform.*[code]

  5. •    # filter the localhost visit

  6. •    SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog

  7. •    # filter some special directories

  8. •    SetEnvIf Request_URI "^ZendPlatform.*[        DISCUZ_CODE_9        ]quot; dontlog

  9. •    SetEnvIf Request_URI \.healthcheck\.html$ dontlog

  10. •    SetEnvIf Remote_Addr "::1" dontlog

  11. •    SetEnvIf Request_URI "\.getPing.php[        DISCUZ_CODE_9        ]quot; dontlog

  12. •    SetEnvIf Request_URI "^/error\.html[        DISCUZ_CODE_9        ]quot; dontlog

  13. •    SetEnvIf Request_URI "\.gif[        DISCUZ_CODE_9        ]quot; dontlog

  14. •    SetEnvIf Request_URI "\.jpg[        DISCUZ_CODE_9        ]quot; dontlog

  15. •    SetEnvIf Request_URI "\.css[        DISCUZ_CODE_9        ]quot; dontlog
  16. 复制代码quot; dontlog
  17.     SetEnvIf Request_URI \.healthcheck\.html$ dontlog
  18.     SetEnvIf Remote_Addr "::1" dontlog
  19.     SetEnvIf Request_URI "\.getPing.php[        DISCUZ_CODE_9        ]quot; dontlog
  20.     SetEnvIf Request_URI "^/error\.html[        DISCUZ_CODE_9        ]quot; dontlog
  21.     SetEnvIf Request_URI "\.gif[        DISCUZ_CODE_9        ]quot; dontlog
  22.     SetEnvIf Request_URI "\.jpg[        DISCUZ_CODE_9        ]quot; dontlog
  23.     SetEnvIf Request_URI "\.css[        DISCUZ_CODE_9        ]quot; dontlog
复制代码
4). Apache防盗链(Apache防盗链相关问题汇总:)
    RewriteEngine on

•    RewriteCond %{HTTP_REFERER} !^$

•    RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]

•    RewriteRule \.(gif|jpg)$ http://网站域名/nolink.png [R,L][/code]复制代码四、基本安全设置
  1)iptables 封锁相关端口(推荐读CU白金大哥的两小时玩转iptables)
  2)SSH全安(修改SSH端口限制来源IP登陆,或者参考)
  3)Linux防Arp攻击策略()
  4)注意(还是那句老话:安全工作从细节做起!)
阅读(1395) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~