您好,登錄后才能下訂單哦!
下文給大家帶來nginx + keepalived 是怎么樣實現高可用負載均衡的,希望能夠給大家在實際運用中帶來一定的幫助,負載均衡涉及的東西比較多,理論也不多,網上有很多書籍,今天我們就用億速云在行業內累計的經驗來做一個解答。
虛擬IP: 192.168.2.52
nginx-1: 192.168.2.50
nginx-2: 192.168.2.51
關閉/etc/sysconfig/selinux
SELINUX=disabled
nginx-1
yum install keepalived
vim /etc/keepalived/keepalived.conf
---------------------------------------------------
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER //定義為MASTER主機
interface eth0
virtual_router_id 51 //虛擬id
priority 100 //優先級
advert_int 1 //檢測間隔
authentication {
auth_type PASS //認證方式
auth_pass abcd //認證密碼
}
virtual_ipaddress {
192.168.2.52 //虛擬ip,即VIP
}
-------------------------------------------------
chkconfig keepalived on
service keepalived start
nginx-2
yum install keepalived
vim /etc/keepalived/keepalived.conf
--------------------------------------------------只改動如下
state BACKUP //定義為BACKUP
priority 99 //優先級
virtual_ipaddress {
192.168.2.52
}
-------------------------------------------------
chkconfig keepalived on
service keepalived start
ip a
已經綁定成功
檢測keepalived自動切換
客戶機:
ping 192.168.2.52 -t
nginx-1: 關閉keepalived服務
service keepalived stop
客戶機是否正常ping
安裝nginx
因為centos 沒有nginx,先安裝第三方epel-release源
yum install -y epel-release
yum install -y nginx
負載均衡
vi /etc/nginx/nginx.conf
添加以下內容
------------------------
# for more information.
include /etc/nginx/conf.d/*.conf;
upstream zhizhimao.com {
server 192.168.2.101:80; #web云服務器
server 192.168.2.100:80; #web云服務器
}
}
------------------------
反向代理
vi /etc/nginx/conf.d/default.conf
--------------------------------------------
server {
listen 80;
listen [::]:80default_server;
server_name zhizhimao.com; #如只做代理填寫IP
root /usr/share/nginx/html;
#Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://zhizhimao.com; #如只做代理填寫IP
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
-----------------------------------------------------
chkconfig nginx on
service nginx start
防火墻打開80端口
看了以上關于nginx + keepalived 是怎么樣實現高可用負載均衡的,如果大家還有什么地方需要了解的可以在億速云行業資訊里查找自己感興趣的或者找我們的專業技術工程師解答的,億速云技術工程師在行業內擁有十幾年的經驗了。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。