比思論壇

標題: LNMP+Memcached+GPerfTools For Discuz [打印本頁]

作者: admin    時間: 2012-2-9 04:01
標題: LNMP+Memcached+GPerfTools For Discuz
這是適合Discuz的LNMP,其他程式可能有缺少PHP擴展模塊,請自行編繹PHP加上需要的模塊。

安裝軟件為
Centos 5.5.17
Nginx 1.0.12
Mysql 5.5.20
PHP 5.3.10

以上為最新穩定版

把 (SELINUX=disabled)
vi /etc/selinux/config

cd /usr/local/src 下載以下所需軟件
  1. wget http://nginx.org/download/nginx-1.0.12.tar.gz
  2. wget http://hk2.php.net/get/php-5.3.10.tar.gz/from/this/mirror
  3. wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
  4. wget ftp://ftp.eenet.ee/pub/FreeBSD/distfiles/libmcrypt-2.5.8.tar.gz
  5. wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz/download
  6. wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.0.tar.gz
  7. wget http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz
  8. wget http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz
  9. wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.20.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/
  10. wget http://pecl.php.net/get/memcache-2.2.6.tgz
  11. wget http://pecl.php.net/get/imagick-3.0.1.tgz
  12. wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
複製代碼

安裝所需開發包

  1. yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel
複製代碼

同步時間,台灣時間

  1. crontab -e
複製代碼

加入以下這一句,儲存離開。

  1. */30 * * * * ntpdate tock.stdtime.gov.tw > /dev/null 2>&1
複製代碼

移除Apache(有沒安裝都可以打入下面一句)

  1. yum remove httpd
複製代碼

安装libunwind(64位元Centos才需要安裝)

  1. tar zxvf libunwind-1.0.tar.gz

  2. cd libunwind-1.0

  3. ./configure --enable-shared

  4. make && make install
複製代碼



安裝Google-perftools(加速nginx 和 mysql)

  1. tar zxvf gperftools-2.0.tar.gz

  2. cd gperftools-2.0

  3. ./configure

  4. make && make install
複製代碼



更新動態庫

  1. echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf

  2. /sbin/ldconfig
複製代碼

安裝MYSQL


  1. cd /usr/local/src

  2. tar zxvf cmake-2.8.7.tar.gz

  3. cd cmake-2.8.7

  4. ./configure

  5. make && make install

  6. cd /usr/local/src

  7. groupadd mysql

  8. useradd -g mysql -M -s /sbin/nologin mysql

  9. tar zxvf mysql-5.5.20.tar.gz

  10. cd mysql-5.5.20

  11. cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc/

  12. make && make install

  13. cp support-files/my-huge.cnf /etc/my.cnf
  14. /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --no-defaults
複製代碼

增加檔案權限給用戶MYSQL

  1. chown -R mysql:mysql /usr/local/mysql/data
  2. chgrp -R mysql /usr/local/mysql/.
複製代碼

開機自動啟動

  1. cp support-files/mysql.server /etc/init.d/mysqld
  2. chmod +x /etc/init.d/mysqld
  3. chkconfig --add mysqld
  4. chkconfig --level 2345 mysqld on
  5. echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
  6. echo "/usr/local/lib" >>/etc/ld.so.conf
  7. ldconfig
  8. ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
  9. ln -s /usr/local/mysql/include/mysql /usr/include/mysql
  10. service mysqld start
  11. /usr/local/mysql/bin/mysqladmin -u root password 1234 (1234為密碼,可以自行設定)
  12. service mysqld restart
複製代碼
  1. /usr/local/mysql/bin/mysql -u root –p
  2. 輸入密碼:1234
複製代碼
  1. mysql>use mysql;
  2. mysql>select Host,User,Password,Select_priv,Grant_priv from user;
  3. mysql>delete from user where user='';                  (删除user用户)
  4. mysql>delete from user where password='';               (删除user用户)
  5. mysql>delete from user where host='';                     (删除user用户)
  6. mysql>flush privileges;               (刷新mysql的缓存,让以上设置立即生效)
  7. mysql>quit;
複製代碼

vi /etc/my.cnf

在[mysqld]下面增加
  1. wait-timeout = 10
  2. max_connections = 512
  3. max_connect_errors = 10000000
複製代碼

修改max_allowed_packet =16M

儲存後離開

內存小的,可以關閉innodb,編輯/etc/my.cnf,在[mysqld]下面增加。
  1. default-storage-engine = MyISAM
  2. skip-innodb
複製代碼

使用tcmalloc加速MYSQL

vi /usr/local/mysql/bin/mysqld_safe

在# executing mysqld_safe下加一行
  1. export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
複製代碼

儲存後離開,重啟MYSQL。

  1. service mysqld restart
複製代碼

查看tcmalloc有沒正確啟動

  1. lsof -n | grep tcmalloc
複製代碼

如果出現如下類似的信息,代表正確生效。

mysqld    7368     mysql  mem       REG      253,0  1727456    8632769 /usr/local/lib/libtcmalloc.so.4.1.0

安裝NGINX及增加用戶和權限。

  1. groupadd www

  2. useradd -g www www

  3. mkdir -p /data/wwwroot

  4. chmod +w /data/wwwroot

  5. chown www:www /data/wwwroot -R
複製代碼


  1. cd /usr/local/src/

  2. tar zxvf nginx-1.0.12.tar.gz

  3. cd nginx-1.0.12

  4. ./configure –user=www –group=www --prefix=/usr/local/nginx --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --with-http_random_index_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-google_perftools_module

  5. make

  6. make install
複製代碼

增加開機自動啟動

  1. cp /usr/local/src/nginx /etc/init.d/nginx

  2. chmod 755 /etc/init.d/nginx

  3. chkconfig nginx on
複製代碼


使用google-perftools加速NGINX

  1. vi /usr/local/nginx/conf/nginx.conf
複製代碼

修改#user nobody;

  1. user www www;
複製代碼

#error_log logs/error.log;

  1. error_log logs/error.log crit;
複製代碼

#pid logs/nginx.pid;

  1. pid logs/nginx.pid;
  2. google_perftools_profiles /tmp/tcmalloc/;
  3. events{
  4. use epoll;
  5. worker_connections 65535;
  6. }
複製代碼

儲存後離開及創建目錄及相關權限

  1. mkdir /tmp/tcmalloc
  2. chmod 0777 /tmp/tcmalloc
複製代碼

啟動NGINX

  1. service nginx restart
複製代碼

輸入下面字令

  1. ps au|grep nginx
複製代碼

如果出現如下類似的信息,代表NGINX已經啟動。

root      9705  0.0  0.0   5120   672 pts/1    S+   12:40   0:00 grep nginx

輸入下面字令

  1. lsof -n | grep tcmalloc
複製代碼

如果出現如下類似的信息,代表正確生效

  1. nginx     12135       www    9w      REG      253,0        0   20774967 /tmp/tcmalloc/.12135
複製代碼

安裝PHP所需要的庫

安裝Libiconv

  1. cd /usr/local/src/

  2. tar zxvf libiconv-1.14.tar.gz

  3. cd libiconv-1.14/

  4. ./configure --prefix=/usr/local

  5. make

  6. make install

  7. cd ..
複製代碼


安裝Libmcrypt

  1. tar zxvf libmcrypt-2.5.8.tar.gz

  2. cd libmcrypt-2.5.8

  3. ./configure

  4. make

  5. make install

  6. /sbin/ldconfig

  7. cd libltdl/

  8. ./configure --enable-ltdl-install

  9. make

  10. make install

  11. cd /usr/local/src/
複製代碼


安裝Mhash

  1. tar zxvf mhash-0.9.9.9.tar.gz

  2. cd mhash-0.9.9.9/

  3. ./configure

  4. make

  5. make install

  6. cd ..
複製代碼

做軟連接(32位)

  1. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
  2. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
  3. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
  4. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
  5. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
  6. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
  7. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
  8. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
  9. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
  10. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
複製代碼

做軟連接(64位)

  1. ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
  2. ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
  3. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
  4. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
  5. ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
  6. ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
  7. ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
  8. ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
  9. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
  10. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
  11. ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/libiconv.so.2
複製代碼

安裝Mcrypt


  1. tar zxvf mcrypt-2.6.8.tar.gz
  2. cd mcrypt-2.6.8
  3. /sbin/ldconfig
  4. ./configure
  5. make
  6. make install
複製代碼

安裝PH5.3.10


  1. cd /usr/local/src
  2. tar zxvf php-5.3.10.tar.gz
  3. cd php-5.3.10
  4. ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-xml --enable-mbstring --enable-ftp --with-gd --enable-magic-quotes --with-pear --enable-sockets --with-ttf --enable-gd-native-ttf --enable-sysvsem --enable-sysvshm --enable-shmop --enable-force-cgi-redirect --enable-fastcgi --enable-zip --enable-fpm --with-mhash --with-mcrypt --enable-discard-path --enable-bcmath --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --with-openssl
  5. make ZEND_EXTRA_LIBS='-liconv'
  6. make install
  7. cp php.ini-production /usr/local/php/etc/php.ini
  8. echo 'ulimit -SHn 65535' >> /etc/rc.local
複製代碼

安裝PHP Memcahce 模塊

  1. tar zxvf memcache-3.0.6.tgz
  2. cd memcache-3.0.6
  3. /usr/local/php/bin/phpize
  4. ./configure --with-php-config=/usr/local/php/bin/php-config
  5. make
  6. make install
複製代碼

修改php.ini

  1. vi /usr/local/php/etc/php.ini
複製代碼

output_buffering = 4096

修改

  1. output_buffering = On
複製代碼

; extension_dir = "./"

修改

  1. extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
複製代碼

下加

  1. extension = "memcache.so"
複製代碼

安裝Memcached

  1. cd /usr/local/src
  2. tar zxvf libevent-1.4.13-stable.tar.gz
  3. cd libevent-1.4.13-stable
  4. ./configure --prefix=/usr/lib
  5. make
  6. make install
  7. cd ..
  8. tar zxvf memcached-1.4.13.tar.gz
  9. cd memcached-1.4.13
  10. ./configure --prefix=/usr/local --with-libevent=/usr/lib/
  11. make
  12. make install
複製代碼

啟動Memcahced

  1. /usr/local/bin/memcached -d -u www -m 128
複製代碼

增加開機支持

  1. echo '/usr/local/bin/memcached -d -u www -m 128' >> /etc/rc.local
複製代碼

安裝PHP-FPM

  1. cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
複製代碼

修改

  1. vi /usr/local/php/etc/php-fpm.conf
複製代碼
  1. user = www
  2. group = www
  3. pid = run/php-fpm.pid-p
  4. error_log = log/php-fpm.log
  5. log_level = notice:
複製代碼

儲存後離開,使NGINX支持PHP。

  1. vi /usr/local/nginx/conf/nginx.conf
複製代碼
  1. location ~ \.php$ {
  2. root /home/www/wwwroot;
  3. fastcgi_pass 127.0.0.1:9000;
  4. fastcgi_index index.php;
  5. fastcgi_param SCRIPT_FILENAME  /home/www/wwwroot$fastcgi_script_name;
  6. include fastcgi_params;
  7. }
複製代碼

儲存後離開

  1. cd /usr/local/src/php-5.3.10
  2. cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  3. chmod 755 /etc/init.d/php-fpm
  4. chkconfig --add php-fpm
  5. chkconfig php-fpm on
  6. service php-fpm start
複製代碼

終於完成,感受一下吧,此文為比思論壇原創文章,轉貼請注明出處,謝謝。


作者: taiyangtians    時間: 2012-9-14 22:22
版主还是挺好学额嘛




歡迎光臨 比思論壇 (http://108.170.5.99:8181/) Powered by Discuz! X2.5