tengine模块

发布 : 2016-10-02 分类 : 大数据 浏览 :

1.安装tomcat

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

1
2
3
[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
1
2
3
<html>
<h1>Matrix</h1>
</html>
1
2
进入tomcat目录
[root@node1 ROOT]# cd /opt/modules/apache-tomcat-7.0.61/bin
1
2
启动tomcat
[root@node1 bin]# ./startup.sh
1
在地址行输入检查页面是否能正常显示:http://192.168.230.10:8080/

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

1
2
3
[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
1
2
3
<html>
<h1>Matrix2</h1>
</html>
1
2
[root@node2 ROOT]# cd /opt/modules/apache-tomcat-7.0.61/bin
[root@node2 bin]# ./startup.sh
1
在地址行输入检查页面是否能正常显示:http://192.168.230.11:8080/

2.配置nginx访问禁止允许

2.1.进入tengine的conf目录下

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

2.2.编辑nginx.conf文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[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访问禁止配置是否成功

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

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

3.配置nginx用户认证

1
2
3
4
5
6
7
8
9
10
用户认证访问
模块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

1
[root@node1 ~]# yum install httpd

3.2.编辑nginx.conf文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[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 文件

1
2
3
4
5
6
7
[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服务

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

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

1
身份认证成功页面显示:

4.配置nginx访问状态监控

4.1.进入tengine的conf目录

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

4.2.编辑nginx.conf文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[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目录

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

5.2.编辑nginx.conf文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[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服务

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

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

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

6.配置nginx负载均衡

6.1.进入tengine的conf目录

1
2
[root@node1 ~]# cd /opt/modules/tengine-2.1.0/conf
前提:保证192.168.230.10:8080.192.168.230.11:8080都能正常运行

6.2.编辑nginx.conf文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[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服务

1
2
3
4
[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/

1
访问一次显示:

1
在访问一次显示:

7.tengine新增健康检查模块

7.1.进入tengine的conf目录

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

7.2.编辑nginx.conf文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[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服务器进行健康检查

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

1
2
3
重新启动两台tomcat

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

本文作者 : Matrix
原文链接 : https://matrixsparse.github.io/2016/10/02/tengine模块/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!

知识 & 情怀 | 二者兼得

微信扫一扫, 向我投食

微信扫一扫, 向我投食

支付宝扫一扫, 向我投食

支付宝扫一扫, 向我投食

留下足迹