Lnmp安裝配置(nginx)
1.準備php函數的rpm包
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
2.準備lnmp其他的源代碼包
wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz
3.安裝php-5.2.14源代碼包所需要的函數支持包
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install
cd ../
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
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
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure
make
make install
cd ../
4. 編譯安裝MySQL 5.5.3-m3
./configure --prefix=/usr/local/mysql --without-debug --enable-thread-safe-client --with-pthread --enable-assembler --enable-profiling --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-extra-charsets=all --with-plugins=all --with-mysqld-user=mysql --without-embedded-server --with-server-suffix=-community --with-unix-socket-path=/tmp/mysql.sock
Make
#編譯
Make install
#安裝
1.cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
修改mysql配置文件
1.[client]
default-character-set=utf8
#客戶端字符集
#連接字符集
2.[ mysqld]
character-set-server = utf8
#服務器字符集wwww
#數據庫字符集
collation-server = utf8_general_ci
#服務器,庫,表的校驗字符集
#default-storage-engine=innodb
#把默認的表引擎改爲innodb
* 生成MySQL配置文件
Useradd mysql
Setfacl –m u:mysql:rwx –R /usr/local/mysql
Setfacl –m d:u:mysql:rwx –R /usr/local/mysql
* 用acl來讓mysql用戶對/usr/local/mysql有所有權限
/usr/local/mysql/bin/mysql_install_db --user=mysql
* 創建數據庫授權表
啓動MySQL服務
1.用原本源代碼的方式去使用和啓動mysql
/usr/local/mysql/bin/mysqld_safe --user=mysql &
2.重啓以後還要生效:
Vi /etc/rc.local
/usr/local/mysql/bin/mysqld_safe --user=mysql &
4./usr/local/mysql/bin/mysqladmin -uroot password kkk
#給mysql用戶root加密碼.密碼爲kkk
/usr/local/mysql/bin/mysql -u root -pkkk test
mysql>show databases;
mysql>use test
mysql>show tables;
#進入mysql以後用set來改密碼.
mysql> exit
登錄MySQL客戶端控制檯設置指定root密碼
5. 編譯安裝PHP(FastCGI模式)
tar zxvf php-5.2.14.tar.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
#解壓並打補丁,讓php支持fpm來方便管理php-cgi進程
cd php-5.2.14/
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /usr/local/php/etc/php.ini
cd ../
6.準備編譯安裝PHP5擴展模塊
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make
make install
cd ../
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
7. 修改php.ini文件,讓php模塊生效
cp /lnmp/php-5.2.14/php.ini-dist /usr/local/php/etc/php.ini
vi php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"
再查找output_buffering = Off
修改爲output_buffering = On
再查找; cgi.fix_pathinfo=0
修改爲cgi.fix_pathinfo=0,防止Nginx文件類型錯誤解析漏洞
8. 在php.ini中配置eAccelerator加速PHP
mkdir -p /usr/local/eaccelerator_cache
#準備eaccelerator緩存目錄
Vi php.ini
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
9.準備php-cgi和nginx進程執行者用戶
Useradd nginx
10. 創建php-fpm配置文件- php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
0
#0改成1,頁面上會輸出錯誤日誌
Unix user of processes
nginx
Unix group of processes
nginx
128
#最大子進程數128,如果內存小於2G,則64個最佳
65535
# Set open file desc rlimit,同時打開的文件數,linux系統允許同時打開的文件數爲1024,修改linux系統中允許同時打開的文件,ulimit -SHn 65535,而且這個參數重啓後還能生效,加到 /etc/profile全局配置文件的最後,開機就會生效,
ulimit -a查看open files 65535
1024
#最大請求數, How much requests each process should execute before respawn.一個子進程能夠迴應1042個請求
11. 啓動php-cgi(fastcgi)進程,監聽127.0.0.1的9000端口,進程數爲128(如果服務器內存小於3GB,可以只開啓64個進程),用戶爲nginx:
/usr/local/php/sbin/php-fpm start
#啓動php-cgi
/usr/local/php/sbin/php-fpm reload
#重新加載配置文件
/usr/local/php/sbin/php-fpm stop
#關閉php-fpm,此時nginx肯定不上php
12. 安裝Nginx所需的pcre庫
tar zxvf pcre-8.10.tar.gz
cd pcre-8.10/
./configure
make && make install
cd ../
13. 安裝Nginx
tar zxvf nginx-0.8.46.tar.gz
cd nginx-0.8.46/
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../
14. 修改Nginx配置文件
vi /usr/local/nginx/conf/nginx.conf
user nginx nginx;
worker_processes 8;
#相當於cpu個數
error_log logs/nginx_error.log
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80;
server_name blog.s135.com;
index index.html index.htm index.php;
root /data0/htdocs/blog;
#limit_conn crawler 20;
location ~ .*.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 1h;
}
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data1/logs/access.log access;
}
}
15. 在/usr/local/nginx/conf/目錄中fastcgi_params文件添加
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
16.配置開機啓動nginx,php-fpm,ulimit
1)nginx
Vi /etc/rc.local
/usr/local/nginx/sbin/nginx
2)php-fpm
Vi /etc/rc.local
/usr/local/php/sbin/php-fpm start
3)ulimit
Vi /etc/profile
Ulimit -SHn 65535
17.檢查nginx配置文件語句錯誤
/usr/local/nginx/sbin/nginx -t
18.平滑重啓nginx進程
1)Pkill -HUP nginx
2)kill -HUP `pgrep -uroot nginx`
3)/usr/local/nginx/sbin/nginx -s reload
(注意此處開啓cgi /usr/local/php/sbin/php-fpm start)
20.配置nginx虛擬主機
Vi /usr/local/nginx/conf/nginx.conf
==èwww.baidu.com公司網站
server
{
listen 80;
server_name www.baidu.com;
index index.html index.php index.htm;
root /web/baidu;
location ~ .*.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
#設置圖片在客戶端緩存時間爲30days
location ~ .*.(js|css)?$
{
expires 1h;
}
#設置js和css文件在客戶端的緩存時間爲1hour
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log logs/access.log access;
#自定義日誌區域
}
==èwww.sina.com公司網站
server
{
listen 80;
server_name www.sina.com;
index index.html index.php index.htm;
root /web/baidu;
location ~ .*.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
#設置圖片在客戶端緩存時間爲30days
location ~ .*.(js|css)?$
{
expires 1h;
}
#設置js和css文件在客戶端的緩存時間爲1hour
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log logs/access.log access;
#自定義日誌區域
}
最後在客戶端測試虛擬主機www.baidu.com和www.sina.com兩家公司網站
其他模塊安裝部分(環境不同 僅供參考)
TTsevser
(參考網址 http://www.cnblogs.com/kudosharry/articles/2261924.html)
entos 5.5 下安裝Tokyo 數據庫tokyocabinet-1.4.47 和 網絡接口tokyotyrant-1.1.41
需求:
實現一個高性能類似memcached 內存緩存,並可以持續化數據。
下載:
wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.47.tar.gz
wget http://fallabs.com/tokyotyrant/tokyotyrant-1.1.41.tar.gz
更新庫:
yum install bzip2-devel
安裝:
tar -zxvf tokyocabinet-1.4.47.tar.gz && cd tokyocabinet-1.4.47 && ./configure --prefix=/home/tc && make && make install
tar -zxvf tokyotyrant-1.1.41.tar.gz && cd tokyotyrant-1.1.41 && ./configure --prefix=/home/tt --with-tc=/home/tc && make && make install
軟鏈接下庫:
ln -s /home/tc/lib/libtokyocabinet.so.9 /lib/libtokyocabinet.so.9
啓動:(mkdir /ttserver)
cd /home/tt/bin/
./ttserver
或:
/home/tt/bin/ttserver -host 127.0.0.1 -port 1978 -thnum 8 -dmn -pid /ttserver/ttserver.pid -log /ttserver/ttserver.log -le -ulog /ttserver/ -ulim 128m -sid 1 -rts /ttserver/ttserver.rts /ttserver/database.tch
測試命令:
存儲:
curl -X PUT http://127.0.0.1:11211/my_key -d "this is value"
讀取:
curl http://127.0.0.1:11211/my_key
刪除:
curl -X DELETE http://127.0.0.1:11211/my_key
安裝php擴展 tokyo_tyrant
Webserver 相應目錄
--with-tokyo-tyrant 安裝目錄 相應改動
wget http://pecl.php.net/get/tokyo_tyrant-0.6.0.tgz
tar zxvf tokyo_tyrant-0.6.0.tgz
cd tokyo_tyrant-0.6.0
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-tokyo-tyrant=/usr/local/webserver/tt/ --with-tokyo-cabinet-dir=/usr/local/webserver/tc/
make
cd modules
cp tokyo_tyrant.so /usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/
vi /usr/local/webserver/php/etc/php.ini
extension = tokyo_tyrant.so記得重啓
Memcached
http://www.cnblogs.com/czh-liyu/archive/2010/04/27/1722084.html
http://blog.johntechinfo.com/technology/264