文章目录
LVS模型搭建
docker 搭建 参见 linux上搭建docker服务
1. 使用docker创建LVS环境
按照步骤一步一步来,基本都会成功的
1.1 使用docker创建服务器
负载均衡服务器-lvs-server
Dockerfile
FROM centos:7
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
ADD conf/ipvsadm /etc/sysconfig/
RUN yum -y install net-tools
RUN yum -y install ipvsadm
RUN yum install -y gcc make vim ipvsadm iproute2
EXPOSE 80
CMD ["/usr/sbin/init"]
conf/ipvsadm文件内容
# Unload modules on restart and stop
# Value: yes|no, default: yes
# This option has to be 'yes' to get to a sane state for a ipvs
# restart or stop. Only set to 'no' if there are problems unloading ipvs
# modules.
IPVS_MODULES_UNLOAD="yes"
# Save current ipvs rules on stop.
# Value: yes|no, default: no
# Saves all ipvs rules to /etc/sysconfig/ipvsadm if ipvsadm gets stopped
# (e.g. on system shutdown).
IPVS_SAVE_ON_STOP="no"
# Save current ipvs rules on restart.
# Value: yes|no, default: no
# Saves all ipvs rules to /etc/sysconfig/ipvsadm if ipvsadm gets
# restarted.
IPVS_SAVE_ON_RESTART="no"
# Numeric status output
# Value: yes|no, default: yes
# Print IP addresses and port numbers in numeric format in the status output.
IPVS_STATUS_NUMERIC="yes"
镜像构建命令
$ docker build --rm -t local/c7-ipvs .
启动命令
$ docker run -d -it --privileged -p 80:8