基于CentOS构建高性能的LAMP平台

基于CentOS构建高性能的LAMP平台

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

大纲:
一、系统安装
二、编译安装基本环境
三、配置虚拟主机及基本性能调优
四、基本安全设置
五、附录及相关介绍

一、系统安装
1. 分区
   /boot 100M左右
   SWAP  物理内存的2倍(如果你的物理内存大于4G以上,分配4G即可)
   /usr/local 15G (用于安装软件)
   /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 | 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 (执行上面保存的脚本,仍后重启)
三、编译安装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
复制内容到剪贴板
代码:
-------------------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---------------------------------------------