1. Server端、client端都需要安装keepalived httpd服务
yum install -y httpd keepalived
2. Server端:
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node3.tao.com
}
vrrp_instance websrv {
state MASTER <==指定此节点为 Master 节点
interface br0(修改成本机使用的网卡) <==指定监听的网卡
virtual_router_id 51
priority 100 <==指定优先级,数字越高约优先
advert_int 1 <==心跳监测,单位为 s
authentication {
auth_type PASS <==设定验证方式
auth_pass 1111 <==设定密码为 1111
}
virtual_ipaddress {
192.168.123.250 <==指定 VIP
}
}
保存后 重启 keepalived服务
之后在/var/www/html/中写一个测试页
vi index.html
server.tao.com
保存后 重启httpd服务
3. Client端
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node4.tao.com
}
vrrp_instance websrv {
state MASTER <==指定此节点为 Master 节点
interface br0(修改成本机使用的网卡) <==指定监听的网卡
virtual_router_id 51
priority 50 <==指定优先级,数字越高约优先
advert_int 1 <==心跳监测,单位为 s
authentication {
auth_type PASS <==设定验证方式
auth_pass 1111 <==设定密码为 1111
}
virtual_ipaddress {
192.168.123.250 <==指定 VIP
}
}
保存后 重启 keepalived服务
之后在/var/www/html/中写一个测试页
Vi index.html
Server.tao.com
保存后 重启httpd服务
4. 测试结果
在server 和client端 keepalived都正常 显示的是server端页面
Server端关闭keepalived模拟宕机 显示的就是client端
1.使用docker commit构建镜像
创建环境
[root@xiongan /]# yum clean all
[root@xiongan /]# yum install -y httpd
[root@xiongan /]# vi /var/www/html/index.html
[root@xiongan /]# httpd -k start #使httpd服务立即生效
【扩展】:
[root@xiongan /]# curl http://172.17.0.2
hello,docker-xiongan
#使用docker commit 构建新的镜像
[root@docker-tz ~]# docker commit xiongan centos-httpd:v1
2.使用docker build构建镜像-Dockerfile
编辑脚本内容
Dockerfile:
FROM centos:7
MAINTAINER "tz taozi@taozi.com"
RUN yum clean all
RUN yum -y install httpd
ADD run-httpd.sh /run-httpd.sh
RUN chmod 755 /run-httpd.sh
ADD index.html /var/www/html
EXPOSE 80
WORKDIR /
CMD ["/bin/bash","/run-httpd.sh"]
run-httpd.sh:
#! /bin/bash
rm -rf /run/httpd*
exec /sbin/httpd -D FOREGROUND
[root@docker-tz dockerbuild]# docker build -t centos-test:v1 .
#末尾有个. 不要丢掉 代表当前运行目录下的脚本文件