您好,登錄后才能下訂單哦!
這篇文章主要介紹“l(fā)vs+并發(fā)的優(yōu)化方法教程”,在日常操作中,相信很多人在lvs+并發(fā)的優(yōu)化方法教程問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”lvs+并發(fā)的優(yōu)化方法教程”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
在一次實(shí)際項(xiàng)目中,lvs 只能承載量很低,需要對(duì)lvs和Linux內(nèi)核參數(shù)進(jìn)行優(yōu)化。
(1)LVS可以實(shí)現(xiàn)負(fù)載均衡,但是不能夠進(jìn)行健康檢查。比如一個(gè)RS出現(xiàn)故障,LVS 仍然會(huì)把請(qǐng)求轉(zhuǎn)發(fā)給故障的RS服務(wù)器,這樣就會(huì)導(dǎo)致請(qǐng)求的無(wú)效性;keepalived 軟件可以進(jìn)行健康檢查。
(2)使用keepalived能同時(shí)實(shí)現(xiàn) LVS 的高可用性,解決 LVS 單點(diǎn)故障的問(wèn)題。
注意:
(1)lvs+keepalived至少需要2臺(tái)服務(wù)器。
(2)需要一個(gè)VIP。
(3)RS服務(wù)器不能和LVS以及Keepalived復(fù)用。
安裝ipvs和keepalived
yum install ipvsadm keepalived -y
keepalived配置
注意:
(1)keepalived是否需要爭(zhēng)搶主IP,如果不需要,需要把state都修改為BACKUP,并配置nopreempt。
(2)persistence_timeout的作用是:在一定時(shí)間內(nèi)使來(lái)自于同一個(gè)Client的所有TCP請(qǐng)求被負(fù)載到同一個(gè)RealServer上,查看ipvsadm -S -n
主節(jié)點(diǎn)
#主節(jié)點(diǎn)( MASTER )配置文件 cat > /etc/keepalived/keepalived.conf <<'EOF' ! Configuration File for keepalived global_defs { router_id LVS_DEVEL } vrrp_instance VI_1 { state BACKUP ! 主為master,不爭(zhēng)搶模式改為BACKUP nopreempt !不爭(zhēng)搶模式添加 interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.112.10 } } virtual_server 192.168.112.10 80 { delay_loop 6 lb_algo rr lb_kind DR ! persistence_timeout 0 protocol TCP real_server 192.168.112.13 80 { weight 1 TCP_CHECK { connect_timeout 10 retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.112.14 80 { weight 1 TCP_CHECK { connect_timeout 10 retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.112.15 80 { weight 1 TCP_CHECK { connect_timeout 10 retry 3 delay_before_retry 3 connect_port 80 } } } EOF
從節(jié)點(diǎn)
cat > /etc/keepalived/keepalived.conf <<'EOF' ! Configuration File for keepalived global_defs { router_id LVS_DEVEL } vrrp_instance VI_1 { state BACKUP nopreempt ! 不爭(zhēng)搶模式添加 interface eth0 virtual_router_id 51 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.112.10 } } virtual_server 192.168.112.10 80 { delay_loop 6 lb_algo rr lb_kind DR ! persistence_timeout 0 protocol TCP real_server 192.168.112.13 80 { weight 1 TCP_CHECK { connect_timeout 10 retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.112.14 80 { weight 1 TCP_CHECK { connect_timeout 10 retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.112.15 80 { weight 1 TCP_CHECK { connect_timeout 10 retry 3 delay_before_retry 3 connect_port 80 } } } EOF
內(nèi)核參數(shù)
echo 1 > /proc/sys/net/ipv4/ip_forward sysctl -w net.ipv4.ip_forward=1
啟動(dòng)
systemctl enable keepalived systemctl start keepalived
配置腳本
不需要在lvs+keepalived的服務(wù)器上配置,需要在所有的真實(shí)服務(wù)器上配置。注意vip必須與前面keepalived上的vip相同。
# vim lvs_dr_rs.sh SNS_VIP=192.168.112.10 /etc/rc.d/init.d/functions case "$1" in start) ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP /sbin/route add -host $SNS_VIP dev lo:0 echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce sysctl -p >/dev/null 2>&1 echo "RealServer Start OK" ;; stop) ifconfig lo:0 down route del $SNS_VIP >/dev/null 2>&1 echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce echo "RealServer Stoped" ;; *) echo "Usage: $0 {start|stop}" exit 1 esac exit 0 執(zhí)行生效 # 所有RS節(jié)點(diǎn)上分別執(zhí)行腳本: chmod +x lvs_dr_rs.sh ./lvs_dr_rs.sh start
增大ipvs模塊hash table的大小
ipvs模塊hash table默認(rèn)值為2^12=4096,改為2^20=1048576??梢杂胕pvsadm -l命令查詢當(dāng)前hash table的大小。
IP Virtual Server version 1.2.1 (size=4096)
修改方法:
在/etc/modprobe.d/目錄下添加文件ip_vs.conf,內(nèi)容為:
options ip_vs conn_tab_bits=20
重新加載ipvs模塊。
IP Virtual Server version 1.2.1 (size=1048576)
修改 LVS 表中的 timeout
ipvsadm --set 900 60 300 ipvsadm -ln --timeout Timeout (tcp tcpfin udp): 900 60 300
* soft nofile 1024000 * hard nofile 1024000 * soft nproc 1024000 * hard nproc 1024000
fs.file-max = 1048576 net.ipv4.ip_forward = 1 net.core.wmem_default = 8388608 net.core.wmem_max = 16777216 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.somaxconn = 65535 net.core.optmem_max = 81920 net.core.netdev_max_backlog = 262144 net.ipv4.route.gc_timeout = 20 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_abort_on_overflow = 1 net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.tcp_sack = 1 net.ipv4.tcp_window_scaling = 1 net.ipv4.tcp_no_metrics_save = 1 net.ipv4.tcp_rmem = 32768 131072 16777216 net.ipv4.tcp_wmem = 8192 131072 16777216 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_max_syn_backlog = 262144 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_fin_timeout = 10 net.ipv4.tcp_keepalive_time = 120 net.ipv4.tcp_keepalive_probes = 3 net.ipv4.tcp_keepalive_intvl = 15 net.ipv4.tcp_retries2 = 5 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 #modprobe ip_conntrack net.netfilter.nf_conntrack_tcp_timeout_established = 180 net.netfilter.nf_conntrack_max = 1048576 net.nf_conntrack_max = 1048576 kernel.sysrq = 0 kernel.core_uses_pid = 1 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296
注意:
net.ipv4.tcp_tw_recycle = 1有坑,在nat環(huán)境下慎用。越是大并發(fā),越要注意net.ipv4.tcp_max_tw_buckets的值不能太大。
到此,關(guān)于“l(fā)vs+并發(fā)的優(yōu)化方法教程”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。