日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

主nginx linux,Linux-实现双主模型的nginx的高可用

發布時間:2025/3/19 linux 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 主nginx linux,Linux-实现双主模型的nginx的高可用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1 [root@234c17 ~]# for i in {1..4};do curl www.a.com;curl www.b.com;sleep 1;done

2 234.57

3 234.77

4 234.47

5 234.67

6 234.57

7 234.77

8 234.47

9 234.67

過程:

一、先配置4臺real_server,安裝好測試用的httpd

1 [root@234c47 ~]# curl 192.168.234.47;curl 192.168.234.57;curl 192.168.234.67;curl 192.168.234.77

2 234.47

3 234.57

4 234.67

5 234.77

二、配置keepalived

因為是雙主模型

1.配置keepalived主機234.27

[root@234c27 ~]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

root@localhost

}

notification_email_from keepalived@localhost

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id kpone

vrrp _mcast_group4 234.10.10.10

}

vrrp_instance VI_1 {

state MASTER

interface ens33

virtual_router_id 50

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

172.18.0.100/16 //這ip調度 192.168.234.47/57

}

}

vrrp_instance VI_2 {

state BACKUP

interface ens33

virtual_router_id 51

priority 80

advert_int 1

authentication {

auth_type PASS

auth_pass 2222

}

virtual_ipaddress {

172.18.0.200/16 //這ip調度 192.168.234.147/157

}

}

2.配置keepalived主機234.37

[root@234c37 ~]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

root@localhost

}

notification_email_from keepalived@localhost

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id kpone

vrrp _mcast_group4 234.10.10.10

}

vrrp_instance VI_1 {

state BACKUP

interface ens33

virtual_router_id 50

priority 80

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

172.18.0.100/16 //這ip調度 192.168.234.47/57

}

}

vrrp_instance VI_2 {

state MASTER

interface ens33

virtual_router_id 51

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 2222

}

virtual_ipaddress {

172.18.0.200/16 //這ip調度 192.168.234.147/157

}

}

這樣雙主模型簡單的就搭建好了

3.配置nginx主機234.27/37

先配置http語塊

http {

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 /var/log/nginx/access.log main;

upstream web1{//

server 192.168.234.47:80;

server 192.168.234.57:80;

}

upstream web2{

server 192.168.234.67:80;

server 192.168.234.77:80;

}

#zs#

ngx_http_upstream_module

ngx_http_upstream_module模塊

用于將多個服務器定義成服務器組,而由proxy_pass, fastcgi_pass等指令

進行引用

1、upstream name { ... }

定義后端服務器組,會引入一個新的上下文

默認調度算法是wrr

Context: http

upstream httpdsrvs {

server ...

server...

...

#fzs#

然后配置server

server {

listen 80 default_server; //默認監聽80端口

server_name www.a.com//域名

listen [::]:80 default_server;

root /usr/share/nginx/html;

# Load configuration files for the default server block.

include /etc/nginx/default.d#zs#.conf;

location / {

proxy_pass http://web1 ; //定義訪問80端口的請求,以web1提供服務。而指定的web1在http語塊中為 192.168.234.47/57:80 提供服務

}

error_page 404 /404.html;

location = /40x.html {

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

}

server {

server_name www.b.com

listen 80;

location / {

proxy_pass http://web2 ; //定義訪問80端口的請求,以web2提供服務。而指定的web2在http語塊中為 192.168.234.147/157:80 提供服務

}

}

}

這樣訪問 www.a.com就是訪問192.168.234.47/57:80

訪問 www.b.com就是訪問192.168.234.67/77:80

現在客戶機將host添加www.a/b.com

172.18.0.100 www.a.com

172.18.0.200www.b.com

客戶端將www.a.com 解析 172.18.0.100

[root@234c17 ~]# ping www.a.com

PING www.a.com (172.18.0.100) 56(84) bytes of data.

64 bytes from www.a.com (172.18.0.100): icmp_seq=1 ttl=64 time=0.358 ms

64 bytes from www.a.com (172.18.0.100): icmp_seq=2 ttl=64 time=0.376 ms

64 bytes from www.a.com (172.18.0.100): icmp_seq=3 ttl=64 time=0.358 ms

64 bytes from www.a.com (172.18.0.100): icmp_seq=4 ttl=64 time=0.366 ms

客戶端將www.b.com 解析 172.18.0.200

[root@234c17 ~]# ping www.b.com

PING www.b.com (172.18.0.200) 56(84) bytes of data.

64 bytes from www.b.com (172.18.0.200): icmp_seq=1 ttl=64 time=0.582 ms

64 bytes from www.b.com (172.18.0.200): icmp_seq=2 ttl=64 time=0.339 ms

64 bytes from www.b.com (172.18.0.200): icmp_seq=3 ttl=64 time=0.524 ms

64 bytes from www.b.com (172.18.0.200): icmp_seq=4 ttl=64 time=0.337 ms

結果:

1 [root@234c17 ~]# for i in {1..4};do curl www.a.com;curl www.b.com;sleep 1;done

2 234.57

3 234.77

4 234.47

5 234.67

6 234.57

7 234.77

8 234.47

9 234.67

實現雙主模型的ngnix高可用(二)

現在擴展實驗

將192.168.234.47/57主機加ip地址

[root@234c47 ~]#ip a a dev ens37 192.168.167/24

[root@234c57 ~]#ip a a dev ens37 192.168.177/24

編輯http的的配置文件增加基于FQDN虛擬主機

[root@234c47 ~]# vim /etc/httpd/conf.d/vhost.conf

documentroot /data/web1

servername www.a.com

< directory /data/web1>

require all granted

< /directory>

< /virtualhost>

另一個主機也加上虛擬主機

[root@234c57 ~]# vim /etc/httpd/conf.d/vhost.conf

documentroot /data/web1

servername www.a.com

require all granted

< /directory>

< /virtualhost>

重啟httpd服務

1 [root@234c17 ~]# for i in {1..8};do curl www.a.com;done

2 234.167

3 234.177

4 234.47

5 234.57

6 234.167

7 234.167

8 234.177

9 234.47

10

1 [root@234c17 ~]# for i in {1..8};do curl www.b.com;done

2 234.67

3 234.67

4 234.77

5 234.67

6 234.77

7 234.67

8 234.77

9 234.77

10

總結

以上是生活随笔為你收集整理的主nginx linux,Linux-实现双主模型的nginx的高可用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。