歡迎您光臨本站 註冊首頁

基於CentOS構建高性能的LAMP平台.

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

基於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 | 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  (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

   2) LibXML2
       # cd /usr/local/src
                # tar xvf 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 xvf 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 xvf 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 xvf openssl-0.9.8g.tar.gz
    # cd openssl-0.9.8g
    # ./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---------------------------------------------
複製代碼
《解決方案》

謝謝分享
《解決方案》

教程很不錯啊:lol
《解決方案》

太感謝分享,好資料!
《解決方案》

樓主的分享精神很是佩服,
我看了之後對分區有點想法,
備份的數據放哪比較好。

[火星人 ] 基於CentOS構建高性能的LAMP平台.已經有705次圍觀

http://coctec.com/docs/service/show-post-1078.html