当前位置:首页 > Windows程序 > 正文

nginx安装配置+集群tomcat:Centos和windows环境

2021-03-29 Windows程序

版本:nginx-1.8.0.tar.gz

官网:    

 

 

版本:apache-tomcat-6.0.44.tar.gz 

官网:

 

1、安装脚本:        

# yum clean all   

# yum makecache

# yum update

 

# yum install wget

# wget -c 

 

# 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

 

# cd /usr/local/nginx

# ./configure --prefix=http://www.mamicode.com/usr/local/nginx --conf-path=http://www.mamicode.com/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

 

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=http://www.mamicode.com/usr/local/nginx/sbin/nginx

nginx_config=http://www.mamicode.com/usr/local/nginx/conf/nginx.conf

nginx_pid=http://www.mamicode.com/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      

技术分享

  

技术分享

 

 

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/69960.html