【frontend】前端frontend的安裝與配置

一割以、實(shí)驗(yàn)環(huán)境


操作系統(tǒng):CentOS7.2?Mininal

serverA:192.168.1.104

serverB:192.168.1.109

VIP:???????192.168.1.110

test: ? ? ?192.168.1.120

二、軟件安裝

在serverA?和?serverB?上

#?yum??-y?install??nginx bind? ntp ?keepalived?

#?systemctl??enable??named??ntpd??nginx?keepalived

三、特殊配置

在serverA?和?serverB?上

#?sysctl?-w?net.ipv4.ip_nonlocal_bind=1

#?echo?"net.ipv4.ip_nonlocal_bind=1"?>>?/etc/sysctl.conf

注:更改Linux系統(tǒng)控制文件巫糙,使得端口即使監(jiān)聽在不存在的IP上旦签,也不報錯

#?setenforce?0

#?sed?-i?'s/^SELINUX=.*/SELINUX=permissive/g'???/etc/selinux/config


#?systemctl?stop???firewalld

#?systemctl?diable?firewalld


三、serverA服務(wù)配置

# vim ?/etc/keepalived/keepalived.conf

##############################

! Configuration File for keepalived

global_defs {

? ?router_id LVS_DEVEL

}

vrrp_script check {?

? ? script "/etc/keepalived/check.sh"?

? ? interval 5 ? ??

} ??

vrrp_instance VI_1 {

? ? state BACKUP

? ? interface eno16777736

? ? virtual_router_id 100

? ? priority 100

? ? advert_int 1

? ? nopreempt

? ? authentication {

? ? ? ? auth_type PASS

? ? ? ? auth_pass 1111

? ? }

? ? track_script { ??

? ? ? check

? ? } ??

? ? virtual_ipaddress {

? ? ? ? 192.168.1.110

? ? }

}

##############################

注意:?vrrp_script{}中的interval時間需大于腳本中的sleep時間肪跋!

# ?vim /etc/keepalived/check.sh

##############################

#!/bin/bash

nginx_status1=$(ps -C nginx --no-heading|wc -l)

if [ "${nginx_status1}" = "0" ]; then

? systemctl start nginx.service

? sleep 3

? nginx_status2=$(ps -C nginx --no-heading|wc -l)

? if [ "${nginx_status2}" = "0" ]; then

? ? systemctl stop keepalived.service

? fi

fi

named_status1=$(ps -C named --no-heading|wc -l)

if [ "${named_status1}" = "0" ]; then

? systemctl start named.service

? sleep 3

? named_status2=$(ps -C named --no-heading|wc -l)

? if [ "${named_status2}" = "0" ]; then

? ? systemctl stop keepalived.service

? fi

fi

ntpd_status1=$(ps -C ntpd --no-heading|wc -l)

if [ "${ntpd_status1}" = "0" ]; then

? systemctl start ntpd.service

? sleep 3

? ntpd_status2=$(ps -C ntpd --no-heading|wc -l)

? if [ "${ntpd_status2}" = "0" ]; then

? ? systemctl stop keepalived.service

? fi

fi

#######################################

# chmod +x ?/etc/keepalived/check.sh

#?vim ?/etc/ntp.conf

########################################

driftfile /var/lib/ntp/drift

restrict default nomodify notrap nopeer noquery

restrict 127.0.0.1

restrict ::1

restrict 192.168.1.0 mask 255..255.255.0 nomodify notrap

server 192.168.1.110 iburst

server 127.127.1.0

fudge 127.127.1.0 stratum 10

interface ignore ?wildcard

interface listen ?192.168.1.110

interface listen ?127.0.0.1

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

disable monitor

##########################################

# vim /etc/named.conf

##########################################

options {

? ? ? ? listen-on port 53 { 192.168.1.110; };

? ? ? ? listen-on-v6 port 53 { ::1; };

? ? ? ? directory ? ? ? "/var/named";

? ? ? ? dump-file ? ? ? "/var/named/data/cache_dump.db";

? ? ? ? statistics-file "/var/named/data/named_stats.txt";

? ? ? ? memstatistics-file "/var/named/data/named_mem_stats.txt";

? ? ? ? allow-query ? ? { any; };

? ? ? ? recursion yes;

? ? ? ? dnssec-enable yes;

? ? ? ? dnssec-validation yes;

? ? ? ? pid-file "/run/named/named.pid";

};

zone "test.com" IN {

? ? ? ? type master;

? ? ? ? file "test.com.zone";

};

###############################################

# cp ?-p ?/var/named/named.localhost ? ?/var/named/test.com.zone

# vim??/var/named/test.com.zone



# vim /etc/nginx/nginx.conf

#########################################

# ? ?For more information on configuration, see:

# ? * Official English Documentation:http://nginx.org/en/docs/

# ? * Official Russian Documentation:http://nginx.org/ru/docs/

user nginx;

worker_processes auto;

error_log /var/log/nginx/error.log;

pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events {

? ? worker_connections ?1024;

}

# stream轉(zhuǎn)發(fā)

stream {

# ? ?hash $remote_addr consistent;

? ? proxy_connect_timeout 3s;

? ? include /etc/nginx/conf.d/stream_proxy.conf;

}

# http轉(zhuǎn)發(fā)

http {

? ? client_max_body_size ? ? 500M;

? ? include ? ? ? ? ? ? ? ? ? ? ? ? ? ? mime.types;

? ? default_type ? ? ? ? ? ? ? ? ? ? application/octet-stream;

? ? server_tokens ? ? ? ? ? ? ? ? ? off;

? ? sendfile ? ? ? ? ? ? ? ? ? ? ?? ? ? on;

? ? keepalive_timeout ? ? ? ? ? 65;

? ? include /etc/nginx/conf.d/http_proxy.conf;

}

############################################

# ?vim ?/etc/nginx/conf.d/stream_proxy.conf

#############################################

upstream stream_service?{

? ? hash $remote_addr consistent;

? ? server192.168.1.103:12345? ? ? ? max_fails=1 fail_timeout=180s;

? ? server 192.168.1.104:12345? ? ? ?max_fails=1 fail_timeout=180s;


}

server {

? ? listen 192.168.1.110:54321;

? ? proxy_pass stream_service;

}

#####################################################

# ?vim /etc/nginx/conf.d/http_proxy.conf

#####################################################

upstream http_service?{

? ? server 192.168.1.107:443 ? ? ?max_fails=1 fail_timeout=180s;

? ? server 192.168.1.108:443 ? ? ? max_fails=1 fail_timeout=180s;


? }

server {

? ? listen 192.168.1.110:443 ssl;

? ? ssl_certificate ? ? ? ? ?/etc/nginx/ssl/nginx-selfsigned.crt;

? ? ssl_certificate_key ?/etc/nginx/ssl/nginx-selfsigned.key;

? ? location / {

? ? ? ? proxy_connect_timeout ? ? 3;

? ? ? ? proxy_send_timeout ? ? ? ? 600;

? ? ? ? proxy_read_timeout ? ? ? ?? 600;

? ? ? ? send_timeout ? ? ? ? ? ? ? ? ?? 600;

? ? ? ? proxy_set_header ? ? ? ? ?? X-Real-IP $remote_addr;

? ? ? ? proxy_set_header ? ? ? ?? ? X-Forwarded-For $proxy_add_x_forwarded_for;

? ? ? ? ?proxy_pass ?https://http_service;

? ? }

}

#################################################################

# mkdir ?/etc/nginx/ssl

# openssl req ?-x509 ?-nodes \

? ? -newkey rsa:2048 \

? ? -days 365 \

? ? -subj "/C=CN/ST=Gunagdong/L=Shenzhen/O=TEST/OU=TEST/CN=www.test.com" \

? ? -keyout /etc/nginx/ssl/nginx-selfsigned.key \

? ? -out /etc/nginx/ssl/nginx-selfsigned.crt

四歧蒋、serverB服務(wù)配置

# vim ?/etc/keepalived/keepalived.conf

##########################

! Configuration File for keepalived

global_defs {

? ?router_id LVS_DEVEL

}

vrrp_script check {?

? ? script "/etc/keepalived/check.sh"?

? ? interval 5 ? ??

} ??

vrrp_instance VI_1 {

? ? state BACKUP

? ? interface eno16777736

? ? virtual_router_id 100

? ? priority 90

? ? advert_int 1

? ? authentication {

? ? ? ? auth_type PASS

? ? ? ? auth_pass 1111

? ? }

? ? track_script { ??

? ? ? check

? ? } ??

? ? virtual_ipaddress {

? ? ? ? 192.168.1.110

? ? }

}

##############################

注意:?vrrp_script{}中的interval時間需大于腳本中的sleep時間!

# ?vim /etc/keepalived/check.sh


##############################

#!/bin/bash

nginx_status1=$(ps -C nginx --no-heading|wc -l)

if [ "${nginx_status1}" = "0" ]; then

? systemctl start nginx.service

? sleep 3

? nginx_status2=$(ps -C nginx --no-heading|wc -l)

? if [ "${nginx_status2}" = "0" ]; then

? ? systemctl stop keepalived.service

? fi

fi

named_status1=$(ps -C named --no-heading|wc -l)

if [ "${named_status1}" = "0" ]; then

? systemctl start named.service

? sleep 3

? named_status2=$(ps -C named --no-heading|wc -l)

? if [ "${named_status2}" = "0" ]; then

? ? systemctl stop keepalived.service

? fi

fi

ntpd_status1=$(ps -C ntpd --no-heading|wc -l)

if [ "${ntpd_status1}" = "0" ]; then

? systemctl start ntpd.service

? sleep 3

? ntpd_status2=$(ps -C ntpd --no-heading|wc -l)

? if [ "${ntpd_status2}" = "0" ]; then

? ? systemctl stop keepalived.service

? fi

fi

#######################################

# chmod +x ?/etc/keepalived/check.sh

#?vim ?/etc/ntp.conf

########################################

driftfile /var/lib/ntp/drift

restrict default nomodify notrap nopeer noquery

restrict 127.0.0.1

restrict ::1

restrict 192.168.1.0 mask 255..255.255.0 nomodify notrap

server 192.168.1.110 iburst

server 127.127.1.0

fudge 127.127.1.0 stratum 10

interface ignore ?wildcard

interface listen ?192.168.1.110

interface listen ?127.0.0.1

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

disable monitor

##########################################

# vim /etc/named.conf

##########################################

options {

? ? ? ? listen-on port 53 { 192.168.1.110; };

? ? ? ? listen-on-v6 port 53 { ::1; };

? ? ? ? directory ? ? ? "/var/named";

? ? ? ? dump-file ? ? ? "/var/named/data/cache_dump.db";

? ? ? ? statistics-file "/var/named/data/named_stats.txt";

? ? ? ? memstatistics-file "/var/named/data/named_mem_stats.txt";

? ? ? ? allow-query ? ? { any; };

? ? ? ? recursion yes;

? ? ? ? dnssec-enable yes;

? ? ? ? dnssec-validation yes;

? ? ? ? pid-file "/run/named/named.pid";

};

zone "test.com" IN {

? ? ? ? type master;

? ? ? ? file "test.com.zone";

};

###############################################

# cp ?-p ?/var/named/named.localhost ? ?/var/named/test.com.zone

# vim??/var/named/test.com.zone


# vim /etc/nginx/nginx.conf

#########################################

# ? ?For more information on configuration, see:

# ? * Official English Documentation:http://nginx.org/en/docs/

# ? * Official Russian Documentation:http://nginx.org/ru/docs/

user nginx;

worker_processes auto;

error_log /var/log/nginx/error.log;

pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events {

? ? worker_connections ?1024;

}

# stream轉(zhuǎn)發(fā)

stream {

# ? ?hash $remote_addr consistent;

? ? proxy_connect_timeout 3s;

? ? include /etc/nginx/conf.d/stream_proxy.conf;

}

# http轉(zhuǎn)發(fā)

http {

? ? client_max_body_size ? ? 500M;

? ? include ? ? ? ? ? ? ? ? ? ? ? ? ? ? mime.types;

? ? default_type ? ? ? ? ? ? ? ? ? ? application/octet-stream;

? ? server_tokens ? ? ? ? ? ? ? ? ? off;

? ? sendfile ? ? ? ? ? ? ? ? ? ? ?? ? ? on;

? ? keepalive_timeout ? ? ? ? ? 65;

? ? include /etc/nginx/conf.d/http_proxy.conf;

}

############################################

# ?vim ?/etc/nginx/conf.d/stream_proxy.conf

#############################################

upstream stream_service?{

? ? hash $remote_addr consistent;

? ? server192.168.1.103:12345? ? ? ? max_fails=1 fail_timeout=180s;

? ? server 192.168.1.104:12345? ? ? ?max_fails=1 fail_timeout=180s;

}

server {

? ? listen 192.168.1.110:54321;

? ? proxy_pass stream_service;

}

#####################################################

# ?vim /etc/nginx/conf.d/http_proxy.conf

#####################################################

upstream http_service?{

? ? server 192.168.1.107:443 ? ? ?max_fails=1 fail_timeout=180s;

? ? server 192.168.1.108:443 ? ? ??max_fails=1 fail_timeout=180s;

? }

server {

? ? listen 192.168.1.110:443 ssl;

? ? ssl_certificate ? ? ? ???/etc/nginx/ssl/nginx-selfsigned.crt;

? ? ssl_certificate_key??/etc/nginx/ssl/nginx-selfsigned.key;

? ? location / {

? ? ? ? proxy_connect_timeout ? ? 3;

? ? ? ? proxy_send_timeout ? ? ? ? 600;

? ? ? ? proxy_read_timeout ? ? ? ?? 600;

? ? ? ? send_timeout ? ? ? ? ? ? ? ? ?? 600;

? ? ? ? proxy_set_header ? ? ? ? ?? X-Real-IP $remote_addr;

? ? ? ? proxy_set_header ? ? ? ?? ? X-Forwarded-For $proxy_add_x_forwarded_for;

? ? ? ? proxy_pass ?https://http_service;

? ? }

}

#################################################################

# mkdir ?/etc/nginx/ssl

# openssl req ?-x509 ?-nodes \

? ? -newkey rsa:2048 \

? ? -days 365 \

? ? -subj "/C=CN/ST=Gunagdong/L=Shenzhen/O=TEST/OU=TEST/CN=www.test.com" \

? ? -keyout /etc/nginx/ssl/nginx-selfsigned.key \

? ? -out /etc/nginx/ssl/nginx-selfsigned.crt

五州既、啟動服務(wù)

在serverA 和 serveB上

#?systemctl??start named??ntpd??nginx?keepalived

六谜洽、查看服務(wù)狀態(tài)

在serverA

在serverB


七、在test服務(wù)器上測試

反向代理測試:

https://192.168.1.110:443

DNS測試:

# vim ??/etc/resolv.conf

######################

nameserver 192.168.1.110

# Generated by NetworkManager

nameserver 202.96.128.166

nameserver 202.96.134.133

#####################

# ping www.test.com

# ping mysql.test.com

NTP測試:

# ntpdate 192.168.1.110

# vim ?/etc/ntp.conf


#########################

driftfile /var/lib/ntp/drift

restrict default nomodify notrap nopeer noquery

restrict 127.0.0.1

restrict ::1

server 192.168.1.110 iburst

restrict 192.168.1.110 nomodify notrap noquery

server 127.127.1.0

fudge 127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

disable monitor

#########################

# systemctl start ? ntpd

# systemctl enable ntpd

八吴叶、前端的高可用性測試

在 serverA

# systemctl ?restart keepalived

# systemctl ?status keepalived

# ip addr list

在 serverB

# systemctl ?status keepalived

# ip addr list

可以看到阐虚,重啟serverA的keepalived,VIP成功漂移了,實(shí)際上蚌卤,VIP所在的服務(wù)器上的 nginx实束、named 、ntpd任何一個服務(wù)出問題逊彭,keepalived的檢測腳本就會停其keepalived服務(wù)咸灿,使得VIP漂移,服務(wù)基本不受影響诫龙,實(shí)現(xiàn)高可用析显!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子谷异,更是在濱河造成了極大的恐慌分尸,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,546評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件歹嘹,死亡現(xiàn)場離奇詭異箩绍,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)尺上,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評論 3 395
  • 文/潘曉璐 我一進(jìn)店門材蛛,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人怎抛,你說我怎么就攤上這事卑吭。” “怎么了马绝?”我有些...
    開封第一講書人閱讀 164,911評論 0 354
  • 文/不壞的土叔 我叫張陵豆赏,是天一觀的道長。 經(jīng)常有香客問我富稻,道長掷邦,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,737評論 1 294
  • 正文 為了忘掉前任椭赋,我火速辦了婚禮抚岗,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘哪怔。我一直安慰自己宣蔚,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評論 6 392
  • 文/花漫 我一把揭開白布认境。 她就那樣靜靜地躺著件已,像睡著了一般。 火紅的嫁衣襯著肌膚如雪元暴。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,598評論 1 305
  • 那天兄猩,我揣著相機(jī)與錄音茉盏,去河邊找鬼。 笑死枢冤,一個胖子當(dāng)著我的面吹牛鸠姨,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播淹真,決...
    沈念sama閱讀 40,338評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼讶迁,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了核蘸?” 一聲冷哼從身側(cè)響起巍糯,我...
    開封第一講書人閱讀 39,249評論 0 276
  • 序言:老撾萬榮一對情侶失蹤啸驯,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后祟峦,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體罚斗,經(jīng)...
    沈念sama閱讀 45,696評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評論 3 336
  • 正文 我和宋清朗相戀三年宅楞,在試婚紗的時候發(fā)現(xiàn)自己被綠了针姿。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,013評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡厌衙,死狀恐怖距淫,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情婶希,我是刑警寧澤榕暇,帶...
    沈念sama閱讀 35,731評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站饲趋,受9級特大地震影響拐揭,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜奕塑,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評論 3 330
  • 文/蒙蒙 一堂污、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧龄砰,春花似錦盟猖、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,929評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至固蚤,卻和暖如春娘汞,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背夕玩。 一陣腳步聲響...
    開封第一講書人閱讀 33,048評論 1 270
  • 我被黑心中介騙來泰國打工你弦, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人燎孟。 一個月前我還...
    沈念sama閱讀 48,203評論 3 370
  • 正文 我出身青樓禽作,卻偏偏與公主長得像,于是被迫代替她去往敵國和親揩页。 傳聞我的和親對象是個殘疾皇子旷偿,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評論 2 355

推薦閱讀更多精彩內(nèi)容