佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > Red Hat Enterprise Linux 4+Nginx 0.7.47+PHP5.2+MYSQL5.0+Memcache+eAccelerator收

Red Hat Enterprise Linux 4+Nginx 0.7.47+PHP5.2+MYSQL5.0+Memcache+eAccelerator收

熱門標(biāo)簽:電銷行業(yè) 記事本 客服熱線 回?fù)芟到y(tǒng) 外呼系統(tǒng) 客戶服務(wù) 銀行業(yè)務(wù) 分布式呼叫中心
安裝LINUX
1. 導(dǎo)航界面 【回車】
2. 是否將CD數(shù)據(jù)拷貝到磁盤上安裝 【跳過】
3. LINUX安裝界面 【下一步】
4. 選擇語言 【英文】
5. 鍵盤 【美國標(biāo)準(zhǔn)鍵盤】
6. 選擇類型 【自定義】
7. 磁盤分配 【自動分區(qū)】
8. 自動分區(qū) 【刪除所有分區(qū)】
9. 引導(dǎo)裝載 【下一步】
10. 網(wǎng)絡(luò)配置 【DHCP】
11. 選擇系統(tǒng)默認(rèn)語言 【英文】
12. 選擇時區(qū) 【北京】
13. 設(shè)置管理員密碼 【321321】
14. 選擇安裝包 LINUX開發(fā)工具,系統(tǒng)配置工具
15. 開始安裝


網(wǎng)絡(luò)配置
Netconfig 圖形界面設(shè)置網(wǎng)絡(luò),重啟network后生效。
網(wǎng)絡(luò)服務(wù)啟動腳本
/etc/init.d/network 從新啟動才能生效
擴(kuò)展:# /etc/rc.d/init.d/network start 啟動network
# /etc/rc.d/init.d/network stop 停止network
# /etc/rc.d/init.d/network restart 重啟network

# ifconfig eth0 down 停止eth0接口
# ifconfig eth0 up 開啟eth0接口

Ifdown 網(wǎng)絡(luò)接口名稱 停止某個網(wǎng)絡(luò)接口。
Ifup 網(wǎng)絡(luò)接口名稱 開啟某個網(wǎng)絡(luò)接口。


設(shè)置Ip
netcofnig
/etc/rc.d/init.d/network start
ifconfig eth0 up

設(shè)置防火墻
vi /etc/sysconfig/iptables
重啟防火墻
/etc/init.d/iptables restart
查看防火墻
/etc/init.d/iptables status

創(chuàng)建目錄
Mkdir /home/soft/
wget http://memcached.googlecode.com/files/memcached-1.2.7.tar.gz
wget http://apache.etoak.com/httpd/httpd-2.2.11.tar.gz
wget http://www.zlib.net/zlib-1.2.3.tar.gz
wget http://jaist.dl.sourceforge.net/sourceforge/libpng/libpng-1.4.0beta53.tar.gz
wget http://ftp.twaren.net/Unix/NonGNU/freetype/freetype-2.1.10.tar.gz
wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.17.tar.gz
wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
wget http://cn2.php.net/get/php-5.2.9.tar.gz/from/cn.php.net/mirror

安裝Mysql5.0.37

開始安裝和編譯代碼:
groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.0.37.tar.gz
cd mysql-5.0.37
./configure --prefix=/usr/local/webserver/mysql
make
make install
scripts/mysql_install_db
chown -R root:mysql /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql/var
chgrp -R mysql /usr/local/webserver/mysql
cp support-files/my-medium.cnf /etc/my.cnf
cp /usr/local/webserver/mysql/share/mysql/mysql.server /usr/local/webserver/mysql/share/mysql/mysqld
chmod a+x /usr/local/webserver/mysql/share/mysql/mysqld
mysqladmin -uroot password "321321"
啟動服務(wù)方法
/usr/local/webserver/mysql/share/mysql/mysqld start
停止服務(wù)方法
/usr/local/webserver/mysql/bin/mysqladmin shutdown

cp /usr/local/webserver/mysql/include/mysql/mysql.h /usr/local/webserver/mysql/

設(shè)置成開機(jī)自啟動
在/etc/rc.d/rc.local文件中加入一行
/usr/local/webserver/mysql/share/mysql/mysqld start
這樣每次重新啟動系統(tǒng)以后,mysql也會隨系統(tǒng)一起啟動.

安裝Memcache + libevent

tar zxvf libevent-1.4.9-stable.tar.gz
cd libevent-1.4.9-stable
./configure --prefix=/usr/ make make install
cd ../
tar zxvf memcached-1.2.7.tar.gz
cd memcached-1.2.7
./configure --prefix=/usr/local/server/memcached --with-libevent=/usr/ make make install
/usr/local/server/memcached/bin/memcached -l 192.168.8.1 -d -p 10000 -u nobody -m 128
cd ../



表示用 daemon 的方式啟動 memcached,監(jiān)聽在 192.168.8.1 的 10000 端口上,運(yùn)行用戶為 nobody,為其分配128MB 的內(nèi)存


安裝 PHP擴(kuò)展包

tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
make install
cd ../

tar zxvf libpng-1.4.0beta53.tar.gz
cd libpng-1.4.0beta53
cd scripts/
mv makefile.linux ../makefile
cd ../
make
make install
cd ../

tar zxvf freetype-2.1.10.tar.gz
cd freetype-2.1.10
./configure
make make install
cd ../

tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-shared
make
make test
mkdir /usr/local/man
mkdir /usr/local/man/man1
make install
cd ../

tar zxvf gettext-0.17.tar.gz
cd gettext-0.17
./configure --prefix=/usr
cp /usr/lib/libattr.* /lib/
make
make install
cd ../

tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --with-png --with-freetype --with-jpeg
make make install
cp gd.h /usr/
cd ../

tar zxvf libiconv-1.12.tar.gz
cd libiconv-1.12
./configure --prefix=/usr/local/iconv
make
make install
cd ../

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 ../../

tar zxvf mhash-0.9.9.tar.gz
cd mhash-0.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

tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../



安裝PHP

tar zxvf php-5.2.9.tar.gz
gzip -cd php-5.2.8-fpm-0.5.10.diff.gz | patch -d php-5.2.9 -p1
cd php-5.2.9
./configure --prefix=/usr/local/webserver/php --with-mysql=/usr/local/webserver/mysql --with-freetype --with-png --with-gd --with-jpeg --with-zlib --enable-magic-quotes --with-iconv --without-sqlite --with-mcrypt --with-iconv=/usr/local/iconv --without-pdo-sqlite --with-gettext=/usr --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mhash --enable-pcntl --enable-sockets --with-config-file-path=/usr/local/webserver/php/etc --disable-dom --disable-simplexml --enable-roxen-zts
make ZEND_EXTRA_LIBS='-liconv'
make install

cp php.ini-dist /usr/local/webserver/php/etc/php.ini

編譯安裝PHP5擴(kuò)展模塊

tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/usr/local/webserver/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../

tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-mysql=/usr/local/webserver/mysql
make
make install
cd ../

配置eAccelerator加速PHP
mkdir -p /usr/local/webserver/eaccelerator_cache

修改PHP.ini
vi /usr/local/webserver/php/etc/php.ini

手工修改:查找/usr/local/webserver/php/etc/php.ini中的extension_dir = "./"
  修改為extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
  并在此行后增加以下幾行,然后保存:
  extension = "memcache.so"
  extension = "pdo_mysql.so"

  再查找output_buffering = Off
  修改為output_buffering = On
按shift+g鍵跳到配置文件的最末尾,加上以下配置信息:
[eaccelerator]
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

修改配置文件
vi /etc/sysctl.conf
輸入以下內(nèi)容
kernel.shmmax = 134217728
然后執(zhí)行以下命令使配置生效
/sbin/sysctl -p

創(chuàng)建www用戶和組,虛擬主機(jī)使用的目錄:
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /data0/htdocs/www
chmod +w /data0/htdocs/www
chown -R www:www /data0/htdocs/www

創(chuàng)建php-fpm配置文件(php-fpm是為PHP打的一個FastCGI管理補(bǔ)丁,可以平滑變更php.ini配置而無需重啟php-cgi):
在/usr/local/webserver/php/etc/目錄中創(chuàng)建php-fpm.conf文件:

rm -f /usr/local/webserver/php/etc/php-fpm.conf
vi /usr/local/webserver/php/etc/php-fpm.conf

輸入以下內(nèi)容(如果您安裝 Nginx + PHP 用于程序調(diào)試,請將以下的value name="display_errors">0/value>改為value name="display_errors">1/value>,以便顯示PHP錯誤信息,否則,Nginx 會報狀態(tài)為500的空白錯誤頁):

?xml version="1.0" ?>
configuration>

All relative paths in this config are relative to php's install prefix

section name="global_options">

Pid file
value name="pid_file">/usr/local/webserver/php/logs/php-fpm.pid/value>

Error log file
value name="error_log">/usr/local/webserver/php/logs/php-fpm.log/value>

Log level
value name="log_level">notice/value>

When this amount of php processes exited with SIGSEGV or SIGBUS ...
value name="emergency_restart_threshold">10/value>

... in a less than this interval of time, a graceful restart will be initiated.
Useful to work around accidental curruptions in accelerator's shared memory.
value name="emergency_restart_interval">1m/value>

Time limit on waiting child's reaction on signals from master
value name="process_control_timeout">5s/value>

Set to 'no' to debug fpm
value name="daemonize">yes/value>

/section>

workers>

section name="pool">

Name of pool. Used in logs and stats.
value name="name">default/value>

Address to accept fastcgi requests on.
Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
value name="listen_address">127.0.0.1:9000/value>

value name="listen_options">

Set listen(2) backlog
value name="backlog">-1/value>

Set permissions for unix socket, if one used.
In Linux read/write permissions must be set in order to allow connections from web server.
Many BSD-derrived systems allow connections regardless of permissions.
value name="owner">/value>
value name="group">/value>
value name="mode">0666/value>
/value>

Additional php.ini defines, specific to this pool of workers.
value name="php_defines">
value name="sendmail_path">/usr/sbin/sendmail -t -i/value>
value name="display_errors">1/value>
/value>

Unix user of processes
value name="user">www/value>

Unix group of processes
value name="group">www/value>

Process manager settings
value name="pm">

Sets style of controling worker process count.
Valid values are 'static' and 'apache-like'
value name="style">static/value>

Sets the limit on the number of simultaneous requests that will be served.
Equivalent to Apache MaxClients directive.
Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
Used with any pm_style.
value name="max_children">128/value>

Settings group for 'apache-like' pm style
value name="apache_like">

Sets the number of server processes created on startup.
Used only when 'apache-like' pm_style is selected
value name="StartServers">20/value>

Sets the desired minimum number of idle server processes.
Used only when 'apache-like' pm_style is selected
value name="MinSpareServers">5/value>

Sets the desired maximum number of idle server processes.
Used only when 'apache-like' pm_style is selected
value name="MaxSpareServers">35/value>

/value>

/value>

The timeout (in seconds) for serving a single request after which the worker process will be terminated
Should be used when 'max_execution_time' ini option does not stop script execution for some reason
'0s' means 'off'
value name="request_terminate_timeout">0s/value>

The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
'0s' means 'off'
value name="request_slowlog_timeout">0s/value>

The log file for slow requests
value name="slowlog">logs/slow.log/value>

Set open file desc rlimit
value name="rlimit_files">51200/value>

Set max core size rlimit
value name="rlimit_core">0/value>

Chroot to this directory at the start, absolute path
value name="chroot">/value>

Chdir to this directory at the start, absolute path
value name="chdir">/value>

Redirect workers' stdout and stderr into main error log.
If not set, they will be redirected to /dev/null, according to FastCGI specs
value name="catch_workers_output">yes/value>

How much requests each process should execute before respawn.
Useful to work around memory leaks in 3rd party libraries.
For endless request processing please specify 0
Equivalent to PHP_FCGI_MAX_REQUESTS
value name="max_requests">500/value>

Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
Makes sense only with AF_INET listening socket.
value name="allowed_clients">127.0.0.1/value>

Pass environment variables like LD_LIBRARY_PATH
All $VARIABLEs are taken from current environment
value name="environment">
value name="HOSTNAME">$HOSTNAME/value>
value name="PATH">/usr/local/bin:/usr/bin:/bin/value>
value name="TMP">/tmp/value>
value name="TMPDIR">/tmp/value>
value name="TEMP">/tmp/value>
value name="OSTYPE">$OSTYPE/value>
value name="MACHTYPE">$MACHTYPE/value>
value name="MALLOC_CHECK_">2/value>
/value>

/section>

/workers>

/configuration>

啟動php-cgi進(jìn)程,監(jiān)聽127.0.0.1的9000端口,進(jìn)程數(shù)為200(如果服務(wù)器內(nèi)存小于3GB,可以只開啟64個進(jìn)程),用戶為www

ulimit -SHn 51200
/usr/local/webserver/php/sbin/php-fpm start




安裝Nginx 0.7.47

安裝Nginx所需的pcre庫:

tar zxvf pcre-7.8.tar.gz
cd pcre-7.8/
./configure
make make install
cd ../

tar zxvf nginx-0.7.47.tar.gz
cd nginx-0.7.47/
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --without-http_memcached_module --without-http_map_module --without-http_geo_module --without-http_autoindex_module --with-http_stub_status_module --with-http_ssl_module
make make install
cd ../

mkdir -p /data1/logs
chmod +w /data1/logs
chown -R www:www /data1/logs

rm -f /usr/local/webserver/nginx/conf/nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf

輸入以下內(nèi)容

user www www;

worker_processes 8;

error_log /data1/logs/nginx_error.log crit;

pid /usr/local/webserver/nginx/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
{
use epoll;
worker_connections 51200;
}

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 60;

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;
include fcgi.conf;
}

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;
}

server
{
listen 80;
server_name www.s135.com;
index index.html index.htm index.php;
root /data0/htdocs/www;

location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}

log_format wwwlogs '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data1/logs/wwwlogs.log wwwlogs;
}
}

在/usr/local/webserver/nginx/conf/目錄中創(chuàng)建fcgi.conf文件:

vi /usr/local/webserver/nginx/conf/fcgi.conf

輸入以下內(nèi)容

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

啟動Nginx

ulimit -SHn 51200
/usr/local/webserver/nginx/sbin/nginx

配置開機(jī)自動啟動Nginx + PHP
vi /etc/rc.local
在末尾增加以下內(nèi)容
ulimit -SHn 51200
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx

優(yōu)化Linux內(nèi)核參數(shù)
vi /etc/sysctl.conf

net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000

使配置立即生效
/sbin/sysctl -p

編寫每天定時切割Nginx日志的腳本
vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
增寫以下內(nèi)容
#!/bin/bash
# This script run at 00:00

# The Nginx logs path
logs_path="/usr/local/webserver/nginx/logs/"

mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`

設(shè)置crontab,每天凌晨00:00切割nginx訪問日志

crontab -e
輸入以下內(nèi)容
00 00 * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

標(biāo)簽:阿里 德州 公主嶺 廣東 濱州 拉薩 阜陽 綿陽

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Red Hat Enterprise Linux 4+Nginx 0.7.47+PHP5.2+MYSQL5.0+Memcache+eAccelerator收》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    盐源县| 赤水市| 麦盖提县| 平果县| 尖扎县| 怀集县| 浦东新区| 文登市| 张家口市| 丰台区| 无为县| 延吉市| 呼玛县| 余江县| 巴楚县| 云龙县| 海安县| 石台县| 铁岭市| 通海县| 石家庄市| 宜川县| 运城市| 博爱县| 乐至县| 顺平县| 高密市| 沂水县| 吉木萨尔县| 灌南县| 楚雄市| 洞头县| 富蕴县| 延川县| 柳林县| 琼结县| 海淀区| 南雄市| 襄垣县| 浮梁县| 水城县|