中文字幕理论片,69视频免费在线观看,亚洲成人app,国产1级毛片,刘涛最大尺度戏视频,欧美亚洲美女视频,2021韩国美女仙女屋vip视频

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
LNAMP+CentOS 6.0(64位)編譯安裝 CentOS 6.0 Apache2、PHP、MySQL、Nginx

LNAMP+CentOS 6.0(64位) 編譯安裝

本片內(nèi)容是早期根據(jù)網(wǎng)絡(luò)上收集的一些教程改造出來(lái)的,無(wú)論是當(dāng)初的參考教程,還是最后總結(jié)出來(lái)的這篇,都有各種問(wèn)題. 盡管最終問(wèn)題都一一解決,但是有感于網(wǎng)絡(luò)上關(guān)于LNAMP的配置教程魚(yú)龍混雜, 最終解決問(wèn)題的資料也就沒(méi)有發(fā)布上來(lái),因?yàn)槲乙矒?dān)心仍會(huì)干擾有迫切需求的用戶(hù).

所以,如果有問(wèn)題的話(huà),大家可以留言交流!

一、系統(tǒng)約定

軟件源代碼包存放位置 /usr/local/src

二、系統(tǒng)環(huán)境初始化

01. 檢查系統(tǒng)是否正常

1
2
3
4
5
6
# more /var/log/messages(檢查有無(wú)系統(tǒng)級(jí)錯(cuò)誤信息)
# dmesg (檢查硬件設(shè)備是否有錯(cuò)誤信息)
# cat /proc/cpuinfo (檢查CPU頻率是否正常)
# top (按1檢測(cè)CPU核數(shù)是否正常,內(nèi)存大小是否正常)
# ifconfig(檢查網(wǎng)卡設(shè)置是否正確)
# ping www.163.com (檢查網(wǎng)絡(luò)是否正常)

02. 關(guān)閉不需要的服務(wù)

命令:

1
# ntsysv

以下僅列出需要啟動(dòng)的服務(wù),未列出的服務(wù)一律推薦關(guān)閉:

atd
crond
irqbalance
microcode_ctl
network
sendmail
sshd
syslog

03.關(guān)閉SElinux

修改/etc/selinux/config文件中的SELINUX= 為 disabled
命令:

1
2
# vi /etc/selinux/config
:1,$s/SELINUX=enforcing/SELINUX=disabled/ge (vi的替換命令)

04.更換快速源:

1
2
3
4
5
# cd /etc/yum.repos.d/ (切換至yum.repos.d目錄)
# mv CentOS-Base.repo CentOS-Base.repo.old (將原有CentOS-Base.repo文件備份并重命名)
# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo (下載對(duì)應(yīng)版本的repo文件,注意區(qū)分64位和32位系統(tǒng))
# mv CentOS6-Base-163.repo CentOS-Base.repo (將下載好的文件重命名為CentOS-Base.repo)
# yum update (更新)

05.安裝 vi

1
# yum -y install vim-enhanced

06. 配置 vim

1
# vi /root/.bashrc

在 alias mv=’mv -i’ 下面添加一行:

1
alias vi='vim'

保存退出。

1
# echo 'syntax on' > /root/.vimrc

07.定時(shí)校正服務(wù)器時(shí)鐘,定時(shí)與中國(guó)國(guó)家授時(shí)中心授時(shí)服務(wù)器同步

1
# crontab –e

加入一行:(insertr命令)

1
*/30 * * * * ntpdate 210.72.145.44 > /dev/null 2>&1

08.刪除Centos 多余組件,并更新及添加LNAMP所需組件:

1
2
3
# cd /etc/yum.repos.d/
# yum -y remove httpd mysql php
# yum -y install gcc gcc-c++ bison patch lsof unzip mlocate flex wget automake gd cpp gettext readline-devel 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 libidn libidn-devel openldap openldap-devel openldap-clients openldap-servers nss_ldap expat-devel libtool libtool-ltdl-devel bison

安裝autoconf-2.61

01
02
03
04
05
06
07
08
09
10
cd /usr/local/src
autoconf-2.61
wget -c http://files.directadmin.com/services/custombuild/autoconf-2.61.tar.gz
tar -zxvf autoconf-2.61.tar.gz
cd autoconf-2.61
./configure --prefix=/usr
make
make install
export PHP_AUTOCONF=/usr/bin/autoconf
export PHP_AUTOHEADER=/usr/bin/autoheader

09.關(guān)閉selinux:

1
/usr/sbin/setenforce 0   //立刻關(guān)閉 SELINUX,1為開(kāi)啟

10.增加系統(tǒng)默認(rèn)啟動(dòng):

1
echo "/usr/sbin/setenforce 0" >> /etc/rc.local

11. 重新啟動(dòng)

1
# init 6

12. 下載程序包

請(qǐng)到各程序官方網(wǎng)站下載最新的穩(wěn)定版本存放到/usr/local/src/目錄
此次LNAMP包含了:
Apache2、PHP、MySQL、Nginx四個(gè)主要程序。

命令:

1
cd /usr/local/src

Apache-2.4.2:

1
2
wget -c https://lnamp-web-server.googlecode.com/files/httpd-2.4.2.tar.gz
wget -c https://lnamp-web-server.googlecode.com/files/httpd-2.4.2-deps.tar.gz

PHP-5.4.2:

1
wget -c https://lnamp-web-server.googlecode.com/files/php-5.4.2.tar.gz

MySQL-5.5.24:

1
wget -c https://lnamp-web-server.googlecode.com/files/mysql-5.5.24.tar.tar.gz

Nginx-1.2.0:

1
wget -c https://lnamp-web-server.googlecode.com/files/nginx-1.2.0.tar.gz

其他所需組件:

php5-mail-header.patch(php補(bǔ)丁,有助于防止郵件發(fā)送被濫用)

1
wget -c http://www.lancs.ac.uk/~steveb/patches/php-mail-header-patch/php5-mail-header.patch

ioncube_loaders_lin_x86-64

1
wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.bz2

pcre

1
wget -c https://lnamp-web-server.googlecode.com/files/pcre-8.30.tar.gz

字符轉(zhuǎn)換庫(kù)libiconv

1
wget -c http://lnamp-web-server.googlecode.com/files/libiconv-1.14.tar.gz

libmcrypt

1
2
wget -c  http://lnamp-web-server.googlecode.com/files/libmcrypt-2.5.8.tar.gz
wget -c http://lnamp-web-server.googlecode.com/files/mcrypt-2.6.8.tar.gz

mhash

1
wget -c http://lnamp-web-server.googlecode.com/files/mhash-0.9.9.9.tar.gz

phpMyAdmin
wget -c http://lnamp-web-server.googlecode.com/files/phpMyAdmin-3.4.2-all-languages.zip

gd

1
wget -c http://lnamp-web-server.googlecode.com/files/gd-2.0.35.tar.gz

將eaccelerator換成xcache(xcache 2.0支持php 5.4)

1
wget http://xcache.lighttpd.net/pub/Releases/2.0.0/xcache-2.0.0.tar.gz

ImageMagick

1
wget -c https://lnamp-web-server.googlecode.com/files/ImageMagick-6.7.7.tar.gz

imagick

1
wget -c https://lnamp-web-server.googlecode.com/files/imagick-3.1.0RC1.tgz

PHP的memcache擴(kuò)展

1
2
3
4
5
wget -c https://lnamp-web-server.googlecode.com/files/memcache-3.0.6.tgz
wget -c http://launchpad.net/libmemcached/1.0/1.0.2/+download/libmemcached-1.0.2.tar.gz
wget -c http://pecl.php.net/get/memcached-2.0.1.tgz

memcached緩存

1
wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz

libevent

1
wget https://github.com/downloads/libevent/libevent/libevent-2.0.18-stable.tar.gz

PDO_MYSQL

1
wget https://lnamp-web-server.googlecode.com/files/PDO_MYSQL-1.0.2.tgz

cmake

1
wget -c http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz

rpaf模塊(該模塊用于apache做后端時(shí)獲取訪(fǎng)客真實(shí)的IP)

1
wget -c http://lnamp-web-server.googlecode.com/files/mod_rpaf-0.6.tar.gz

Tcmalloc(優(yōu)化nginx、mysql)
64位操作系統(tǒng)請(qǐng)先安裝 libunwind庫(kù),32位操作系統(tǒng)不要安裝。libunwind庫(kù)為基于64位CPU和操作系統(tǒng)的程序提供了基本的堆棧輾轉(zhuǎn)開(kāi)解功能,其中包括用于輸出堆棧跟蹤的API、用于以編程方式輾轉(zhuǎn)開(kāi)解堆棧的API以及支持C++異常處理機(jī)制的API

1
2
wget http://mirror.yongbok.net/nongnu/libunwind/libunwind-1.0.1.tar.gz
wget http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz

三、安裝MySQL

創(chuàng)建用戶(hù)、組和目錄

1
2
3
4
5
6
/usr/sbin/groupadd mysql  #注釋?zhuān)簞?chuàng)建mysql用戶(hù)組
/usr/sbin/useradd -g mysql mysql -s /sbin/nologin  #注釋?zhuān)簽閙ysql用戶(hù)組添加mysql用戶(hù)
mkdir /usr/local/software/mysql  #注釋?zhuān)簞?chuàng)建安裝目錄
mkdir -p /home/data/mysql/{data,binlog,relaylog,mysql}  #注釋?zhuān)簞?chuàng)建數(shù)據(jù)倉(cāng)庫(kù)目錄。注釋?zhuān)?p 為parents的縮寫(xiě),意思是創(chuàng)建所有遺失的父目錄
chown -R mysql:mysql /home/data/mysql #注釋?zhuān)?將 /home/data/mysql 及其子目錄下所有文件的屬主和屬組更改為mysql:mysql#

#使用Tcmalloc 優(yōu)化nginx、mysql
#64位操作系統(tǒng)請(qǐng)先安裝 libunwind庫(kù),32位操作系統(tǒng)不要安裝。libunwind庫(kù)為基于64位CPU和操作系統(tǒng)的程序提供了基本的堆棧輾轉(zhuǎn)開(kāi)解功能,其中包括用于輸出堆棧跟蹤的API、用于以編程方式輾轉(zhuǎn)開(kāi)解堆棧的API以及支持C++異常處理機(jī)制的API

安裝libunwind

1
2
3
4
5
6
cd /usr/local/src/package
tar -zxvf libunwind-1.0.1.tar.gz
cd libunwind-1.0.1
./configure  --prefix=/usr/local/software/libunwind  #注釋?zhuān)褐付ò惭b目錄為libunwind
make;make install
ln -s /usr/local/software/libunwind/lib/libunwind.so.8 /usr/lib64/

安裝gperftools

1
2
3
4
5
6
7
8
cd ../
tar -zxvf gperftools-2.0.tar.gz
cd gperftools-2.0
./configure  --prefix=/usr/local/software/gperftools --enable-frame-pointers    #注釋?zhuān)?4位系統(tǒng)必須添加:--enable-frame-pointers
make;make install
echo "/usr/local/software/gperftools/lib" > /etc/ld.so.conf.d/usr_local_lib.conf #注釋?zhuān)涸谖募sr_local_lib.conf中添加這句:/usr/local/software/gperftools/lib
/sbin/ldconfig
cd ../

ldconfig命令的用途,主要是在默認(rèn)搜尋目錄(/lib和/usr/lib)以及動(dòng)態(tài)庫(kù)配置文件/etc/ld.so.conf內(nèi)所列的目錄下,搜索出可共享的動(dòng)態(tài)鏈接庫(kù)(格式如前介紹,lib*.so*),進(jìn)而創(chuàng)建出動(dòng)態(tài)裝入程序(ld.so)所需的連接和緩存文件.緩存文件默認(rèn)為/etc/ld.so.cache,此文件保存已排好序的動(dòng)態(tài)鏈接庫(kù)名字列表.
ldconfig通常在系統(tǒng)啟動(dòng)時(shí)運(yùn)行,而當(dāng)用戶(hù)安裝了一個(gè)新的動(dòng)態(tài)鏈接庫(kù)時(shí),就需要手工運(yùn)行這個(gè)命令.

安裝cmake

1
2
3
4
5
6
7
tar -zxvf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./bootstrap --prefix=/usr/local/software/cmake
gmake
gmake install
export PATH=/usr/local/software/cmake/bin:$PATH
cd ../

安裝mysql

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
cd /usr/local/src
tar -zxvf mysql-5.5.24.tar.tar.gz
cd mysql-5.5.24/
rm -rf CMakeCache.txt
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/software/mysql \
-DMYSQL_UNIX_ADDR=/home/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/home/data/mysql/data \
-DMYSQL_TCP_PORT=3306

#注釋?zhuān)喝绻麍?bào)錯(cuò)沒(méi)有找到cmake,那么再重新安裝一次cmake
#注釋?zhuān)?br>-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ —這個(gè)是指定mysql服務(wù)器啟動(dòng)后,聯(lián)機(jī)套接字文件所處的位置和文件名
-DDEFAULT_CHARSET=utf8 \ —–使用 utf8 字符
-DWITH_EXTRA_CHARSETS=all \ —— 校驗(yàn)字符
-DWITH_MYISAM_STORAGE_ENGINE=1 \ ——-安裝 myisam 存儲(chǔ)引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ —-安裝 innodb 存儲(chǔ)引擎
-DENABLED_LOCAL_INFILE=1 \ —-安裝數(shù)據(jù)庫(kù)分區(qū))

1
make;make install
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
chmod +w /usr/local/software/mysql   #注釋?zhuān)盒薷膍ysql文件的權(quán)限
chown -R mysql:mysql /usr/local/software/mysql  #注釋?zhuān)盒薷奈募乃姓邽閙ysql用戶(hù)
ln -s /usr/local/software/mysql/bin/mysql /sbin/mysql  #注釋?zhuān)涸O(shè)置軟連接使mysql的bin命令能在shell中直接運(yùn)行
ln -s /usr/local/software/mysql/bin/mysqladmin /sbin/mysqladmin #注釋?zhuān)涸O(shè)置軟連接使mysqladmin的bin命令能在shell中直接運(yùn)行
ln -s /usr/local/software/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
1
#編輯mysql配置文件
cp /usr/local/software/mysql/support-files/my-medium.cnf /etc/my.cn  #注釋?zhuān)嚎截惻渲梦募?etc目錄下并命名為my.cn
然后將“l(fā)og-bin=mysql-bin”和“binlog_format=mixed”前添加“#”,以取消臃腫的log-bin記錄 (注釋?zhuān)焊鶕?jù)需要設(shè)置)
skip-locking 修改為 skip-external-locking
<strong>#注釋?zhuān)涸谡归_(kāi)的源碼包目錄中的“support-files”文件夾下,提供了多個(gè)MySQL服務(wù)器的配置文件,分別適用于不同負(fù)載的數(shù)據(jù)庫(kù)服務(wù)器,一般選擇my-medium.cnf文件即可,該配置文件適用于中等負(fù)載的數(shù)據(jù)庫(kù),可以滿(mǎn)足大多數(shù)企業(yè)的應(yīng)有需求。</strong>
#或者直接操作創(chuàng)建該文件:
1
cat >> /etc/my.cnf <<EOF
[client]
port    = 3306
socket  = /home/data/mysql/mysql.sock
[mysqld]
character_set_server = utf8
collation-server = utf8_general_ci
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user    = mysql
port    = 3306
socket  = /home/data/mysql/mysql.sock
basedir = /usr/local/software/mysql
datadir = /home/data/mysql/data
log-error = /home/data/mysql/mysql_error.log
pid-file = /home/data/mysql/mysql.pid
open_files_limit    = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 512
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 6M
join_buffer_size = 8M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 256K
transaction_isolation = READ-COMMITTED
tmp_table_size = 256M
max_heap_table_size = 256M
long_query_time = 3
log-slave-updates
log-bin = /home/data/mysql/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 100M
relay-log-index = /home/data/mysql/relaylog/relaylog
relay-log-info-file = /home/data/mysql/relaylog/relaylog
relay-log = /home/data/mysql/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 384M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
skip_external_locking
skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
#master-host     =   192.168.1.2
#master-user     =   username
#master-password =   password
#master-port     =  3306
server-id = 1
skip-innodb
#log-slow-queries = /home/data/mysql/slow.log
#long_query_time = 10
[mysqldump]
quick
max_allowed_packet = 32M
EOF

#初始化mysql

1
/usr/local/software/mysql/scripts/mysql_install_db --basedir=/usr/local/software/mysql --datadir=/home/data/mysql/data --user=mysql

#利用TCMalloc提高mysql在高并發(fā)下的性能

1
vi /usr/local/software/mysql/bin/mysqld_safe

#在# executing mysqld_safe的下一行,加上:

1
export LD_PRELOAD=/usr/local/software/gperftools/lib/libtcmalloc.so

#或者通sed添加

1
sed -i '/# executing mysqld_safe/a\export LD_PRELOAD=/usr/local/lib/libtcmalloc.so' /usr/local/software/mysql/bin/mysqld_safe

#設(shè)置mysql啟動(dòng)文件

1
cp support-files/mysql.server /etc/rc.d/init.d/mysqld

#修改啟動(dòng)腳本:添加basedir以及datadir的路徑:

1
2
3
vi /etc/rc.d/init.d/mysqld
basedir=/usr/local/software/mysql
datadir=/home/data/mysql/data

#或者通sed修改

1
2
sed -i '46 s#basedir=#basedir=/usr/local/software/mysql#'  /etc/rc.d/init.d/mysqld
sed -i '47 s#datadir=#datadir=/home/data/mysql/data#'  /etc/rc.d/init.d/mysqld

#修改啟動(dòng)腳本的權(quán)限:

1
chmod 700 /etc/rc.d/init.d/mysqld

啟動(dòng)MySQL數(shù)據(jù)庫(kù)

1
/etc/rc.d/init.d/mysqld start

#檢查數(shù)據(jù)庫(kù)的默認(rèn)偵聽(tīng)端口 3306是否開(kāi)啟:

1
netstat -lnpt

#使用lsof命令查看tcmalloc是否起效

1
/usr/sbin/lsof -n | grep tcmalloc

如果發(fā)現(xiàn)以下信息,說(shuō)明tcmalloc已經(jīng)起效:

1
mysqld 10847 mysql mem REG 8,5 1203756 20484960 /usr/local/lib/libtcmalloc.so.0.0.0

#設(shè)置mysql開(kāi)機(jī)啟動(dòng)

1
2
/sbin/chkconfig --add mysqld
/sbin/chkconfig --level 2345 mysqld on

#設(shè)置root密碼(9527)

1
/sbin/mysqladmin -u root password 9527

#配置庫(kù)文件搜索路徑

1
2
echo "/usr/local/software/mysql/lib" >>/etc/ld.so.conf
/sbin/ldconfig

#添加/usr/local/software/mysql/bin到環(huán)境變量PATH中

1
2
echo "export PATH=$PATH:/usr/local/software/mysql/bin" >> /etc/profile
source /etc/profile

#添加mysql管理帳戶(hù)

01
02
03
04
05
06
07
08
09
10
11
12
mysql -h localhost -u root -p
msqyl> use mysql;
msqyl> grant all on *.* to 'guodegang'@'localhost' identified by '9527';#創(chuàng)建用戶(hù)
mysql>flush privileges;               #刷新mysql的緩存,讓以上設(shè)置立即生效
mysql>select Host,User,Password,Select_priv,Grant_priv from user; #顯示所有用戶(hù)
mysql>delete from user where user='';                  #刪除user用戶(hù)
mysql>delete from user where password='';               #刪除user用戶(hù)
mysql>delete from user where host='';                     #刪除user用戶(hù)
mysql>drop database test;             #刪除默認(rèn)的test數(shù)據(jù)庫(kù)
mysql>flush privileges;               #刷新mysql的緩存,讓以上設(shè)置立即生效
# msqyl> exit; #退出

#重啟Mysql,使上述設(shè)置生效:

1
2
/etc/rc.d/init.d/mysqld restart (直接啟動(dòng))
service mysqld restart (快捷啟動(dòng))

四.安裝apache 2.4.2:

1
2
3
4
5
6
7
8
/usr/sbin/groupadd www  #注釋?zhuān)簞?chuàng)建www用戶(hù)組
/usr/sbin/useradd -g www www -s /sbin/nologin  #注釋?zhuān)簽閣ww 用戶(hù)組添加www 用戶(hù)
mkdir -p /home/wwwroot/mainsite  #創(chuàng)建站點(diǎn)目錄
chown -R www:www /home/wwwroot/mainsite  #mainsite為某一站點(diǎn)目錄
mkdir -p /home/data/logs/mainsite #創(chuàng)建站點(diǎn)日志目錄
chown -R www:www /home/data/logs/mainsite #logs/mainsite為某一站點(diǎn)日志

 

#安裝pcre

1
2
3
4
5
6
cd /usr/local/src
tar -zxvf pcre-8.30.tar.gz
cd pcre-8.30
./configure --prefix=/usr/local/pcre
make;make install
cd ../

 

#apache分為兩個(gè)包

1
2
3
tar -zxvf httpd-2.4.2.tar.gz
tar -zxvf httpd-2.4.2-deps.tar.gz
cd  httpd-2.4.2

#隱藏apache版本信息

1
2
sed -i 's/#define AP_SERVER_BASEPRODUCT "Apache"/#define AP_SERVER_BASEPRODUCT "Microsoft-IIS 5.0"/' include/ap_release.h
sed -i 's/#define PLATFORM "Unix"/#define PLATFORM "win32"/' os/unix/os.h

#開(kāi)始編譯apache

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
./configure --prefix=/usr/local/apache \
--enable-deflate \
--enable-headers \
--enable-mime-magic \
--enable-proxy \
--enable-ssl \
--enable-so \
--enable-rewrite \
--enable-suexec \
--with-suexec-bin=/usr/sbin/suexec \
--with-suexec-caller=www \
--with-pcre=/usr/local/pcre/bin/pcre-config \
--with-mpm=prefork \
--with-ssl=/usr
make;make install

#make的時(shí)候報(bào)錯(cuò),“/usr/lib/libexpat.so: could not read symbols: File in wrong format”
#解決方法:

1
\cp /usr/lib64/libexpat.* /usr/lib/

#配置自啟動(dòng)文件

01
02
03
04
05
06
07
08
09
10
11
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
#在首行#!/bin/sh下添加
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache/logs/httpd.pid
# config: /usr/local/apache/conf/httpd.conf

#或者直接使用sed添加

1
sed -i '/#!\/bin\/sh/a\# chkconfig: - 85 15\n# description: web server\n# processname: httpd\n# pidfile: /usr/local/apache/logs/httpd.pid\n# config: /usr/local/apache/conf/httpd.conf' /etc/init.d/httpd

#修改apache配置文件

1
2
cd /usr/local/apache/conf/
mv httpd.conf httpd.conf.bak  #備份httpd.conf文件

 

#創(chuàng)建apache配置httpd.conf文件

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
cat >> httpd.conf <<EOF
ServerRoot "/usr/local/apache"
Listen 81
Timeout 300
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 5
UseCanonicalName Off
AccessFileName .htaccess
TraceEnable Off
ServerTokens ProductOnly
FileETag None
ServerSignature Off
HostnameLookups Off
# LoadModule foo_module modules/mod_foo.so
#
LoadModule authn_file_module modules/mod_authn_file.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
#LoadModule authn_anon_module modules/mod_authn_anon.so
#LoadModule authn_dbd_module modules/mod_authn_dbd.so
#LoadModule authn_socache_module modules/mod_authn_socache.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
#LoadModule authz_owner_module modules/mod_authz_owner.so
#LoadModule authz_dbd_module modules/mod_authz_dbd.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
#LoadModule auth_form_module modules/mod_auth_form.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule allowmethods_module modules/mod_allowmethods.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule cache_module modules/mod_cache.so
#LoadModule cache_disk_module modules/mod_cache_disk.so
#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
#LoadModule socache_dbm_module modules/mod_socache_dbm.so
#LoadModule socache_memcache_module modules/mod_socache_memcache.so
#LoadModule dbd_module modules/mod_dbd.so
#LoadModule dumpio_module modules/mod_dumpio.so
#LoadModule buffer_module modules/mod_buffer.so
#LoadModule ratelimit_module modules/mod_ratelimit.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
#LoadModule ext_filter_module modules/mod_ext_filter.so
#LoadModule request_module modules/mod_request.so
#LoadModule include_module modules/mod_include.so
LoadModule filter_module modules/mod_filter.so
#LoadModule substitute_module modules/mod_substitute.so
#LoadModule sed_module modules/mod_sed.so
#LoadModule deflate_module modules/mod_deflate.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
#LoadModule log_debug_module modules/mod_log_debug.so
#LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
#LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
#LoadModule remoteip_module modules/mod_remoteip.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_express_module modules/mod_proxy_express.so
#LoadModule session_module modules/mod_session.so
#LoadModule session_cookie_module modules/mod_session_cookie.so
#LoadModule session_dbd_module modules/mod_session_dbd.so
#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
#LoadModule ssl_module modules/mod_ssl.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so
LoadModule unixd_module modules/mod_unixd.so
#LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
#LoadModule info_module modules/mod_info.so
#LoadModule suexec_module modules/mod_suexec.so
#LoadModule cgi_module modules/mod_cgi.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
#LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
#LoadModule actions_module modules/mod_actions.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
<IfModule unixd_module>
User www
Group www
</IfModule>
ServerAdmin king_819@163.com
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/usr/local/apache/htdocs"
<Directory "/usr/local/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
  LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
</IfModule>
<IfModule cgid_module>
#Scriptsock logs/cgisock
</IfModule>
<Directory "/usr/local/apache/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
RewriteEngine on
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php .php3 .php4 .php5 .php6
AddType application/x-httpd-php-source .phps
</IfModule>
# Server-pool management (MPM specific)
Include conf/extra/httpd-mpm.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# Configure mod_proxy_html to understand HTML4/XHTML1
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
# Secure (SSL/TLS) connections
#Include conf/extra/httpd-ssl.conf
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
EOF

#配置mpm_prefork_module

01
02
03
04
05
06
07
08
09
10
11
mv extra/httpd-mpm.conf extra/httpd-mpm.conf.bak
cat >> extra/httpd-mpm.conf <<EOF
<IfModule mpm_prefork_module>
    ServerLimit   10000
    StartServers  5
    MinSpareServers  5
    MaxSpareServers  10
    MaxRequestWorkers  10000
    MaxConnectionsPerChild 10000
</IfModule>
EOF

#配置虛擬主機(jī)(目錄指到/usr/local/apache/htdocs)

1
mv extra/httpd-vhosts.conf extra/httpd-vhosts.conf.bak

 

01
02
03
04
05
06
07
08
09
10
11
12
13
cat >> extra/httpd-vhosts.conf <<EOF
#Vhosts
<VirtualHost *:81>
    ServerAdmin aiwei.us@gmail.com
    DocumentRoot "/usr/local/apache/htdocs"
<Directory "/usr/local/apache/htdocs">
      Options Indexes FollowSymLinks
      AllowOverride None
      Require all granted
</Directory>
    ServerName 127.0.0.1
</VirtualHost>
EOF

#設(shè)置apache自啟動(dòng)

1
2
3
4
5
chmod 700 /etc/init.d/httpd
/etc/init.d/httpd start
/sbin/chkconfig --add httpd
/sbin/chkconfig --level 2345 httpd on
cd ../

五、安裝PHP 5.4.2

#編譯安裝相關(guān)支持庫(kù)

libiconv

1
2
3
4
5
6
7
cd /usr/local/src
tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14/
./configure
make;make install
/sbin/ldconfig
cd ../

建立libiconv庫(kù)的軟鏈接:
#64位系統(tǒng)使用

1
2
ln -sf /usr/local/lib/libiconv.so.2 /usr/lib64/libiconv.so.2
/sbin/ldconfig

libmcrypt

1
2
3
4
5
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make;make install
/sbin/ldconfig

 

1
2
3
cd libltdl/
./configure --enable-ltdl-install
make;make install

建立libmcrypt庫(kù)的軟鏈接:
#64位系統(tǒng)使用

1
2
3
4
5
6
ln -sf /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
ln -sf /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
ln -sf /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
ln -sf /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
ln -sf /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
ldconfig

安裝mhash

1
2
3
4
5
6
cd /usr/local/src
tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make;make install
/sbin/ldconfig

建立libmhash相關(guān)的軟鏈接:
#64位系統(tǒng)使用

1
2
3
4
5
6
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
ldconfig

安裝mcrypt

1
2
3
4
5
6
cd /usr/local/src
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make;make install

編譯php

這里我們?yōu)閜hp打入補(bǔ)丁.有助于防止郵件發(fā)送被濫用(多用戶(hù))以及在郵件中提供有價(jià)值的信息.補(bǔ)丁介紹信息請(qǐng)點(diǎn)擊:http://www.lancs.ac.uk/~steveb/patches/php-mail-header-patch/

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
cd /usr/local/src/
tar -zxvf php-5.4.2.tar.gz
patch -d php-5.4.2 -p1 < php5-mail-header.patch
cd php-5.4.2
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-apxs2=/usr/local/apache/bin/apxs \
--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-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--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

#如果報(bào)錯(cuò)誤:configure: error: Cannot find ldap libraries in /usr/lib
先執(zhí)行:

1
cp -frp /usr/lib64/libldap* /usr/lib/

再繼續(xù)./configure…… …..

1
2
3
4
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/php/etc/php.ini
cd ../

安裝php擴(kuò)展模塊

1
2
3
4
5
6
7
8
cd /usr/local/src
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 --with-zlib-dir --enable-memcache
make;make install
make test
cd ../

memcached擴(kuò)展
#php的擴(kuò)展memcache,不支持cas,所以我們要裝memcached擴(kuò)展,memcached擴(kuò)展是基于libmemcached,所以要先安裝libmemcached
#安裝memcached的服務(wù)端支持庫(kù)

1
2
3
4
5
6
cd /usr/local/src
tar -zxvf libevent-2.0.18-stable.tar.gz
cd libevent-2.0.18-stable
./configure
make;make install
ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib

#安裝Memcached服務(wù)端

1
2
3
4
5
cd /usr/local/src
tar -zxvf memcached-1.4.13.tar.gz
cd memcached-1.4.13
./configure --prefix=/usr/local/memcached --with-libevent=/usr
make;make install

#安裝libmemcached

1
2
3
4
5
cd /usr/local/src
tar -zxvf libmemcached-1.0.2.tar.gz
cd libmemcached-1.0.2
./configure --prefix=/usr/local/libmemcached  --with-memcached
make;make install

#安裝php的memcached擴(kuò)展庫(kù)

1
2
3
4
5
6
cd /usr/local/src
tar -zxvf memcached-2.0.1.tgz
cd memcached-2.0.1
/usr/local/php/bin/phpize
./configure --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --with-memcached --with-zlib
make;make install

#因eaccelerator-0.9.6.1不支持php 5.4.0,所以就改用XCache 2.0.0

1
2
3
4
5
6
cd /usr/local/src
tar -zxvf xcache-2.0.0.tar.gz
cd xcache-2.0.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make;make install
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
cat >> /usr/local/php/etc/php.ini <<EOF
[xcache-common]
extension = xcache.so
[xcache]
xcache.shm_scheme =        "mmap"
xcache.size  =               256M
xcache.count =                 8
xcache.slots =                8K
xcache.ttl   =                 0
xcache.gc_interval =           0
xcache.var_size  =            8M
xcache.var_count =             8
xcache.var_slots =            8K
xcache.var_ttl   =             0
xcache.var_maxttl   =          0
xcache.var_gc_interval =     300
xcache.test =                Off
xcache.readonly_protection = Off
xcache.mmap_path =    "/dev/zero"
xcache.coredump_directory =   ""
xcache.cacher =               On
xcache.stat   =               On
xcache.optimizer =           Off
[xcache.coverager]
xcache.coverager =          Off
xcache.coveragedump_directory = ""
EOF

#安裝pdo擴(kuò)展

1
2
3
4
5
6
7
cd /usr/local/src
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 ../

#安裝ImageMagick

1
2
3
4
5
cd /usr/local/src
tar -zxvf ImageMagick-6.7.7.tar.gz
cd ImageMagick-6.7.7-0
./configure --prefix=/usr/local/imagemagick
make;make install

 

#imagick最新正式版為imagick-3.0.1.tgz,但imagick-3.0.1.tgz在make的時(shí)候會(huì)出現(xiàn)大量的報(bào)錯(cuò)信息,所以就改用imagick-3.1.0RC1.tgz

1
2
3
4
5
6
cd /usr/local/src
tar -zxvf imagick-3.1.0RC1.tgz
cd imagick-3.1.0RC1/
export  PKG_CONFIG_PATH=/usr/local/imagemagick/lib/pkgconfig
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick
1
2
3
4
5
cd /usr/local/src
tar -jxf ioncube_loaders_lin_x86-64.tar.bz2
cd ioncube
mkdir /usr/local/ioncube
mv ioncube_loader_lin_5.2.so /usr/local/ioncube/

#修改php.ini添加php擴(kuò)展

1
2
sed -i 's#; extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20100525/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\nextension = "memcached.so"\nextension = "imagick.so"\n#' /usr/local/php/etc/php.ini
sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/software/php/etc/php.ini

 

#隱藏php版本

1
sed -i 's#expose_php = On#expose_php = Off#' /usr/local/php/etc/php.ini

#php安全設(shè)置,禁用函數(shù)

1
sed -i 's#disable_functions =#disable_functions =phpinfo,exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source#' /usr/local/php/etc/php.ini

#重啟apache,查看php擴(kuò)展加載的情況

1
/etc/init.d/httpd restart

安裝 Nginx

1
2
3
4
5
6
7
cd /usr/local/src
tar -zxvf nginx-1.2.0.tar.gz
cd nginx-1.2.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-pcre=/usr/local/src/pcre-8.30 --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-google_perftools_module
make;make install
cd ../

Nginx部分的配置文件需根據(jù)實(shí)際自身的實(shí)際情況設(shè)置,比如web目錄等.所以,下文僅供參考

#添加nginx啟動(dòng)腳本

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
cat >> /etc/init.d/nginx <<EOF
#! /bin/sh
ulimit -n 65535
# Description: Startup script for nginx
# chkconfig: 2345 55 25
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
 $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
 kill -QUIT `cat $PIDFILE` || echo -n "nginx not running"
}
do_reload() {
 kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}
case "$1" in
 start)
 echo -n "Starting $DESC: $NAME"
 do_start
 echo "."
 /etc/init.d/httpd start
 ;;
 stop)
 echo -n "Stopping $DESC: $NAME"
 do_stop
 echo "."
 /etc/init.d/httpd stop
 ;;
 reload)
 echo -n "Reloading $DESC configuration..."
 do_reload
 echo "."
 /etc/init.d/httpd restart
 ;;
 restart)
 echo -n "Restarting $DESC: $NAME"
 do_stop
 sleep 1
 do_start
 echo "."
 /etc/init.d/httpd restart
 ;;
 *)
 echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
 exit 3
 ;;
esac
exit 0
EOF

#添加nginx配置文件

1
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

 

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
cat >> /usr/local/nginx/conf/nginx.conf <<EOF
user  www www;
worker_processes 8;
error_log  /usr/local/nginx/logs/nginx_error.log  crit;
pid        /usr/local/nginx/logs/nginx.pid;
#使用Tcmalloc優(yōu)化nginx性能
google_perftools_profiles /var/tmp/tcmalloc;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
#工作模式及連接數(shù)上限
events
{
use epoll;
worker_connections 65535;
}
#設(shè)定http服務(wù)器,利用它的反向代理功能提供負(fù)載均衡支持
http
{
  #設(shè)定mime類(lèi)型
  include       mime.types;
  default_type  application/octet-stream;
  #charset  gb2312;
  #設(shè)定請(qǐng)求緩沖
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 30m;
  sendfile on;
  tcp_nopush     on;
  keepalive_timeout 60;
  tcp_nodelay on;
  server_tokens off;
  client_body_buffer_size 512k;
  proxy_connect_timeout   5;
  proxy_send_timeout      60;
  proxy_read_timeout      5;
  proxy_buffer_size       16k;
  proxy_buffers           4 64k;
  proxy_busy_buffers_size 128k;
  proxy_temp_file_write_size 128k;
  #  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.1;
  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;
  #定義訪(fǎng)問(wèn)日志的寫(xiě)入格式
  log_format  wwwlog  '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
  log_format  bbslog  '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
  ###禁止通過(guò)ip訪(fǎng)問(wèn)站點(diǎn)
   server{
server_name _;
return 404;
  }
  server
  {
listen       80;
server_name  www.kerry.com;
index index.html index.htm index.php;#設(shè)定訪(fǎng)問(wèn)的默認(rèn)首頁(yè)地址
root  /data/www/kerry;#設(shè)定網(wǎng)站的資源存放路徑
#limit_conn   crawler  20;
if (-d $request_filename)
{
  rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
#所有jsp的頁(yè)面均交由tomcat處理
location ~ \.(php)?$ {
  proxy_set_header  Host $host;
  proxy_set_header  X-Real-IP  $remote_addr;
  proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass http://127.0.0.1:81;#轉(zhuǎn)向tomcat處理
}
location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ #設(shè)定訪(fǎng)問(wèn)靜態(tài)文件直接讀取不經(jīng)過(guò)apache
{
  expires      30d;
}
location ~ .*\.(js|css)?$
{
  expires      1h;
}
access_log  /data/logs/kerry/kerry_nginx.log wwwlog;#設(shè)定訪(fǎng)問(wèn)日志的存放路徑
   }
  server
  {
listen       80;
server_name  www.king.com;
index index.html index.htm index.php;#設(shè)定訪(fǎng)問(wèn)的默認(rèn)首頁(yè)地址
root  /data/www/king;#設(shè)定網(wǎng)站的資源存放路徑
#limit_conn   crawler  20;
if (-d $request_filename)
{
  rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
#所有jsp的頁(yè)面均交由tomcat處理
location ~ \.(php)?$ {
  proxy_set_header  Host $host;
                proxy_set_header  X-Real-IP  $remote_addr;
  proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass http://127.0.0.1:81;#轉(zhuǎn)向tomcat處理
}
location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ #設(shè)定訪(fǎng)問(wèn)靜態(tài)文件直接讀取不經(jīng)過(guò)apache
{
  expires      30d;
}
location ~ .*\.(js|css)?$
{
  expires      1h;
}
access_log  /data/logs/king/king_nginx.log bbslog;#設(shè)定訪(fǎng)問(wèn)日志的存放路徑
   }
   server
   {
listen  80;
server_name  status.www.kerry.com;
location / {
stub_status on;
access_log   off;
}
   }
}
EOF

#將nginx添加到啟動(dòng)服務(wù)中

1
2
3
4
chmod 700 /etc/init.d/nginx
/etc/init.d/nginx start
/sbin/chkconfig --add nginx
/sbin/chkconfig --level 2345 nginx on

#每天定時(shí)切割Nginx日志

01
02
03
04
05
06
07
08
09
10
cat >>/usr/local/nginx/sbin/cut_nginx_log.sh<< EOF
#!/bin/bash
# This script run at 00:00
# The Nginx logs path
logs_path_kerry="/data/logs/kerry/"
logs_path_kerry="/data/logs/king/"
mv ${logs_path_kerry}kerry_nginx.log ${logs_path_kerry}$kerry_nginx_$(date -d "yesterday" +"%Y%m%d").log
mv ${logs_path_king}king_nginx.log ${logs_path_king}king_nginx_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/nginx/nginx.pid`
EOF

 

1
chmod +x /usr/local/nginx/sbin/cut_nginx_log.sh

#添加計(jì)劃任務(wù),每天凌晨00:00切割nginx訪(fǎng)問(wèn)日志

1
2
crontab -e
00 00 * * * /bin/bash  /usr/local/nginx/sbin/cut_nginx_log.sh

為apache安裝rpaf模塊:

#為apache安裝rpaf模塊,該模塊用于apache做后端時(shí)獲取訪(fǎng)客真實(shí)的IP
#該模塊用于apache做后端時(shí)獲取訪(fǎng)客真實(shí)的IP(建議在LNAMP最后安裝。。。之前安裝有時(shí)會(huì)出錯(cuò))

1)使用apxs安裝模塊,這里建議不要使用此前apache編譯安裝后的apxs,而是重新單獨(dú)安裝

1
2
3
4
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
yum install httpd-devel  #沒(méi)有apxs的,先安裝httpd-devel
apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c   Apache 2.x 的安裝方式

2)編輯/usr/local/software/apache/conf/httpd.conf,添加模塊參數(shù):

查找代碼:

LoadModule php5_module modules/libphp5.so

在下方添加:

1
2
3
4
5
6
LoadModule rpaf_module modules/mod_rpaf-2.0.so
#Mod_rpaf settings
RPAFenable On
RPAFproxy_ips 127.0.0.1 [your_ips]
RPAFsethostname On
RPAFheader X-Forwarded-For

上面出現(xiàn)的[your_ips]請(qǐng)修改為你本機(jī)所監(jiān)聽(tīng)web服務(wù)的ip,多個(gè)IP用空格空開(kāi)。

#重啟

service nginx restart

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
關(guān)于大型論壇系統(tǒng)環(huán)境搭建(20萬(wàn)日IP負(fù)載平衡實(shí)戰(zhàn))–Nginx Apache2 PHP MySQL - Nginx
apache和IIS共用80端口
虛擬機(jī)上架設(shè)服務(wù)器
簡(jiǎn)單幾步,在Ubuntu上跑WordPress
nginx+PHP+PHP-FPM(FastCGI)在Ubuntu上的安裝和配置
apache代理設(shè)置
更多類(lèi)似文章 >>
生活服務(wù)
熱點(diǎn)新聞
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服