2.开始安装
a.上传nginx程序布署包至/u01目录下
b.将压缩包进行解压
1.<span class="pln">tar </span><span class="pun">–</span><span class="pln">xvzf nginx</span><span class="pun">-</span><span class="lit">1.4</span><span class="pun">.</span><span class="lit">7.tar</span><span class="pun">.</span><span class="pln">gz</span><span class="pun">、</span>
2.<span class="pln">tar </span><span class="pun">–</span><span class="pln">xvzf nginx</span><span class="pun">-</span><span class="pln">sticky</span><span class="pun">-</span><span class="pln">module</span><span class="pun">-</span><span class="lit">1.1</span><span class="pun">.</span><span class="pln">tar</span><span class="pun">.</span><span class="pln">gz</span><span class="pun">、</span>
3.<span class="pln">unzip nginx_upsatream_check_module</span><span class="pun">-</span><span class="pln">master</span><span class="pun">.</span><span class="pln">zip </span>
c.跳转到解压后的文件夹中,执行如下命令
1.<span class="pln"> cd </span><span class="pun">/</span><span class="pln">u01</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">-</span><span class="lit">1.4</span><span class="pun">.</span><span class="lit">4</span><span class="pun">/</span>
2.<span class="pln"> </span><span class="pun">./</span><span class="pln">configure </span><span class="pun">--</span><span class="pln">prefix</span><span class="pun">=/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">nginx </span><span class="pun">--</span><span class="pln">with</span><span class="pun">-</span><span class="pln">http_stub_status_module </span><span class="pun">--</span><span class="pln">with</span><span class="pun">-</span><span class="pln">http_ssl_module </span><span class="pun">--</span><span class="pln">add</span><span class="pun">-</span><span class="pln">module</span><span class="pun">=/</span><span class="pln">u01</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">-</span><span class="pln">sticky</span><span class="pun">-</span><span class="pln">module</span><span class="pun">-</span><span class="lit">1.1</span><span class="pln"> </span><span class="pun">--</span><span class="pln">add</span><span class="pun">-</span><span class="pln">module</span><span class="pun">=/</span><span class="pln">u01</span><span class="pun">/</span><span class="pln">nginx_upstream_check_module</span><span class="pun">-</span><span class="pln">master</span>
3. make
4. make install
命令解释:
./configure是执行configure这个配置文件,后面是为这个文件配置的参数。
prefix=/usr/local/nginx:是安装路径
with-http_stub_status_module
with-http_ssl_module
这个是为nginx添加两个模块
add-module=../nginx-sticky-module-1.1
add-module=../nginx_upstream_check_module-master
d.在安装时遇到的问题以及解决
安装时会遇到缺少包,需要用yum进行安装,关于yum的配置详见另一篇文章,以下是我遇到缺少的包
1.<span class="pun">问题</span><span class="lit">1</span><span class="pun">:</span>
2.<span class="pun">./</span><span class="pln">configure</span><span class="pun">:</span><span class="pln"> error</span><span class="pun">:</span><span class="pln"> the HTTP rewrite module requires the PCRE library</span><span class="pun">.</span>
3.4.<span class="pun">安装</span><span class="pln">pcre</span><span class="pun">-</span><span class="pln">devel</span><span class="pun">解决问题</span>
5.<span class="pln">yum </span><span class="pun">-</span><span class="pln">y install pcre</span><span class="pun">-</span><span class="pln">devel</span>
6.7.8.<span class="pun">问题</span><span class="lit">2</span><span class="pun">:</span>
9.<span class="pun">./</span><span class="pln">configure</span><span class="pun">:</span><span class="pln"> error</span><span class="pun">:</span><span class="pln"> the HTTP gzip module requires the zlib library</span><span class="pun">.</span>
10.<span class="typ">You</span><span class="pln"> can either disable the module by using </span><span class="pun">–</span><span class="pln">without</span><span class="pun">-</span><span class="pln">http_gzip_module</span>
11.<span class="pln">option</span><span class="pun">,</span><span class="pln"> or install the zlib library into the system</span><span class="pun">,</span><span class="pln"> or build the zlib </span>
12.<span class="pln">library</span>
13.<span class="pln">statically from the source with nginx by using </span><span class="pun">–</span><span class="pln">with</span><span class="pun">-</span><span class="pln">zlib</span><span class="pun">=<</span><span class="pln">path</span><span class="pun">></span><span class="pln"> option</span><span class="pun">.</span>
14.15.<span class="pun">则需要安装“</span><span class="pln">zlib</span><span class="pun">-</span><span class="pln">devel</span><span class="pun">”即可。</span><span class="pln">SSH</span><span class="pun">执行以下命令:</span>
16.17.<span class="pln">yum install </span><span class="pun">-</span><span class="pln">y zlib</span><span class="pun">-</span><span class="pln">devel</span>
3.将Nginx服务设为系统服务
a.新建nginx文件,并将她拷入/etc/init.d/中执行如下命令
1.<span class="pun">[</span><span class="pln">root@localhost </span><span class="pun">~]#</span><span class="pln"> vim </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">nginx</span>
2. 按i键,进入编辑模式,输入如下信息(不包含中文注释),其中nginxd、nginx_config、nginx_pid请按实际情况配置:
3. #nx Startup script for the Nginx HTTP Server
# this script create it by jackbillow at 2007.10.15.
# it is v.0.0.2 version.
# if you find any errors on this scripts,please contact jackbillow.
# and send mail to jackbillow at gmail dot com.
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it’s not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
#nginx 脚本路径
nginxd=/usr/local/nginx/sbin/nginx
#nginx 脚本nginx.conf配置
nginx_config=/usr/local/nginx/conf/nginx.conf
#nginx.pid
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog=”nginx”
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = “no” ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo “nginx already running….”
exit 1
fi
echo -n $”Starting $prog: “
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $nginx_pid
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $”Stopping $prog: “
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $nginx_pid
}
# reload nginx service functions.
reload() {
echo -n $”Reloading $prog: “
“nginx” 81L, 1855C
按ESC键,退出编辑模式,输入命令:wq保存退出。
b.执行以下代码,将配置文件加入启动项,并解决权限问题
1.<span class="pun">[</span><span class="pln">root@localhost </span><span class="pun">~]#</span><span class="pln"> chmod </span><span class="lit">755</span><span class="pln"> </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">nginx</span>
2.<span class="pun">[</span><span class="pln">root@localhost </span><span class="pun">~]#</span><span class="pln"> chkconfig </span><span class="pun">--</span><span class="pln">add nginx</span>
4.启动nginx服务
使用命令service nginx start启动nginx服务,出现如下信息即启动成功:
Service nginx: [OK]
在ie浏览器中访问http://192.168.20.102(其中192.168.20.102为nginx服务器IP),出现如下图所示,则nginx安装完成
使用命令 service nginx stop 关闭nginx关闭服务
4.Nginx插件包说明
安装nginx主要有两个插件,他们的作用如下 nginx_upstream_checkmodule-master.zip nginx-sticky-module-1.1.tar.gz
_ nginx_upstream_checkmodule-master 主要用来检测后端服务器状态
nginx-sticky-module 主要是更好负载均衡
关于这两个插件,后续会详细介绍
_