Part : Nginx Installation and configuration

yum install epel-release yum install nginx  

(start|stop|reload) list

service nginx start 
service nginx stop 
service nginx restart
http://IP     check your website,got nginx webpage anot
if cannot open website ,please check you got allow iptables and disabled selinux ..

Nginx HTTP Configure 

vim /usr/local/nginx/config/product.conf
upstream product { 
server 127.0.0.1:8080
} 
server {
listen           80;
server_name             xxx.com;
root                /web/product/;
index                index.jhtml index.html index.htm index.jsp;
charset                utf-8; access_log              logs/product.log ;
location ~ ^/(WEB-INF)/ {
deny all;
}
location / {
include proxy.conf;
proxy_pass https://product;
}
error_page 404 404.jsp;
error_page 500 502 503 500.jsp;
}

Nginx HTTPS Configure 

vim /usr/local/nginx/config/product.conf
server {
listen          443 ssl;
ssl_certificate         ssl/product.crt;
ssl_certificate_key     ssl/product.key;
ssl_session_cache       shared:SSL:20m;
ssl_session_timeout     4h;
ssl_session_tickets     on;
ssl_stapling on;
ssl_stapling_verify     on;
ssl_trusted_certificate ssl/startssl/trustchain.crt;
resolver                8.8.8.8 8.8.4.4;
server_name             xxx.com;
root                /web/product/;
index                index.jhtml index.html index.htm index.jsp;
charset                utf-8;
access_log              logs/product.log;
location ~ ^/(WEB-INF)/ {
deny all;
}
location / {
include proxy.conf;
proxy_pass https://product;
}
error_page 404 404.jsp;
error_page 500 502 503 500.jsp;
}

Proxy HTTP Configure 

vim /usr/local/nginx/conf/proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
set_real_ip_from 0.0.0.0/0;
real_ip_recursive on;
real_ip_header X-Forwarded-For;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
client_max_body_size 30m;
client_body_buffer_size 256k;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;

add include at nginx configure file /usr/local/nginx/conf/nginx.conf 

include /usr/local/nginx/conf/config/product.conf;
service nginx restart

add HTML WEB PAGE

mkdir -p /web/product
vim index.html

I M SYSTEM ADMIN

I M SYSTEM ADMIN.

Nginx Log Rotate Configure :put at /root/bin

#!/bin/sh
P1="product"
P2="logserver"
log_dir="/usr/local/nginx/logs"

time=`date +%Y%m%d`

/bin/mv ${log_dir}/$P1.access.log ${log_dir}/$P1.access.log.$time
/bin/mv ${log_dir}/$P2.access.log ${log_dir}/$P2.access.log.$time
/bin/mv ${log_dir}/error.log ${log_dir}/error.log.$time

#Ensuring nginx.pid in this path,otherwise,pls changed.
kill -USR1 `cat /var/run/nginx.pid`

Part 2: JDK

Check whether java installed:

#java -version
# yum list installed | grep java

Downalod java version 1.6:

http://www.oracle.com/technetwork/java/javase/downloads/jdk6u38-downloads-1877406.html

Installation:

extract jdk to /opt
mv jdk1.6.0_38 jdk

setup environment variable – add in /etc/profile

# vi /etc/profile,

add to ( export PATH Above ):

JAVA_HOME=/opt/jdk
export JAVA_HOME
CLASSPATH=.:$JAVA_HOME/lirootb:$JAVA_HOME/jre/lib
export CLASSPATH
JRE=$JAVA_HOME/jre
export JRE PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export PATH

Source and check java

#source /etc/profile
# java -version

Part 3: tomcat 6 installation and configuration

download binary package add /opt

cd /opt
http://tomcat.apache.org/download-60.cgi

extract to /opt

vim /opt/tomcat/conf/server.xml

Find to this line uncommand

save and exit
/opt/tomcat/bin/startup.sh
http://IP:8080     check your website
if cannot open website ,please check you got allow iptables and disabled selinux ..

Configure your website

vim /opt/tomcat/conf/server.xml

Find this at server.xml and edit

m1881.com

save and exit

restart tomcat

/opt/tomcat/bin/shutdown.sh
/opt/tomcat/bin/startup.sh
http://IP:8080     check your website

Hide tomcat Version

vim /opt/tomcat/bin/catalina.sh
start on line 471
add # elif [ "$1" = "version" ] ; then
to line499 #  exit 1

check tomcat version

/opt/tomcat_xxx/bin sh version.sh

Part 4: Install APR、tomcat-native – optimize java performance setting

yum -y install apr apr-devel openssl-devel

tomcat configure apr
extract:

cd /opt/tomcat_xxx/bin # tar xfvz tomcat-native.tar.gz

Install and configure

# cd tomcat-native-xxx-src/jni/native/ 
# ./configure --with-apr=/usr/bin/apr-1-config --with-java-home=$JAVA_HOME 
# make && make install

Check APR (/opt/tomcat/log/catalina.out)

if APR running will found log below in catalina.log INFO: Loaded APR based Apache Tomcat Native library  … found not files

Edit tomcat catalina.sh (located on the /opt/tomcat_xxx/bin)

# cd /opt/tomcat/bin/
#vi catalina.sh
insert according server's RAM:
JAVA_OPTS='-server -Xms2048m -Xmx2048m -XX:PermSize=1024M -XX:MaxNewSize=1500m -XX:MaxPermSize=2048m -Djava.awt.headless=true -Dcom.sun.management.jmxremote -Dnetworkaddress.cache.ttl=60 -Dsun.net.inetaddr.ttl=60'
CATALINA_OPTS="$CATALINA_OPTS -Djava.awt.headless=true -Djava.library.path=/usr/local/apr/lib”

Part 5: Cronolog Download , Install , configure tomcat to use cronolog

# wget http://pkgs.fedoraproject.org/repo/pkgs/cronolog/cronolog-1.6.2.tar.gz/a44564fd5a5b061a5691b9a837d04979/cronolog-1.6.2.tar.gz # tar xfvz cronolog-1.6.2.tar.gz
# cd cronolog-1.6.2/
#./configure
# make && make install

Test installation :

# cronolog -h

Following steps implements daily log truncation on Tomcat

Stop tomcat

# killall java

Edit catalina.sh

# cd /opt/apache-tomcat-6.0.24/bin/
# vi catalina.sh

Replace the 2 occurences of:

* org.apache.catalina.startup.Bootstrap "$@" start \ >> "$CATALINA_OUT" 2>&1

To:

* org.apache.catalina.startup.Bootstrap "$@" start 2>&1\
| /usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out >> /dev/null &

Also comment/remove out below line since it is no longer necessary:

* touch "$CATALINA_OUT"

Startup tomcat

/opt/tomcat/bin/startup.sh

Part 6: Auto Startup Tomcat Configure

#vi /etc/rc.local , Add : /opt/tomcat_xxx/bin/startup.sh

Part 7: Auto Startup Nginx Configure

chkconfig nginx on

Part 8: Configure nginx logrotate and tomcat logrotate at Crontab -e  

59 23 * * * /root/bin/nginx_logrotate.sh
0 3 * * * /usr/sbin/tmpwatch -afvd 240 /usr/local/nginx/logs/; /usr/sbin/tmpwatch -afvd 240 /opt/tomcat*/logs/;/usr/sbin/tmpwatch -afvd 240 /opt/logs/ >>/var/log/messages 2>&
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *