第1章 keepalived高级内容
1.1 创建一个nginx脚本,模仿一个nginx服务
mkdir -p /server/scripts/ echo 'sleep 1000000000' >/server/scripts/nginx.sh sh /server/scripts/nginx.sh &
1.2 写一个监控脚本服务
[root@lb01 ~]# cat /server/scripts/check_web.sh
#!/bin/bash if [ `ps -ef |grep -c "[n]ginx"` -ne 1 ];then service keepalived stop fi
1.2.1 给这个脚本一个执行权限
chmod +x /server/scripts/check_web.sh
1.3 修改keepalived.conf配置文件
global_defs { router_id LVS_01 } vrrp_script check_web.sh { script "/server/scripts/check_web.sh" interval 2 weight 2 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.0.0.3/24 dev eth0 label eth0:1 } track_script { check_web.sh } } vrrp_instance VI_2 { state BACKUP interface eth0 virtual_router_id 52 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.0.0.4/24 dev eth0 label eth0:2 } track_script { check_web.sh } } ####lb01 配置
1.4 重启keepalived.conf服务
[root@lb01 ~]# /etc/init.d/keepalived restart
1.5 把lb01上的nginx服务停掉
[root@lb01 ~]# pkill -f nginx
[root@lb01 ~]# pkill -f nginx
[root@lb01 ~]# ps -ef |grep nginx
root 21732 21419 0 16:11 pts/1 00:00:00 grep --color=auto nginx
1.6 在lb02上检查是否keepalived飘逸成功
[root@lb02 ~]# ip a |egrep "0.3|0.4"
inet 10.0.0.4/24 scope global secondary eth0:2
inet 10.0.0.3/24 scope global secondary eth0:1
第2章 检查nginx是否存活的方法:不少与4中方法,检查某一个端口是否开启
1、curl
2、ps -ef
某一个端口
1、netstat/ss -tunlp|grep 22
2、telnet 10.0.0.200 22
3、nc 10.0.0.200 22
4、nmap -p22 localhost nmap -p1-65535 www.baiud.com
nmap -p1-1024 10.0.0.0/24
第3章 当用户在浏览器中输入www.oldboyedu.com 到页面显示内容 发生了什么?
3.1 DNS解析过程
1.www.oldboyedu.com ----->ip地址 (VIP)
dig +trace www.oldboyedu.com
3.2 域名与ip地址对应关系
1.ip与域A记录
blog.oldboyedu.com 101.200.195.98
2.别名CNAME
访问百度的域名时,百度会给你一个别名:www.a.shifen.com
www.a.shifen.com www.baidu.com
3.3 负载均衡
3.3.1 负载均衡与反向代理
http请求与http响应curl -v 先http请求和响应的详细过程
请求头
User-Agent: 用户客户端-用户使用的浏览器
Host: 访问的网站名字 域名
[root@lb01 ~]# curl -v www.baidu.com
* About to connect() to www.baidu.com port 80 (#0) * Trying 61.135.169.125... connected * Connected to www.baidu.com (61.135.169.125) port 80 (#0) > GET / HTTP/1.1 ###请求的起始行 > User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2 > Host: www.baidu.com > Accept: */* > User-Agent: 用户客户端-用户使用的浏览器 Host: 访问的网站名字 域名 403 forbidden 权限拒绝 nginx 你访问的首页文件没了 304 not modified 读取的缓存 < HTTP/1.1 200 OK < Server: bfe/1.0.8.18 < Date: Mon, 04 Sep 2017 09:07:36 GMT < Content-Type: text/html < Content-Length: 2381 < Last-Modified: Mon, 23 Jan 2017 13:27:32 GMT < Connection: Keep-Alive < ETag: "588604c4-94d" < Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform < Pragma: no-cache < Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/ < Accept-Ranges: bytes < <!DOCTYPE html>
3.4 谷歌浏览器chrome 按F12 查=
firefox firebug插件
www.etiantian.org
bbs.etiantian.org
blog.etiantian.org
edu.etiantian.org
img.etiantian.org
video.etiantian.org
proxy_set_header 修改请求头, 反向代理向后面节点请求的时候 请求头
proxy_set_header Host $host;
web服务器想要记录用户的真实IP地址
proxy_set_header X-Forwarded-For $remote_addr;
3.5 反向代理
nginx 7层和4层
haproxy 4层和7层
3.6 负载均衡
lvs 4层
根据用户使用的浏览器进行转发
$http_user_agent
Host ===》$host
User-Agent ===》$http_user_agent
nginx 日志格式 $remote_addr
$status
3.7 web服务器 lnmp
linux nginx mysql php
linux nginx mysql tomcat
容器-----运行和解释对应的语言
tomcat 运行 java
php 运行 php
nginx 运行 html 静态
服务器环境
业务流程
3.8 nfs 存储可以使用
keepalived+rsync+sersync
DRBD+HartBeat
主活着的时候,备节点不可用。
分布式存储 一个数据分为多份存储。
mfs fastdfs glusterfs
select
update
alter
3.9 MySQL
主从同步,读负载均衡 -读写分离用到的软件
atlas
mycat