错误:
如果报unkown什么什么,需要在配置文件里用http{}包主配置文件 events要放在外面
如果缺少events模块,就自己加配置 events{}
nginx
# tar zxvf nginx-0.8.46.tar.gz -C /usr/local/src
# tar zxvf pcre-8.10.tar.gz -C /usr/local/src
添加一个用户
# useradd -M -s /sbin/nologin www
安装pcre
# cd /usr/local/src/pcre-8.10/
# ./configure
# make
# make install
如果报错,安装相应的软件包,比如gcc
# make clean
# make
# make install
安装nginx
# cd /usr/local/src/nginx-0.8.46/
# rpm -q openssl-devel
# ./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
# make && make install
启动服务
# cd /usr/local/webserver/nginx/
# ls
conf html logs sbin
# ./sbin/nginx -c ./conf/nginx.conf
# netstat -altunp |grep :80
------------------------
配置文件
# cd /usr/local/webserver/nginx/conf
# vim nginx.conf
查看状态
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
........
........
location /NginxStatus {
stub_status on;
access_log logs/nginxstatus.log;
auth_basic "nginxstatus";
auth_basic_user_file /usr/local/webserver/nginx/conf/.htpasswd;
}
......
......
......
}
# yum install httpd -y
# cd /usr/local/webserver/nginx/conf
# htpasswd -c .htpasswd n1
热部署
# kill -HUP `cat /usr/local/webserver/nginx/logs/nginx.pid`
--------------------------------------------
虚拟主机
# cd /usr/local/webserver/nginx/conf
# vim nginx.conf
把server { } 注释掉
server {
90 listen 80;
91 server_name www.baidu.com;
92 access_log /data1/logs/baidu.access.log combined;
93
94 location / {
95 root /data0/htdocs/baidu;
96 index index.html index.htm;
97 }
98 }
99
100 server {
101 listen 80;
102 server_name www.google.com;
103 access_log /data1/logs/google.access.log combined;
104
105 location / {
106 root /data0/htdocs/google;
107 index index.html index.htm;
108 }
109 }
112 server {
113 listen 80 default;
114 access_log /data1/logs/default.access.log combined;
115
116 location / {
117 root /data0/htdocs/default;
118 index index.html index.htm;
119 }
120 }
创建网页发布目录
# mkdir -pv /data0/htdocs/{baidu,google,default}
# cd /data0/htdocs/baidu
# echo "欢迎光临baidu" > index.html
# cd /data0/htdocs/google/
# echo "欢迎光临google" > index.html
# cd /data0/htdocs/default/
# echo "欢迎光临" > index.html
# mkdir -pv /data1/logs
# chown -R www:www /data1/logs
检查配置文件
# cd /usr/local/webserver/nginx/
# ./sbin/nginx -t -c ./conf/nginx.conf
解析域名
# vim /etc/hosts
添加
192.168.3.3 www.baidu.com
192.168.3.3 www.google.com
服务平滑重启
# cat /usr/local/webserver/nginx/logs/nginx.pid
11329 //找出进程号
# kill -HUP 11329
# firefox http://www.baidu.com &
http://www.google.com
http://192.168.3.3
---------------------------------------
日志管理
# cd /usr/local/webserver/nginx/conf
# vim nginx.conf
日志格式
语法
log_format name format //name不能重复
log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
access_log //日志记录到哪里
86 server {
87 listen 80;
88 server_name www.baidu.com;
89
90 log_format baidu '$remote_addr - [$time_local] ';
91 access_log /data1/logs/baidu.access.log baidu;
92
93 location / {
94 root /data0/htdocs/baidu;
95 index index.html index.htm;
96 }
97 }
# cd /data1/logs/
# mv baidu.access.log baidu.access.bak
# touch baidu.access.bak
# kill -HUP `cat /usr/local/webserver/nginx/logs/nginx.pid`
# firefox http://www.baidu.com &
# cd /data1/logs/
# less baidu.access.log
-----------------------------
分割日志
# vim nginxlog.sh
#!/bin/bash
date=`date "+%Y%m%d%H%m"`
echo "baidu" > /test/webname
echo "google" >> /test/webname
echo "default" >> /test/webname
while read webname
do
mv /data1/logs/${webname}.access.log /data1/logs/${webname}.access${date}.log
touch /data1/logs/${webname}
kill -HUP `cat /usr/local/webserver/nginx/logs/nginx.pid`
done
# chmod +x nginxlog.sh
# crontab -e
* * * * * /bin/bash /test/nginxlog.sh
负载均衡
前端代理服务器 192.168.3.3
# cd /usr/local/webserver/nginx/conf
# vim nginx.conf
35 upstream uplook {
36 server 192.168.3.5;
37 server 192.168.3.111;
38 server 192.168.3.18;
39 server 192.168.3.22;
40 }
41 server {
42 listen 80;
43 server_name www.uplook.com 192.168.3.3;
44 root html;
45 index index.html index.htm;
46
47 #charset koi8-r;
48
49 #access_log logs/host.access.log main;
50
51 location / {
52 proxy_pass http://uplook;
53 proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
54 include /usr/local/webserver/nginx/conf/proxy.conf;
55 }
# cd /usr/local/webserver/nginx/conf
# vim proxy.conf
proxy_redirect off;
proxy_set_header Host $host; # 设置由后端服务器获取用户的主机名
proxy_set_header X-Real_IP $remote_addr; # 设置由后端服务器获取用户的真实IP地址
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 设置由后端服务器获取代理者的真实IP。
client_body_buffer_size 128k; #用于指定客户端请求主体缓冲区大小,可以理解为先保存到本地再传给用户
proxy_connect_timeout 90; #后端服务器连接的超时时间
proxy_send_timeout 90; # 后端服务器数据传回时间,在这个时间内必须传回数据,否则断开连接
proxy_read_timeout 90; #设置 nginx 从代理的后端服务器获取信息的时间,表示连接成功后,nginx等待后端服务器的响应时间
proxy_buffer_size 4k; # 设置缓冲区大小
proxy_buffers 4 32k; # 设置缓冲区的数量和大小
proxy_busy_buffers_size 64k; # 设置系统很忙的时候,可以使用的缓冲区大小
proxy_temp_file_write_size 64k; # 指定proxy缓存文件的大小
# kill -HUP `cat /usr/local/webserver/nginx/logs/nginx.pid`
------------
启动后端服务器,在每个服务器都创建不同的默认首页
检查配置文件
# /usr/local/webserver/nginx/sbin/nginx -t -c /usr/local/webserver/nginx/conf/nginx.conf
启动服务
# /usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf
打开ie浏览器, http://192.168.3.3 前端ip地址,刷新几次,看到的页面都是不同的
------------------------------
LNMP
fastcgi
一 ,安装php所需的库
1) libiconv
# tar zxvf libiconv-1.13.1.tar.gz -C /usr/local/src
# cd /usr/local/src/libiconv-1.13.1
# ./configure --prefix=/usr/local
# make && make install
2) libmcrypt
# tar zxvf libmcrypt-2.5.8.tar.gz -C /usr/local/src
# cd /usr/local/src/libmcrypt-2.5.8/
# ./configure
# make && make install
# /sbin/ldconfig //加载新的动态连接库
# cd libltdl
# ./configure --enable-ltdl-install
# make && make install
3) mash
# tar xf mhash-0.9.9.9.tar.gz -C /usr/local/src
# cd /usr/local/src/mhash-0.9.9.9/
# ./configure
# make && make install
4)
# tar xf mcrypt-2.6.8.tar.gz -C /usr/local/src
# cd /usr/local/src/mcrypt-2.6.8
# ./configure
configure: error: *** libmcrypt was not found
# vim /etc/ld.so.conf
添加一行
/usr/local/lib
# /sbin/ldconfig //加载新的动态连接库
# ./configure
# make && make install
------------------------
二、 安装mysql数据库
# tar xf mysql-5.5.3-m3.tar.gz -C /usr/local/src
# useradd -s /sbin/nologin -M mysql
# cd /usr/local/src/mysql-5.5.3-m3/
# ./configure --prefix=/usr/local/webserver/mysql --enable-assembler --with-extra-charsets=complex --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg
如果出现错误
# yum install -y ncurses-devel
# ./configure --prefix=/usr/local/webserver/mysql --enable-assembler --with-extra-charsets=complex --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg
# make && make install
# cd /usr/local/webserver/
# chmod +w mysql/
# chown -R mysql:mysql mysql/
# mkdir -p /data0/mysql/3306/data
# mkdir -p /data0/mysql/3306/binlog
# mkdir -p /data0/mysql/3306/relaylog
# chown -R mysql:mysql /data0/mysql/
初始化数据库
# /usr/local/webserver/mysql/bin/mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/data0/mysql/3306/data --user=mysql
复制配置文件 ,配置文件可以在共享的lnmp目录里找到
# cp my.cnf.txt /data0/mysql/3306/my.cnf
# cp mysql.txt /data0/mysql/3306/mysql //启动脚本
# cd /data0/mysql/3306
# chown mysql:mysql my.cnf
# chown mysql:mysql mysql
# chmod +x mysql
# /data0/mysql/3306/mysql start //启动数据库
# netstat -altunp |grep :3306
tcp 0 0 :::3306 :::* LISTEN 29061/mysqld
# /usr/local/webserver/mysql/bin/mysql
mysql> grant all privileges on *.* to admin@localhost identified by '123';
mysql> grant all privileges on *.* to admin@"127.0.0.1" identified by '123';
mysql> grant all privileges on *.* to admin@"192.168.3.3" identified by '123';
--------------------------
三、安装PHP
# tar xf php-5.2.14.tar.gz -C /usr/local/src
# cp php-5.2.14-fpm-0.5.14.diff.gz /usr/local/src
//打补丁,让php支持fastcgi
# gzip -cd php-5.2.14-fpm-0.5.14.diff.gz |patch -d php-5.2.14 -p1
# ./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql/ --with-mysqli=/usr/local/webserver/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
如果出现错误
# yum install libxml2-devel -y
# yum install openssl* -y
# yum install curl* -y
# yum install libjpeg* libpng* -y
# yum install freetype* -y
# yum install openldap* -y
# make ZEND_EXTRA_LIBS='-liconv'
# make install
# cp php.ini-dist /usr/local/webserver/php/etc/php.ini
-------------------------
四、 安装php的扩展模块
1) memcache
# tar zxvf memcache-2.2.5.tgz -C /usr/local/src
# cd /usr/local/src/memcache-2.2.5/
# /usr/local/webserver/php/bin/phpize
如果出现错误
# yum install autoconf -y
# /usr/local/webserver/php/bin/phpize
# ./configure --with-php-config=/usr/local/webserver/php/bin/php-config
# make && make install
2)php加速器
# tar xf eaccelerator-0.9.6.1.tar.bz2 -C /usr/local/src
# cd /usr/local/src/eaccelerator-0.9.6.1/
# /usr/local/webserver/php/bin/phpize
# ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
# make && make install
3)PDO-MYSQL
------------------------
动静分离
克隆网页服务器,充当fastcgi
--------
网页服务器
把qq农场上传到 /data0/htdocs/www/qq
# chmod -R 777 /data0/htdocs/www/qq
# cd /usr/local/webserver/nginx/conf
# vim nginx.conf
67 fastcgi_pass 192.168.3.5:9000; #写fastcgi的ip地址
98 fastcgi_pass 192.168.3.5:9000;
# 启动网页服务
# /usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf
--------------------------
fastcgi
把qq农场上传到 /data0/htdocs/www/qq
# chmod -R 777 /data0/htdocs/www/qq
启动mysql服务器
# /data0/mysql/3306/mysql start
# /usr/local/webserver/mysql/bin/mysql -u root -p
mysql> create database renren;
mysql> use renren;
mysql> source /data0/htdocs/www/qq/qqfarm.sql
# cd /usr/local/webserver/php/etc/
# vim php-fpm.conf
41
137
# /usr/local/webserver/php/sbin/php-fpm start # 启动fastcgi
------------------------
在网页服务器
firefox http://www.s135.com/qq/