比思論壇
標題:
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 下載以下所需軟件
wget http://nginx.org/download/nginx-1.0.12.tar.gz
wget http://hk2.php.net/get/php-5.3.10.tar.gz/from/this/mirror
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wget ftp://ftp.eenet.ee/pub/FreeBSD/distfiles/libmcrypt-2.5.8.tar.gz
wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz/download
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.0.tar.gz
wget http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz
wget http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz
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/
wget http://pecl.php.net/get/memcache-2.2.6.tgz
wget http://pecl.php.net/get/imagick-3.0.1.tgz
wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
複製代碼
安裝所需開發包
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
複製代碼
同步時間,台灣時間
crontab -e
複製代碼
加入以下這一句,儲存離開。
*/30 * * * * ntpdate tock.stdtime.gov.tw > /dev/null 2>&1
複製代碼
移除Apache(有沒安裝都可以打入下面一句)
yum remove httpd
複製代碼
安装libunwind(64位元Centos才需要安裝)
tar zxvf libunwind-1.0.tar.gz
cd libunwind-1.0
./configure --enable-shared
make && make install
複製代碼
安裝Google-perftools(加速nginx 和 mysql)
tar zxvf gperftools-2.0.tar.gz
cd gperftools-2.0
./configure
make && make install
複製代碼
更新動態庫
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
複製代碼
安裝MYSQL
cd /usr/local/src
tar zxvf cmake-2.8.7.tar.gz
cd cmake-2.8.7
./configure
make && make install
cd /usr/local/src
groupadd mysql
useradd -g mysql -M -s /sbin/nologin mysql
tar zxvf mysql-5.5.20.tar.gz
cd mysql-5.5.20
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc/
make && make install
cp support-files/my-huge.cnf /etc/my.cnf
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --no-defaults
複製代碼
增加檔案權限給用戶MYSQL
chown -R mysql:mysql /usr/local/mysql/data
chgrp -R mysql /usr/local/mysql/.
複製代碼
開機自動啟動
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
echo "/usr/local/lib" >>/etc/ld.so.conf
ldconfig
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
service mysqld start
/usr/local/mysql/bin/mysqladmin -u root password 1234 (1234為密碼,可以自行設定)
service mysqld restart
複製代碼
/usr/local/mysql/bin/mysql -u root –p
輸入密碼:1234
複製代碼
mysql>use mysql;
mysql>select Host,User,Password,Select_priv,Grant_priv from user;
mysql>delete from user where user=''; (删除user用户)
mysql>delete from user where password=''; (删除user用户)
mysql>delete from user where host=''; (删除user用户)
mysql>flush privileges; (刷新mysql的缓存,让以上设置立即生效)
mysql>quit;
複製代碼
vi /etc/my.cnf
在[mysqld]下面增加
wait-timeout = 10
max_connections = 512
max_connect_errors = 10000000
複製代碼
修改max_allowed_packet =16M
儲存後離開
內存小的,可以關閉innodb,編輯/etc/my.cnf,在[mysqld]下面增加。
default-storage-engine = MyISAM
skip-innodb
複製代碼
使用tcmalloc加速MYSQL
vi /usr/local/mysql/bin/mysqld_safe
在# executing mysqld_safe下加一行
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
複製代碼
儲存後離開,重啟MYSQL。
service mysqld restart
複製代碼
查看tcmalloc有沒正確啟動
lsof -n | grep tcmalloc
複製代碼
如果出現如下類似的信息,代表正確生效。
mysqld 7368 mysql mem REG 253,0 1727456 8632769 /usr/local/lib/libtcmalloc.so.4.1.0
安裝NGINX及增加用戶和權限。
groupadd www
useradd -g www www
mkdir -p /data/wwwroot
chmod +w /data/wwwroot
chown www:www /data/wwwroot -R
複製代碼
cd /usr/local/src/
tar zxvf nginx-1.0.12.tar.gz
cd nginx-1.0.12
./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
make
make install
複製代碼
增加開機自動啟動
cp /usr/local/src/nginx /etc/init.d/nginx
chmod 755 /etc/init.d/nginx
chkconfig nginx on
複製代碼
使用google-perftools加速NGINX
vi /usr/local/nginx/conf/nginx.conf
複製代碼
修改#user nobody;
user www www;
複製代碼
#error_log logs/error.log;
error_log logs/error.log crit;
複製代碼
#pid logs/nginx.pid;
pid logs/nginx.pid;
google_perftools_profiles /tmp/tcmalloc/;
events{
use epoll;
worker_connections 65535;
}
複製代碼
儲存後離開及創建目錄及相關權限
mkdir /tmp/tcmalloc
chmod 0777 /tmp/tcmalloc
複製代碼
啟動NGINX
service nginx restart
複製代碼
輸入下面字令
ps au|grep nginx
複製代碼
如果出現如下類似的信息,代表NGINX已經啟動。
root 9705 0.0 0.0 5120 672 pts/1 S+ 12:40 0:00 grep nginx
輸入下面字令
lsof -n | grep tcmalloc
複製代碼
如果出現如下類似的信息,代表正確生效
nginx 12135 www 9w REG 253,0 0 20774967 /tmp/tcmalloc/.12135
複製代碼
安裝PHP所需要的庫
安裝Libiconv
cd /usr/local/src/
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14/
./configure --prefix=/usr/local
make
make install
cd ..
複製代碼
安裝Libmcrypt
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd /usr/local/src/
複製代碼
安裝Mhash
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ..
複製代碼
做軟連接(32位)
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
複製代碼
做軟連接(64位)
ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/libiconv.so.2
複製代碼
安裝Mcrypt
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure
make
make install
複製代碼
安裝PH5.3.10
cd /usr/local/src
tar zxvf php-5.3.10.tar.gz
cd php-5.3.10
./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
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/php/etc/php.ini
echo 'ulimit -SHn 65535' >> /etc/rc.local
複製代碼
安裝PHP Memcahce 模塊
tar zxvf memcache-3.0.6.tgz
cd memcache-3.0.6
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
複製代碼
修改php.ini
vi /usr/local/php/etc/php.ini
複製代碼
output_buffering = 4096
修改
output_buffering = On
複製代碼
; extension_dir = "./"
修改
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
複製代碼
下加
extension = "memcache.so"
複製代碼
安裝Memcached
cd /usr/local/src
tar zxvf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure --prefix=/usr/lib
make
make install
cd ..
tar zxvf memcached-1.4.13.tar.gz
cd memcached-1.4.13
./configure --prefix=/usr/local --with-libevent=/usr/lib/
make
make install
複製代碼
啟動Memcahced
/usr/local/bin/memcached -d -u www -m 128
複製代碼
增加開機支持
echo '/usr/local/bin/memcached -d -u www -m 128' >> /etc/rc.local
複製代碼
安裝PHP-FPM
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
複製代碼
修改
vi /usr/local/php/etc/php-fpm.conf
複製代碼
user = www
group = www
pid = run/php-fpm.pid-p
error_log = log/php-fpm.log
log_level = notice:
複製代碼
儲存後離開,使NGINX支持PHP。
vi /usr/local/nginx/conf/nginx.conf
複製代碼
location ~ \.php$ {
root /home/www/wwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/wwwroot$fastcgi_script_name;
include fastcgi_params;
}
複製代碼
儲存後離開
cd /usr/local/src/php-5.3.10
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
service php-fpm start
複製代碼
終於完成,感受一下吧,此文為
比思論壇
原創文章,轉貼請注明出處,謝謝。
作者:
taiyangtians
時間:
2012-9-14 22:22
版主还是挺好学额嘛
歡迎光臨 比思論壇 (http://108.170.10.236/)
Powered by Discuz! X2.5