nginx安装配置+集群tomcat:Centos和windows环境
版本:apache-tomcat-6.0.44.tar.gz
1、安装脚本:
# yum clean all
# yum makecache
# yum update
# yum install wget
# wget -c http://nginx.org/download/nginx-1.7.9.tar.gz
# find -name nginx
# yum remove nginx
# cd /下载目录
# tar -zxv -f nginx-1.7.9.tar.gz
# rm -rf nginx-1.7.9.tar.gz
# mv nginx-1.7.9 /usr/local/nginx
# yum install gcc-c++
# yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
# yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
# cd /usr/local/nginx
# ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf
# make && make install
2、启动/重启/停止/
启动:# /usr/local/nginx/sbin/nginx
重启:# /usr/local/nginx/sbin/nginx -s reload
停止:
#查询nginx主进程号 :ps -ef | grep nginx
#停止进程 :kill -QUIT 主进程号
#快速停止 :kill -TERM 主进程号
#强制停止 :pkill -9 nginx
#快速停止 :kill -TERM 主进程号
#强制停止 :pkill -9 nginx
3、开机启动,启动脚本
1、编写开机启动脚本,在/etc/init.d/目录:vi /etc/init.d/nginx
2、更改脚本权限:chmod 775 /etc/init.d/nginx
或:chmod a+x /etc/init.d/nginx (a+x ==> all user can execute 所有用户可执行)
3、编写脚本内容:
################################
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
#######################
4、设置开机启动:chkconfig nginx on
或:vi /etc/rc.local 加入一行 /etc/init.d/nginx start 保存并退出,下次重启会生效。
5、这样在控制台就很容易的操作nginx了:查看Nginx当前状态、启动Nginx、停止Nginx、重启Nginx…
/etc/init.d/nginx status
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
4、nginx负载均衡配置:集群tomcat
windows下直接解压,点击nginx.exe即可启动,常用命令如下(.exe可去掉)【此为后台运行方式;windows下nginx不自己注册系统服务,需要依赖第三方工具处理注册表信息比较复杂;】:
cd nginx目录下;
启动:nginx.exe 或双击
停止:nginx.exe -s stop
重新加载:nginx.exe -s reload
退出:nginx.exe -s quit;