• 基于CentOS构建高功能的LAMP平台




    作者: linuxtone  出自: http://www.linuxdiyf.com
    作者:NetSeek http://www.linuxtone.org(IT运维|集群架构|功能调优)
    欢迎转载,转载时请务必以超链接方式标明文章原始来由和作者信息及本声明.

    纲要:
    一、零碎装配
    二、编译装配根底情况
    三、设置装备部署编造主机及根底功能调优
    四、根底安好设置
    五、附录及相关引见

    一、零碎装配
    1. 分区
    /boot 100M摆布
    SWAP 物理内存的2倍(要是你的物理内存年夜于4G以上,分派4G即可)
    /usr/local 15G (用于装配软件)
    /data 残剩一切空间

    2. 零碎初始化脚本(凭据注意需求关闭不必要的就事)

    CODE:
    #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 | sshd | syslog | local | mysqld )
    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

    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 xzvf gd-2.0.35.tar.gz
    # cd gd-2.0.35
    # ./configure --prefix=/usr/local/gd2
    # make
    # make install

    2) LibXML2
    # cd /usr/local/src
    # tar xjvf libxml2-2.6.29.tar.bz2
    # cd libxml2-2.6.29
    # ./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.6.2.tar.gz
    # cd cronolog-1.6.2
    # ./configure --prefix=/usr/local/cronolog
    # make
    # make install



    3. 升级OpenSSL和OpenSSH
    # cd /usr/local/src
    # tar xzvf openssl-0.9.8g.tar.gz
    # cd openssl-0.9.8g
    # ./config --prefix=/usr/local/openssl
    # make
    # make test
    # make install
    # cd ..
    # tar xzvf 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设置装备部署可运用以下脚本自动修正:
    CODE:
    -------------------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型号。

    # tar zxvf mysql-5.0.51b.tar.gz
    # cd mysql-5.0.51b
    # vi mysql.sh
    CODE:
    -------------------cut begin-------------------------------------------
    CHOST="i686-pc-linux-gnu"
    CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"
    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=gbk" \
    "--with-collation=gbk_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" \
    "--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
    # cd /usr/local/src
    # tar zxvf httpd-2.2.8.tar.gz
    # cd httpd-2.2.8
    CODE:
    # ./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
    CODE:
    # ./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-libxml-dir=/usr/local/libxml2" \
    "--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/local/openssl" \
    "--with-mcrypt=/usr/local/libmcrypt" \
    "--enable-soap" \
    "--enable-gd-native-ttf" \
    "--enable-memory-limit" \
    "--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 zxvf xcache-1.2.2.tar.gz
    CODE:
    #/usr/local/php-fcgi/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最背面)
    CODE:
    -------------------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 xzvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
    # ./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

    找到:

    DirectoryIndex index.html

    将该行改为

    DirectoryIndex index.html index.htm index.php


    找到:
    #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中的各项信息能否正确。
    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
    CODE:
    -------------------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 index.htm# DirectoryIndex index.phpindex.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/php/etc/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
    CODE:
    NameVirtualHost *:80

    <VirtualHost *:80>
    ServerAdmin cnseek@gmail.com
    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
    CODE:
    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
    CODE:
    <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
    #上面插手如下内容:
    CODE:
    # filter the localhost visit
    SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog
    # filter some special directories
    SetEnvIf Request_URI "^ZendPlatform.*$" dontlog
    SetEnvIf Request_URI \.healthcheck\.html$ dontlog
    SetEnvIf Remote_Addr "::1" dontlog
    SetEnvIf Request_URI "\.getPing.php$" dontlog
    SetEnvIf Request_URI "^/error\.html$" dontlog
    SetEnvIf Request_URI "\.gif$" dontlog
    SetEnvIf Request_URI "\.jpg$" dontlog
    SetEnvIf Request_URI "\.css$" dontlog


    4). Apache防盗链(Apache防盗链相关题目汇总:http://bbs.linuxtone.org/thread-101-1-1.html)
    CODE:
    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

    1)运用Nginx替代apache完成高功能的Web情况(初版): http://bbs.linuxtone.org/thread-7-1-1.html
    第二版注意安好设置装备部署近期更新,请实时关注:http://bbs.linuxtone.org/(网站就事器版)

    2)关于LinuxTone.Org(IT运维专家论坛):
    目的:希冀和巨匠一同死力打造一个专注IT运维,Linux集群架构的开放互动会谈平台!守候您的插手!

    我们很愿意把往常义务中碰到的题目和获得的阅历与巨匠配合分享相互进修!
    要是你是Linux喜欢者?
    要是你今朝在网站就事器方面碰到很多头痛的题目?
    要是你今朝的站就运用了Linux?或许你想将你的Linux的apache迁于至高功能的Nginx?
    要是您运用的是WAMP(即Windows平台的AMP)平台想选移LAMP?
    要是你今朝的网站必要优化进一步晋升硬件功能?
    要是你今朝的网站必要负载平衡集群架构方案? 请联结我们!
    我们愿意抽出空余时间免费热心为你解答相关题目,帮忙你完成一切相关义务!配合分享!配合提高!
    同时也热情守候你能插手http://www.linuxtone.org 帮我一同完美论坛树立义务,完成每版置顶的手册组成可操作性
    强的文档及方案,随意巨匠一同砚习提高!联结方式:QQ:67888954 MSN:cnseek@msn.com Gtalk:cnseek@gmail.com



    版权声明: 原创作品,容许转载,转载时请务必以超链接方式标明文章 原始来由 、作者信息和本声明。否则将追查执法责任。

  • 相关阅读:
    设计模式
    刷新所有视图存储过程
    js杨辉三角控制台输出
    2018申请淘宝客AppKey
    w3c标准 dom对象 事件冒泡和事件捕获
    promise原理
    vue virtual Dom
    css学习
    seo优化
    新概念学习
  • 原文地址:https://www.cnblogs.com/zgqjymx/p/1973124.html
Copyright © 2020-2023  润新知