nginx安装配置集成weblogic(20131107更新红色背景内容)

发布时间:2015-03-02 23:09:11

简介

Nginx(发音同 engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:新浪网易 腾讯等。

官网:http://nginx.org/cn/

一、 yum配置

1. 将光盘内容拷贝到/mnt/redhat5.5目录下

[root@localhost redhat5.5]# cp -fr /media/RHEL_5.5\ x86_64\ DVD/* /mnt/redhat5.5 #把光盘未见拷贝至root根目录下的mnt文件下的redhat5.5

2. 检查是否安装createrepolinux下的创建仓库的软件包

[root@localhost redhat5.5]# rpm -qa |grep createrepo #如果装了显示版本号;未装则结果为空

1)安装createrepo

[root@localhost redhat5.5]# cd Server/

[root@localhost Server]# pwd

/mnt/redhat5.5/Server

[root@localhost Server]# rpm -ivh ./createrepo-0.4.11-3.el5.noarch.rpm

warning: ./createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186

Preparing... ########################################### [100%]

1:createrepo ########################################### [100%]

[root@localhost Server]#

检查安装结果

[root@localhost Server]# rpm -qa |grep createrepo

createrepo-0.4.11-3.el5

3. 创建YUM仓库

[root@localhost Server]# createrepo -g /mnt/redhat5.5/Server/repodata/comps-rhel5-server-core.xml /mnt/redhat5.5/Server

[root@localhost Server]# createrepo -g /mnt/redhat5.5/VT/repodata/comps-rhel5-vt.xml /mnt/redhat5.5/VT/

[root@localhost Server]# createrepo -g /mnt/redhat5.5/Cluster/repodata/comps-rhel5-cluster.xml /mnt/redhat5.5/Cluster/

[root@localhost Server]#createrepo -g /mnt/redhat5.5/ClusterStorage/repodata/comps-rhel5-cluster-st.xml /mnt/redhat5.5/ClusterStorage/

4. 创建本地yum客户端的repo文件

[root@localhost yum.repos.d]# cd /etc/yum.repos.d/

[root@localhost yum.repos.d]# vi local.repo

内容如下:

[local]

name=hntl

baseurl=file:///mnt/redhat5.5/Server

gpgcheck=0

enabled=1

[VT]

name=VT

baseurl=file:///mnt/redhat5.5/VT

gpgcheck=0

[Cluster]

name= Cluster

baseurl=file:///mnt/redhat5.5/Cluster

gpgcheck=0

[CS]

name= ClusterStorage

baseurl=file:///mnt/redhat5.5/ClusterStorage

gpgcheck=0

5. Yum 安装验证

[root@localhost yum.repos.d]# yum install samba

以下命令自己学习

1.使用YUM查找软件包
命令:yum search
2.列出所有可安装的软件包
命令:yum list
3.列出所有可更新的软件包
命令:yum list updates
4.列出所有已安装的软件包
命令:yum list installed
5.列出所有已安装但不在 Yum Repository 內的软件包
命令:yum list extras
6.列出所指定的软件包
命令:yum list
7.使用YUM获取软件包信息
命令:yum info
8.列出所有软件包的信息
命令:yum info
9.列出所有可更新的软件包信息
命令:yum info updates
10.列出所有已安裝的软件包信息
命令:yum info installed
11.列出所有已安裝但不在 Yum Repository 內的软件包信息
命令:yum info extras
12.列出软件包提供哪些文件
命令:yum provides
六、清除YUM缓存
yum会把下载的软件包和header存储在cache中,而不会自动删除。如果我们觉得它们占用了磁盘空间,可以使用yum clean指令进行清除,更精确的用法是yum clean headers清除headeryum clean packages清除下载的rpm包,yum clean all一股脑儿端
1.清除缓存目录(/var/cache/yum)下的软件包
命令:yum clean packages
2.清除缓存目录(/var/cache/yum)下的 headers
命令:yum clean headers
3.清除缓存目录(/var/cache/yum)下旧的 headers
命令:yum clean oldheaders
4.清除缓存目录(/var/cache/yum)下的软件包及旧的headers
命令:yum clean, yum clean all (= yum clean packages; yum clean oldheaders)

二、 nginx 安装

nginx安装依赖pcrezlib两个包,安装包的版本为:nginx-1.2.8(统一安装最新版本的nginx1.4.3版本)pcre-8.30zlib-1.2.7

下载地址分别为:

http://nginx.org/en/download.html

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

http://zlib.net/zlib-1.2.7.tar.gz

1. 选定源码目录

可以是任何目录,本文选定的是/usr/local/src,将上述安装包上传至/usr/local/src文件夹下。

[root@localhost src]# cd /usr/local/src

[root@localhost src]# pwd

/usr/local/src

2. 安装PCRE

使用下面命令下载编译和安装 PCRE 包:

[root@localhost src]# tar -zxvf pcre-8.30.tar.gz

pcre-8.30/

pcre-8.30/doc/

pcre-8.30/doc/html/

pcre-8.30/doc/html/pcre16.html

pcre-8.30/doc/html/pcre_assign_jit_stack.html

pcre-8.30/doc/html/pcre.html

pcre-8.30/doc/html/pcreperform.html

pcre-8.30/doc/html/pcrepartial.html

pcre-8.30/doc/html/pcreunicode.html

.

.

.

.

[root@localhost src]# cd pcre-8.30

[root@localhost pcre-8.30]# ./configure

[root@localhost pcre-8.30]# make

[root@localhost pcre-8.30]# make install

输出结果的后几行如下,注意输出过程是否报错

.

.

.

make[3]: Leaving directory `/usr/local/src/pcre-8.30'

make[2]: Leaving directory `/usr/local/src/pcre-8.30'

make[1]: Leaving directory `/usr/local/src/pcre-8.30'

3. 安装zlib

使用下面命令下载编译和安装 zlib包:

[root@localhost src]# cd /usr/local/src

[root@localhost src]# tar -zxvf zlib-1.2.7.tar.gz

[root@localhost src]# cd zlib-1.2.7

[root@localhost zlib-1.2.7]# ./configure

[root@localhost zlib-1.2.7]# pwd

/usr/local/src/zlib-1.2.7

[root@localhost zlib-1.2.7]# ./configure

[root@localhost zlib-1.2.7]# make

[root@localhost zlib-1.2.7]# make install

输出结果的后几行如下,注意输出过程是否报错

.

.

.

chmod 644 /usr/local/share/man/man3/zlib.3

cp zlib.pc /usr/local/lib/pkgconfig

chmod 644 /usr/local/lib/pkgconfig/zlib.pc

cp zlib.h zconf.h /usr/local/include

chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h

4. 安装ssl

(某些vps默认没装ssl,需要手动安装,或者按照下面附录1.2的方法)

Openssl openssl-devel

[root@localhost nginx-1.2.8]# yum -y install openssl openssl-devel

5. 安装nginx

Nginx 一般有两个版本,分别是稳定版和开发版,可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:

[root@localhost src]# tar -zxvf nginx-1.2.8.tar.gz

[root@localhost src]# cd nginx-1.2.8

[root@localhost nginx-1.2.8]# ./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.30 --with-zlib=/usr/local/src/zlib-1.2.7

运行结果最后几行如下,注意过程是否报错

.

.

.

Configuration summary

+ using PCRE library: /usr/local/src/pcre-8.30

+ using system OpenSSL library

+ md5: using OpenSSL library

+ sha1: using OpenSSL library

+ using zlib library: /usr/local/src/zlib-1.2.7

nginx path prefix: "/usr/local/nginx"

nginx binary file: "/usr/local/nginx/nginx"

nginx configuration prefix: "/usr/local/nginx"

nginx configuration file: "/usr/local/nginx/nginx.conf"

nginx pid file: "/usr/local/nginx/nginx.pid"

nginx error log file: "/usr/local/nginx/logs/error.log"

nginx http access log file: "/usr/local/nginx/logs/access.log"

nginx http client request body temporary files: "client_body_temp"

nginx http proxy temporary files: "proxy_temp"

nginx http fastcgi temporary files: "fastcgi_temp"

nginx http uwsgi temporary files: "uwsgi_temp"

nginx http scgi temporary files: "scgi_temp"

[root@localhost nginx-1.2.8]# make

objs/src/http/modules/ngx_http_upstream_least_conn_module.o \

objs/src/http/modules/ngx_http_upstream_keepalive_module.o \

objs/ngx_modules.o \

-lpthread -lcrypt /usr/local/src/pcre-8.30/.libs/libpcre.a -lssl -lcrypto -ldl /usr/local/src/zlib-1.2.7/libz.a

make[1]: Leaving directory `/usr/local/src/nginx-1.2.8'

make -f objs/Makefile manpage

make[1]: Entering directory `/usr/local/src/nginx-1.2.8'

sed -e "s|%%PREFIX%%|/usr/local/nginx|" \

-e "s|%%PID_PATH%%|/usr/local/nginx/nginx.pid|" \

-e "s|%%CONF_PATH%%|/usr/local/nginx/nginx.conf|" \

-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \

< man/nginx.8 > objs/nginx.8

make[1]: Leaving directory `/usr/local/src/nginx-1.2.8'

[root@localhost nginx]# make install

6. 服务启停

启动

[root@localhost nginx]# cd /usr/local/nginx/

[root@localhost nginx]#./nginx

停止

[root@localhost nginx]# cd /usr/local/nginx/

[root@localhost nginx]#./nginx -s stop

重新启动

[root@localhost nginx]# cd /usr/local/nginx/

[root@localhost nginx]#./nginx –s reload

查看状态

[root@localhost nginx]# ps -ef|grep nginx

root 7425 1 0 13:38 ? 00:00:00 nginx: master process ./nginx

nobody 7460 7425 0 13:42 ? 00:00:00 nginx: worker process

nobody 7461 7425 0 13:42 ? 00:00:00 nginx: worker process

nobody 7462 7425 0 13:42 ? 00:00:00 nginx: worker process

nobody 7463 7425 0 13:42 ? 00:00:00 nginx: worker process

root 7465 4683 0 13:42 pts/1 00:00:00 grep nginx

7. 安装成功验证

默认端口为80,在IE中输入服务IP地址,页面显示如下图,表明安装成功

8. Nginx配置(修改nginx.conf中的 配置如下,然后上传至/usr/local/nginx目录下即可)

user root;

worker_processes 10;

#error_log logs/error.log;

error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

worker_rlimit_nofile 65535;

events {

worker_connections 65535;

}

http {

include mime.types;

default_type application/octet-stream;

#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 logs/access.log main;

sendfile on;

server_names_hash_bucket_size 128;

server_tokens off;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 16m;

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;

fastcgi_intercept_errors on;

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;

server {

listen 80;

server_name 192.168.232.131;

default_type 'text/html';

charset utf-8;

#access_log logs/host.access.log main;

location / {

root /weblogic/apps/cms;

index /publish/html/main/index.html;

client_max_body_size 10m;

client_body_buffer_size 128k;

proxy_connect_timeout 90;

proxy_send_timeout 90;

proxy_read_timeout 90;

proxy_buffer_size 4k;

proxy_buffers 4 32k;

proxy_busy_buffers_size 64k;

proxy_temp_file_write_size 64k;

}

location ~ ^/.*\.(jsp|do){

proxy_pass http://192.168.232.131:8080;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_buffer_size 4k;

proxy_buffers 4 32k;

proxy_busy_buffers_size 64k;

proxy_temp_file_write_size 64k;

proxy_max_temp_file_size 512m;

}

location ~ ^/(WEB-INF)/ {

deny all;

}

#error_page 404 http://www.sh.sgcc.com.cn/404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /404.html;

location = /404.html {

root html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

# root html;

# fastcgi_pass 127.0.0.1:9000;

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

# include fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

# listen 8000;

# listen somename:8080;

# server_name somename alias another.alias;

# location / {

# root html;

# index index.html index.htm;

# }

#}

# HTTPS server

#

#server {

# listen 443;

# server_name localhost;

# ssl on;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;

# ssl_ciphers HIGH:!aNULL:!MD5;

# ssl_prefer_server_ciphers on;

# location / {

# root html;

# index index.html index.htm;

# }

#}

}

}

}

检查配置结果有无错误

[root@localhost nginx]# cd /usr/local/nginx/

[root@localhost nginx]# ./nginx -t -c ./nginx.conf

nginx: the configuration file /usr/local/nginx/./nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/./nginx.conf test is successful

重新启动

[root@localhost nginx]# cd /usr/local/nginx/

[root@localhost nginx]#./nginx –s reload

测试配置结果:http:// 192.168.72.130/(如果发生页面乱码的情况,先清除浏览器的缓存,再重新访问)

正常显示结果为网站首页地址

测试集成结果:http://192.168.72.130/test_license_info.jsp

显示结果为license信息

9. 升级

查看服务状态及进程

[root@localhost local]# ps -ef|grep nginx

root 7425 1 0 13:38 ? 00:00:00 nginx: master process ./nginx

root 8083 7425 0 14:47 ? 00:00:00 nginx: worker process

root 8084 7425 0 14:47 ? 00:00:00 nginx: worker process

root 8085 7425 0 14:47 ? 00:00:00 nginx: worker process

root 8086 7425 0 14:47 ? 00:00:00 nginx: worker process

root 8512 4683 0 15:36 pts/1 00:00:00 grep nginx

查看原始版本

[root@localhost local]# nginx/nginx -V

nginx version: nginx/1.2.8

built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)

TLS SNI support disabled

configure arguments: --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.30 --with-zlib=/usr/local/src/zlib-1.2.7

上传新版本至/usr/local目录,解压编译

[root@localhost local]# tar -zxvf nginx-1.4.3.tar.gz

[root@localhost local]# cd nginx-1.4.3

[root@localhost nginx-1.4.3]# ./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.30 --with-zlib=/usr/local/src/zlib-1.2.7

………

Configuration summary

+ using PCRE library: /usr/local/src/pcre-8.30

+ using system OpenSSL library

+ md5: using OpenSSL library

+ sha1: using OpenSSL library

+ using zlib library: /usr/local/src/zlib-1.2.7

nginx path prefix: "/usr/local/nginx"

nginx binary file: "/usr/local/nginx/nginx"

nginx configuration prefix: "/usr/local/nginx"

nginx configuration file: "/usr/local/nginx/nginx.conf"

nginx pid file: "/usr/local/nginx/nginx.pid"

nginx error log file: "/usr/local/nginx/logs/error.log"

nginx http access log file: "/usr/local/nginx/logs/access.log"

nginx http client request body temporary files: "client_body_temp"

nginx http proxy temporary files: "proxy_temp"

nginx http fastcgi temporary files: "fastcgi_temp"

nginx http uwsgi temporary files: "uwsgi_temp"

nginx http scgi temporary files: "scgi_temp"

[root@localhost nginx-1.4.3]# make

………..

objs/ngx_modules.o \

-lpthread -lcrypt /usr/local/src/pcre-8.30/.libs/libpcre.a -lssl -lcrypto -ldl /usr/local/src/zlib-1.2.7/libz.a

make[1]: Leaving directory `/usr/local/nginx-1.4.3'

make -f objs/Makefile manpage

make[1]: Entering directory `/usr/local/nginx-1.4.3'

sed -e "s|%%PREFIX%%|/usr/local/nginx|" \

-e "s|%%PID_PATH%%|/usr/local/nginx/nginx.pid|" \

-e "s|%%CONF_PATH%%|/usr/local/nginx/nginx.conf|" \

-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \

< man/nginx.8 > objs/nginx.8

make[1]: Leaving directory `/usr/local/nginx-1.4.3'

注意:此时一定不要make install

[root@localhost nginx-1.4.3]# mv /usr/local/nginx/nginx /usr/local/nginx/nginx1103

[root@localhost nginx-1.4.3]# cp objs/nginx /usr/local/nginx/nginx

[root@localhost nginx-1.4.3]# cd ../nginx

回原目录执行升级

[root@localhost nginx]# cd /usr/local/nginx-1.4.3

[root@localhost nginx-1.4.3]# make upgrade

/usr/local/nginx/nginx -t

nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/nginx.conf test is successful

kill -USR2 `cat /usr/local/nginx/nginx.pid`

sleep 1

test -f /usr/local/nginx/nginx.pid.oldbin

kill -QUIT `cat /usr/local/nginx/nginx.pid.oldbin`

查看进程状态,此时处于新老进程交接任务状态。

[root@localhost nginx-1.4.3]# ps -ef|grep nginx

root 14061 1 0 15:56 ? 00:00:00 nginx: master process ./nginx

root 14062 14061 1 15:56 ? 00:00:02 nginx: master process ./nginx

root 14063 14061 1 15:56 ? 00:00:01 nginx: master process ./nginx

root 14064 14061 1 15:56 ? 00:00:01 nginx: master process ./nginx

root 14065 14061 2 15:56 ? 00:00:02 nginx: master process ./nginx

root 14085 4683 1 15:58 pts/1 00:00:00 grep nginx

此时新进程已经开始工作。

[root@localhost nginx-1.4.3]# ps -ef|grep nginx

root 14061 1 0 15:56 ? 00:00:00 nginx: master process ./nginx

root 14062 14061 1 15:56 ? 00:00:02 nginx: worker process

root 14063 14061 1 15:56 ? 00:00:02 nginx: worker process

root 14064 14061 1 15:56 ? 00:00:02 nginx: worker process

root 14065 14061 2 15:56 ? 00:00:03 nginx: worker process

root 14091 4683 0 15:59 pts/1 00:00:00 grep nginx

查看版本升级结果

[root@localhost nginx-1.4.3]# ../nginx/nginx -V

nginx version: nginx/1.4.3

built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)

TLS SNI support disabled

configure arguments: --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.30 --with-zlib=/usr/local/src/zlib-1.2.7

完毕!

nginx安装配置集成weblogic(20131107更新红色背景内容)

相关推荐