Centos7+nginx+tomcat 集群部署实战

1:安装centos7(链接:http://pan.baidu.com/s/1o80x36a 密码:xuwb),安装步骤自己百度,并克隆4个虚拟机

我的ip为(192.168.72.129 192.168.72.130 192.168.72.131 192.168.72.132)

2:下载xshell,连接上这四台linux

3:在192.168.72.129安装nginx(链接:http://pan.baidu.com/s/1skAQ3X7 密码:lwrz)

 安装步骤:先在192.168.72.129创建文件夹   

------------------------nginx开始安装---------------------------

       cd /usr/local

       mkdir software/nginx

       cd /usr/local/software/nginx

       rz 这里把下载好的nginx复制到/usr/local/software/nginx目录下,

      tar -xzvf nginx-1.8.1.tar.gz

     cd /usr/local/software/nginx/nginx-1.8.1

     ./configure

     这里会报错,一些包找不到

     安装缺失的包

     yum -y install pcre-devel

    yum -y install openssl-devel

     安装完成后执行

    ./configure

   make

    make install

测试nginx

   cd /usr/local/nginx/sbin

  ./nginx -t

启动nginx

    ./nginx

访问nginx      192.168.72.129:80

--------------------nginx安装完成-----------------------

4:4个机器上安装tomcat,并分别部署测试项目(链接:http://pan.baidu.com/s/1i4VzLtF 密码:qnxv)

   安装步骤略

5:修改nginx配置文件

#user  nobody;
#启动进程,通常设置成和cpu的数量相等
worker_processes  1;

#全局错误日志及PID文件
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
   #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
    use   epoll;
   #单个后台worker process进程的最大并发链接数
    worker_connections  1024;
}

#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
   #设定mime类型,类型由mime.type文件定义
    include       mime.types;
    default_type  application/octet-stream;
   #设定日志格式  
    

 #设定负载均衡的服务器列表
  upstream tomcat {
   #weigth参数表示权值,权值越高被分配到的几率越大
    server 192.168.72.129:8080 weight=1 max_fails=1 fail_timeout=30s;  
    server 192.168.72.130:8080 weight=1 max_fails=2 fail_timeout=30s;
    server 192.168.72.131:8080 weight=1 max_fails=2 fail_timeout=30s;
    server 192.168.72.132:8080 weight=1 max_fails=2 fail_timeout=30s;
  }
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
       #侦听8888端口
        listen       8888;
       # server_name 192.168.72.129;
       # 定义使用 www.GeekPlusA.com 访问
    server_name   www.GeekPlusA.com;
       #设定本虚拟主机的访问日志
       # access_log  logs/www.GeekPlusA.com.access.log  main;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
       #定义服务器的默认网站根目录位置
            root   html;
       #定义首页索引文件的名称
            index index.jsp index.html index.htm;
    
        proxy_connect_timeout   3;  
            proxy_send_timeout     30;  
            proxy_read_timeout     30;  
      #请求转向 tomcat  定义的服务器列表
        proxy_pass  http://tomcat;
      #以下是一些反向代理的配置可删除.  
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

6:启动tomcat,启动tomcat,观看效果

浏览器输入(http://192.168.72.129:8888/nginx/),刷新看效果

每刷新一次,就切换一下

7:停止某个tomcat,观看效果.再启动观看效果

---

### nginx部署VUE项目

`nginx.cong`

~~~

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
        use   epoll;
        #单个后台worker process进程的最大并发链接数
        worker_connections  50;
}

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        
        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        gzip on;

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
        
        server {
            listen       9000; # nginx 服务启动监听的端口 默认为:80
            server_name  localhost;

            #charset koi8-r;
            #access_log  /var/log/nginx/host.access.log  main;

            location / {
                root   /home/geekplusa/makemoney/xianyu/code/detection-xianyu-front/dist; # 我的vue打包后的文件夹目录
                index  index.html index.htm;
            }

            location /api/ {
                rewrite ^/api/(.*) /$1 break; # 过滤掉接口前缀
                proxy_pass  http://172.21.252.163:9010; # 后端接口地址,
            }

            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   /usr/share/nginx/html;
            }

        }
}
 

~~~

  如有疑问,随时加Q交流:1428424253


  

    

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GeekPlusA

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值