outline
1. Tomcat
BasicConfiguration
1. Provide SysV scripts for Tomcat
2. catalina script explanation
3. Telnet login management Tomcat
4. ConfigurationTomcat virtual host
5.Tomcat graphical management interface
6. Deployment of JSP website case
Two, NginxreverseproxyTomcatserver >
1. Nginx will request reverseproxy to backend Tomcat
2. Nginx caches images locally
3. Nginx separates requests from static and dynamic
Note, description of experimental environment, operating system: CentOS 6.4
x86_64, software version: jdk-7u40, apache-tomcat-7.0.42, Nginx-1.4.2, please download the software used in the blog here: http://yunpan.cn/QGBCLwrZnpLMS.
1. Tomcat BasicConfiguration
1. Provide SysV scripts for Tomcat
Note, in the previous blog post, we have demonstrated the installation of Tomcat, and we will not demonstrate it here. For bloggers who are not clear, you can refer to this blog post, http://freeloda.blog.51cto.com/2033581/1299644, on In a blog post, we did not add the SysV script. In this blog post, we will add it. Let’s demonstrate it in detail below.
[root@tomcat ~]# vim /etc/init.d/tomcat
#!/bin/sh
# Tomcat init script for Linux.
#
# chkconfig: 2345 96 14
# description: The Apache Tomcat servlet/JSP container.
CATALINA_HOME=/usr/local/tomcat #Pay attention to your script path
export CATALINA_HOME
# export CATALINA_OPTS=”-Xms128m -Xmx256m”
exec $CATALINA_HOME/bin/catalina.sh $*
Next, let’s increase the execution permission and add the service list to set it to start automatically.
[root@tomcat ~]# chmod +x /etc/init.d/tomcat
[root@tomcat ~]# chkconfig –add tomcat
[root@tomcat ~]# chkconfig tomcat –list
tomcat 0: off 1: off 2: on 3: on 4: on 5: on 6: off
Let’s start Tomcat and test it out.
[root@tomcat ~]# service tomcat start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Check the enabled port number,
[root@tomcat ~]# netstat -ntulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1044/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1121/master
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 12988/sshd
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 13053/sshd
tcp 0 0 :::8080 :::* LISTEN 13088/java
tcp 0 0 :::22 :::* LISTEN 1044/sshd
tcp 0 0 ::1:25 :::* LISTEN 1121/master
tcp 0 0 ::1:6010  pid-path=/var/run/nginx/nginx.pid \
> –lock-path=/var/lock/nginx.lock \
> –user=nginx \
> –group=nginx \
> –with-http_ssl_module \
> –with-http_flv_module \
> –with-http_stub_status_module \
> –with-http_gzip_static_module \
> –http-client-body-temp-path=/var/tmp/nginx/client/ \
> –http-proxy-temp-path=/var/tmp/nginx/proxy/ \
> –http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
> –http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
> –http-scgi-temp-path=/var/tmp/nginx/scgi \
> –with-pcre
[root@nginx nginx-1.4.2]# make && make install
illustrate:
Nginx can use Tmalloc (fast, multi-threaded malloc library and excellent performance analysis tool) to speed up memory allocation. To use this function, you need to install gperftools in advance, and then add the –with-google_perftools_module option when compiling nginx.
If you want to use the perl module of nginx, you can add the –with-http_perl_module option to the configure script. However, this module is still in the experimental stage, and accidents may occur during operation. Therefore, its implementation is no longer here introduce. If you want to use the cgi function based on nginx, you can also implement it based on FCGI. For the specific implementation method, please refer to the online documents.
Below we provide the SysV init script for nginx,
[root@nginx ~]# cat /etc/init.d/nginx
#!/bin/sh
#
# nginx – this script starts and stops the nginx daemon
#
# chkconfig: – 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
./etc/rc.d/init.d/functions
# Source networking configuration.
./etc/sysconfig/network
# Check that networking is up.
[ “$NETWORKING” = “no” ] && exit 0
nginx=”/usr/sbin/nginx”
prog=$(basename $nginx)
NGINX_CONF_FILE=”/etc/nginx/nginx.conf”
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep “configure arguments:” | sed ‘s/[^*]*–user=\([^ ]*\).*/\1/g’ -`
optiOns=`$nginx -V 2>&1 | grep ‘configure arguments:’`
for opt in $options; do
if [ `echo $opt | grep ‘.*-temp-path’` ]; then
value=`echo $opt | cut -d “=” -f 2`
if [ ! -d “$value” ]; then
# echo “creating” $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $”Starting $prog: “
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $”Stopping $prog: “
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sle