- jdk部署配置
tar zxvf jdk1.7.0_79 mv jdk1.7.0_79 /usr/local/jdk1.7.0_79 - 编辑文件写入一下配置
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
======================= - 安装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 - 下载解压
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 - 安装所需路径以及模块
./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 \ - 编译安装
make
make install
执行echo $?进行检查
/usr/local/nginx/sbin/nginx 启动nginx
/usr/local/nginx/sbin/nginx -s reload 重启nginx - 编写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 prog: "
mkdir -p /dev/shm/nginx_temp
daemon NGINX_CONF
RETVAL=RETVAL
}
stop() {
echo -n prog: "
killproc -p NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=RETVAL
}
reload(){
echo -n prog: "
killproc -p NGINX_SBIN -HUP
RETVAL=RETVAL
}
restart(){
stop
start
}
configtest(){
NGINX_CONF -t
return 0
}
case ""Usage:
RETVAL
保存后,执行
chmod a+x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
----nginx配置文件示例----
- 头部公共配置
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 'http_x_forwarded_for [
host "
status'
'"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;
- 负载均衡
nginx 的upstream使用sticky,如下
upstream cluster_test {
sticky;
server 192.168.100.209:80;
server 192.168.100.225:80;
} - 反向代理配置
server {
listen 7001;
server_name 192.168.0.3;
location /{
proxy_pass http://172.1.1.10:7001;
proxy_set_header Hostserver_port;
proxy_set_header X-Real-IPproxy_add_x_forwarded_for;
}
} - 日志切割
add_header X-Frame-Options SAMEORIGIN;
log_format main 'remote_user [
request" '
'body_bytes_sent "
http_user_agent
request_time
upstream_addr $upstream_status';
- 配置静态文件
location ~ .*.(gif|jpg|jpeg|png)request_filename)
{
proxy_pass http://192.168.1.88:10054;
}
} - 端口转发-将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"; }