NGINX、JDK部署配置

  1. jdk部署配置
    tar zxvf jdk1.7.0_79 mv jdk1.7.0_79 /usr/local/jdk1.7.0_79
  2. 编辑文件写入一下配置
    vim /etc/profile.d/java.sh加入如下配置
    JAVA_HOME=/usr/local/jdk1.7.0_79
    JAVA_BIN=/usr/local/jdk1.7.0_79/bin
    JRE_HOME=/usr/local/jdk1.7.0_79/jre
    PATH=$PATH:/usr/local/jdk1.7.0_79/bin:/usr/local/jdk1.7.0_79/jre/bin
    CLASSPATH=/usr/local/jdk1.7.0_79/jre/lib:/usr/local/jdk1.7.0_79/lib:/usr/local/jdk1.7.0_79/jre/lib/charsets.jar
    source /etc/profile.d/java.sh //及时生效
    如果以上配置成功,则下面的命令可以看到java的版本: java -version
    =======================
  3. 安装nginx所需依赖
    yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
    yum install –y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
  4. 下载解压
    cd /usr/local/src/
    wget http://nginx.org/download/nginx1.6.2.tar.gz
    tar zxvf nginx-1.6.2.tar.gz cd nginx-1.6.2
  5. 安装所需路径以及模块
    ./configure
    --prefix=/usr/local/nginx
    --with-http_realip_module
    --with-http_ssl_module
    --with-http_sub_module
    --with-http_stub_status_module
    --with-http_gzip_static_module
    --with-pcre \
  6. 编译安装
    make
    make install
    执行echo $?进行检查
    /usr/local/nginx/sbin/nginx 启动nginx
    /usr/local/nginx/sbin/nginx -s reload 重启nginx
  7. 编写nginx启动脚本
    vim /etc/init.d/nginx //加入如下内容

!/bin/bash

chkconfig: - 30 21

description: http service.

Source Function Library

. /etc/init.d/functions

Nginx Settings

NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=03
prog="Nginx"

start() {
echo -n "Startingprog: "
mkdir -p /dev/shm/nginx_temp
daemon NGINX_SBIN -cNGINX_CONF
RETVAL=? echo returnRETVAL
}

stop() {
echo -n "Stoppingprog: "
killproc -p NGINX_PIDNGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=? echo returnRETVAL
}

reload(){
echo -n "Reloadingprog: "
killproc -p NGINX_PIDNGINX_SBIN -HUP
RETVAL=? echo returnRETVAL
}

restart(){
stop
start
}

configtest(){
NGINX_SBIN -cNGINX_CONF -t
return 0
}

case "1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo"Usage: 0 {start|stop|reload|restart|configtest}" RETVAL=1 esac exitRETVAL
保存后,执行
chmod a+x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
----nginx配置文件示例----

  1. 头部公共配置
    user nobody nobody;
    worker_processes 2;
    error_log /usr/local/nginx/logs/nginx_error.log crit;
    pid /usr/local/nginx/logs/nginx.pid;
    worker_rlimit_nofile 51200;

events
{
use epoll;
worker_connections 6000;
}

http
{
server_tokens off
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip 'remote_addrhttp_x_forwarded_for [time_local]' 'host "request_uri"status'
'"http_referer" "http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 300m;
client_body_buffer_size 16k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml;


  1. 负载均衡
    nginx 的upstream使用sticky,如下
    upstream cluster_test {
    sticky;
    server 192.168.100.209:80;
    server 192.168.100.225:80;
    }
  2. 反向代理配置
    server {
    listen 7001;
    server_name 192.168.0.3;
    location /{
    proxy_pass http://172.1.1.10:7001;
    proxy_set_header Host host:server_port;
    proxy_set_header X-Real-IP remote_addr; proxy_set_header X-Forwarded-Forproxy_add_x_forwarded_for;
    }
    }
  3. 日志切割
    add_header X-Frame-Options SAMEORIGIN;
    log_format main 'remote_addrremote_user [time_local] "request" '
    'statusbody_bytes_sent "http_referer" ' 'http_user_agent http_x_forwarded_forrequest_time upstream_response_timeupstream_addr $upstream_status';
  4. 配置静态文件
    location ~ .*.(gif|jpg|jpeg|png){ expires 24h; root /web/resource/UploadFiles/SystemFile/; access_log /usr/local/nginx/logs/images.log; proxy_store on; proxy_store_access user:rw group:rw all:rw; proxy_temp_path /web/resource/UploadFiles/SystemFile/; proxy_redirect off; proxy_set_header host 127.0.0.1; client_max_body_size 10m; client_body_buffer_size 1280k; proxy_connect_timeout 900; proxy_send_timeout 900; proxy_read_timeout 900; proxy_buffer_size 40k; proxy_buffers 40 320k; proxy_busy_buffers_size 640k; proxy_temp_file_write_size 640k; if ( !-erequest_filename)
    {
    proxy_pass http://192.168.1.88:10054;
    }
    }
  5. 端口转发-将9000端口转发映射至 8080
    server {
    listen 8080;

    listen somename:8080;

     server_name  localhost;
     location / {
     proxy_pass http://localhost:9000 ;
     proxy_set_header Host $host:8080;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Via "nginx";
     }
    
    }
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 200,527评论 5 470
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,314评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 147,535评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,006评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,961评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,220评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,664评论 3 392
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,351评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,481评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,397评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,443评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,123评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,713评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,801评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,010评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,494评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,075评论 2 341

推荐阅读更多精彩内容