update
This commit is contained in:
19
nginx/Demo/TwoNodes/README.md
Normal file
19
nginx/Demo/TwoNodes/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# 部署 nginx 双节点+高可用
|
||||
|
||||
- 在两台服务器上都执行下面操作
|
||||
- 根据实际环境修改
|
||||
- docker-compose.yml
|
||||
- keepalived/conf/keepalived.conf
|
||||
- nginx/http.d/80.conf
|
||||
|
||||
- 创建目录
|
||||
```
|
||||
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
|
||||
```
|
||||
|
||||
- 上传可能需要的前端文件到 nginx/html/ 下
|
||||
- 启动
|
||||
```
|
||||
docker-compose up -d
|
||||
```
|
||||
|
38
nginx/Demo/TwoNodes/docker-compose.yml
Normal file
38
nginx/Demo/TwoNodes/docker-compose.yml
Normal file
@@ -0,0 +1,38 @@
|
||||
version: "3.7"
|
||||
|
||||
services:
|
||||
keepalived:
|
||||
image: harbor.colben.cn/general/keepalived
|
||||
container_name: keepalived
|
||||
restart: "on-failure"
|
||||
stop_grace_period: 1m
|
||||
privileged: true
|
||||
network_mode: host
|
||||
volumes:
|
||||
- type: bind
|
||||
source: ./keepalived/conf
|
||||
target: /etc/keepalived
|
||||
- type: bind
|
||||
source: ./keepalived/log
|
||||
target: /var/log/keepalived
|
||||
|
||||
nginx:
|
||||
image: harbor.colben.cn/general/nginx
|
||||
container_name: nginx
|
||||
restart: "on-failure"
|
||||
stop_grace_period: 1m
|
||||
network_mode: host
|
||||
volumes:
|
||||
- type: bind
|
||||
source: ./nginx/html
|
||||
target: /var/lib/nginx/html
|
||||
- type: bind
|
||||
source: ./nginx/http.d
|
||||
target: /etc/nginx/http.d
|
||||
- type: bind
|
||||
source: ./nginx/stream.d
|
||||
target: /etc/nginx/stream.d
|
||||
- type: bind
|
||||
source: ./nginx/log
|
||||
target: /var/log/nginx
|
||||
|
33
nginx/Demo/TwoNodes/keepalived/conf/keepalived.conf
Normal file
33
nginx/Demo/TwoNodes/keepalived/conf/keepalived.conf
Normal file
@@ -0,0 +1,33 @@
|
||||
global_defs {
|
||||
router_id nginx1 # 在另一台服务器中,这里配置 nginx2
|
||||
script_user root
|
||||
enable_script_security
|
||||
}
|
||||
|
||||
vrrp_script chk_nginx {
|
||||
script "/sbin/ss -lnt | grep -q ':80\>'"
|
||||
interval 10
|
||||
weight 0
|
||||
fall 2
|
||||
rise 2
|
||||
}
|
||||
|
||||
vrrp_instance VI_1 {
|
||||
state BACKUP
|
||||
virtual_router_id 14
|
||||
priority 150 # 在另一台服务器中,这里配置100
|
||||
advert_int 2
|
||||
nopreempt
|
||||
interface eth0 # 这里的 eth0 是服务器的网卡名
|
||||
track_script {
|
||||
chk_nginx
|
||||
}
|
||||
authentication {
|
||||
auth_type PASS
|
||||
auth_pass El_en_nginx_1234
|
||||
}
|
||||
virtual_ipaddress {
|
||||
虚拟IP/掩码 dev eth0 # 这里的eth0是服务器的网卡名
|
||||
}
|
||||
}
|
||||
|
5
nginx/Demo/TwoNodes/nginx/http.d/80.conf
Normal file
5
nginx/Demo/TwoNodes/nginx/http.d/80.conf
Normal file
@@ -0,0 +1,5 @@
|
||||
server {
|
||||
listen 80;
|
||||
location / {}
|
||||
}
|
||||
|
Reference in New Issue
Block a user