tengine模块,


tengine模块

操作前提:

1、安装tomcat

1.1、安装ip为192.168.230.10的主机的tomcat

[root@node1 software]# tar -zxvf apache-tomcat-7.0.61.tar.gz -C /opt/modules
[root@node1 software]# cd /opt/modules/apache-tomcat-7.0.61/webapps/ROOT
[root@node2 ROOT]# vi index.jsp

<html>
   <h1>Matrix</h1>
</html>

进入tomcat目录
[root@node1 ROOT]# cd /opt/modules/apache-tomcat-7.0.61/bin

启动tomcat
[root@node1 bin]# ./startup.sh

在地址行输入检查页面是否能正常显示:http://192.168.230.10:8080/

1.2、安装ip为192.168.230.11的主机的tomcat

[root@node2 software]# tar -zxvf apache-tomcat-7.0.61.tar.gz -C /opt/modules
[root@node2 software]# cd /opt/modules/apache-tomcat-7.0.61/webapps/ROOT
[root@node2 ROOT]# vi index.jsp


<html>
   <h1>Matrix2</h1>
</html>

[root@node2 ROOT]# cd /opt/modules/apache-tomcat-7.0.61/bin
[root@node2 bin]# ./startup.sh

在地址行输入检查页面是否能正常显示:http://192.168.230.11:8080/

2、配置nginx访问禁止允许

2.1、进入tengine的conf目录下

[root@node1 ~]# cd /opt/modules/tengine-2.1.0/conf

2.2、编辑nginx.conf文件

[root@node1 conf]# vi nginx.conf
server {
        listen       80;
        server_name  www.sparsematrix.com;

        location / {
            deny 192.168.230.10;
            allow 192.168.230.0/24;
            deny all;

            root    /opt/html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }  

2.3、查看nginx访问禁止配置是否成功

在地址栏输入:http://192.168.230.10/

在地址栏输入:http://192.168.230.18/

3、配置nginx用户认证

用户认证访问
  模块ngx_http_auth_basic_module 允许使用"HTTP基本认证"协议验证用户名和密
码来限制对资源的访问。
location / {
  auth_basic "closed site";
  auth_basic_user_file /var/users;
}
Apache发行包中的htpasswd命令来创建user_file 文件
htpasswd -c -m /var/users username
注:需要安装httpd才可以使用上面命令

3.1、使用yum安装httpd

[root@node1 ~]# yum install httpd

3.2、编辑nginx.conf文件

 [root@node1 conf]# vi nginx.conf
  server {
        listen       80;
        server_name  www.sparsematrix.com;

        location / {
            root    /opt/html;
            index  index.html index.htm;            

            auth_basic "Hello!";
            auth_basic_user_file /opt/modules/htpasswd;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location /basic_status {
           stub_status on;
        }
    }

3.3、Apache发行包中的htpasswd命令来创建user_file 文件

[root@node1 ~]# htpasswd -m -c /opt/modules/htpasswd tom
New password: 
Re-type new password: 
Adding password for user tom

[root@node1 ~]# cd /opt/modules/tengine-2.1.0/conf
[root@node1 conf]# rm -rf .nginx.conf.swp

3.4、重新加载nginx服务

[root@node1 init.d]# service nginx reload

3.5、在浏览器地址栏中输入:http://192.168.230.10/

身份认证成功页面显示:

4、配置nginx访问状态监控

4.1、进入tengine的conf目录

[root@node1 ~]# cd /opt/modules/tengine-2.1.0/conf

4.2、编辑nginx.conf文件

[root@node1 conf]# vi nginx.conf
server {
    listen       80;
    server_name  www.sparsematrix.com;

    location / {
        root    /opt/html;
        index  index.html index.htm;
    }
     location /status {
       stub_status on;
     }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;

    }
}

4.3、在浏览器地址栏中输入:http://192.168.230.10/status

5、配置nginx反向代理

5.1、进入tengine的conf目录

[root@node1 ~]# cd /opt/modules/tengine-2.1.0/conf

5.2、编辑nginx.conf文件

[root@node1 conf]# vi nginx.conf
server {
    listen       80;
    server_name  www.sparsematrix.com;

    location / {
        proxy_pass http://192.168.230.11:8080;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;

    }
}  

5.3、重新加载nginx服务

[root@node1 init.d]# service nginx reload

5.4、在地址行输入检查页面是否能正常显示:http://192.168.230.10/

页面显示的是http://192.168.230.11中的内容

6、配置nginx负载均衡

6.1、进入tengine的conf目录

[root@node1 ~]# cd /opt/modules/tengine-2.1.0/conf

前提:保证192.168.230.10:8080、192.168.230.11:8080都能正常运行

6.2、编辑nginx.conf文件

[root@node1 conf]# vi nginx.conf

    upstream sparsematrix { 
        server 192.168.230.10:8080 weight=1;
        server 192.168.230.11:8080 weight=1;
    } 

server {
    listen       80;
    server_name  www.sparsematrix.com;

    location / {
        proxy_pass http://sparsematrix;
    }


} 

6.3、重新启动nginx服务

[root@node1 init.d]# service nginx stop
Stopping nginx:                                            [  OK  ]
[root@node1 init.d]# service nginx start
Starting nginx:                                            [  OK  ]

6.4、在地址行输入检查页面是否能正常显示:http://192.168.230.10/

访问一次显示:

在访问一次显示:

7、tengine新增健康检查模块

7.1、进入tengine的conf目录

[root@node1 ~]# cd /opt/modules/tengine-2.1.0/conf

7.2、编辑nginx.conf文件

[root@node1 conf]# vi nginx.conf

    upstream sparsematrix { 
        server 192.168.230.10:8080 weight=1;
        server 192.168.230.11:8080 weight=1;
        check interval=3000 rise=2 fall=5 timeout=1000 type=http;
        check_http_send "HEAD / HTTP/1.0\r\n\r\n";
        check_http_expect_alive http_2xx http_3xx;
    } 

server {
    listen       80;
    server_name  www.sparsematrix.com;

    location / {
        proxy_pass http://sparsematrix;
    }
    location /status {
        check_status;
    }


}

7.3、在地址行输入:http://192.168.230.10/status对tomcat服务器进行健康检查

访问显示两台tomcat都没有响应:

重新启动两台tomcat

再次访问http://192.168.230.10/status显示两台tomcat运行正常:

相关内容

    暂无相关文章