saltstack之keepalived的安装配置
使用saltstack编译安装keepalived:
创建相应的目录,并在目录下创建相应的sls配置文件
[root@node1 ~]# mkdir /srv/salt/prod/keepalived
[root@node1 ~]# mkdir /srv/salt/prod/keepalived/files
1、使用saltstack进行编译安装keepalived
1.1将下载好的keepalived源码包放置在keepalived目录下面的files目录中(files目录提供需要用的源码包,文件等)
[root@node1 etc]# pwd
/usr/local/src/keepalived-1.3.6/keepalived/etc
[root@node1 etc]# cp keepalived/keepalived.conf /srv/salt/prod/keepalived/files/
[root@node1 etc]# cp init.d/keepalived /srv/salt/prod/keepalived/files/keepalived.init
[root@node1 sysconfig]# pwd
/usr/local/src/keepalived-1.3.6/keepalived/etc/sysconfig
[root@node1 sysconfig]# cp keepalived /srv/salt/prod/keepalived/files/keepalived.sysconfig
查看files目录下面文件:
[root@node1 keepalived]# ll files/
total 696
-rw-r--r-- 1 root root 702570 Oct 10 22:21 keepalived-1.3.6.tar.gz
-rwxr-xr-x 1 root root 1335 Oct 10 22:17 keepalived.init
-rw-r--r-- 1 root root 667 Oct 10 22:28 keepalived.sysconfig
1.2haproxy的源码包和启动脚本准备好后,开始进行安装keepalived
[root@node1 keepalived]# pwd
/srv/salt/prod/keepalived
[root@node1 keepalived]# cat install.sls
include:
- pkg.pkg-init keepalived-install:
file.managed:
- name: /usr/local/src/keepalived-1.3.6.tar.gz
- source: salt://keepalived/files/keepalived-1.3.6.tar.gz
- user: root
- group: root
- mode: 755
cmd.run:
- name: cd /usr/local/src/ && tar xf keepalived-1.3.6.tar.gz && cd keepalived-1.3.6 && ./configure --prefix=/usr/local/keepalived --disable-fwmark && make && make install
- unless: test -d /usr/local/keepalived
- require:
- pkg: pkg-init
- file: keepalived-install keepalived-init:
file.managed:
- name: /etc/init.d/keepalived
- source: salt://keepalived/files/keepalived.init
- user: root
- group: root
- mode: 755
cmd.run:
- name: chkconfig --add keepalived
- unless: chkconfig --list|grep keepalived
- require:
- file: /etc/init.d/keepalived /etc/sysconfig/keepalived:
file.managed:
- source: salt://keepalived/files/keepalived.sysconfig
- user: root
- group: root
- mode: 644 /etc/keepalived:
file.directory:
- user: root
- group: root
- mode: 755
总结上面配置文件包括:1、include进来编译环境 2、编译安装keepalived 3、添加keepalived脚本文件,并添加到系统服务中 4、复制keepalived.sysconfig文件 5、创建keepalived配置文件目录
执行install.sls文件,安装keepalived:
[root@node1 keepalived]# salt 'node1' state.sls keepalived.install saltenv=prod
3、安装完keepalived后,并且keepalived已经有了启动脚本,接下来需要给keepalived提供配置文件,最后将keepalived服务开启,由于根据业务需求的不同,可能用到的keepalived的配置文件会有区别,
所以这里将配置文件与keepalived的安装分隔开进行状态管理配置,以后minion的keepalived可以根据配置文件的不同而提供安装
[root@node1 cluster]# pwd
/srv/salt/prod/cluster
[root@node1 cluster]# cat haproxy-outside-keepalived.sls haproxy与keepalived结合使用的高可用
include:
- keepalived.install keepalived-service:
file.managed:
- name: /etc/keepalived/keepalived.conf
- source: salt://cluster/files/haproxy-outside-keepalived.conf
- user: root
- group: root
- mode: 644
- template: jinja jinja模板调用,使用变量
{% if grains['fqdn'] == 'node1' %} 基于节点的fqdn信息来赋予变量值
- ROUTEID: haproxy_node1
- STATEID: MASTER
- PRIORITYID: 150
{% elif grains['fqdn'] == 'node2' %}
- ROUTEID: haproxy_node2
- STATEID: BACKUP
- PRIORITYID: 100
{% endif %}
service.running:
- name: keepalived
- enable: True
- reload: True
- watch:
- file: keepalived-service
总结上述配置文件内容:1、include进来keepalived的安装 2、给各节点提供不同的配置文件,用到了jinja模板调用grains 3、开启keepalived服务,并开启自启动
最后将keepalived项目添加到top.sls文件中:
[root@node1 base]# cat top.sls
base:
'*':
- init.env_init prod:
'node1':
- cluster.haproxy-outside
- cluster.haproxy-outside-keepalived
整个keepalived项目构架图:
[root@node1 keepalived]# tree
.
├── files
│ ├── keepalived-1.3.6.tar.gz
│ ├── keepalived.init
│ └── keepalived.sysconfig
└── install.sls 1 directory, 4 files
[root@node1 keepalived]# cd ../cluster/
[root@node1 cluster]# tree
.
├── files
│ ├── haproxy-outside.cfg
│ └── haproxy-outside-keepalived.conf
├── haproxy-outside-keepalived.sls
└── haproxy-outside.sls
node1节点安装没有问题,那么更改top.sls中节点设置,将node2节点也给添加上:
[root@node1 base]# cat top.sls
base:
'*':
- init.env_init prod:
'*': 只有两个节点,所以这里*代替了
- cluster.haproxy-outside
- cluster.haproxy-outside-keepalived
执行状态配置文件:
[root@node1 base]# salt '*' state.highstate
查看node2状态:
[root@node2 ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.44.10:80 0.0.0.0:* LISTEN 16791/haproxy
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1279/sshd
tcp 0 0 0.0.0.0:8090 0.0.0.0:* LISTEN 16791/haproxy
tcp 0 0 :::8080 :::* LISTEN 14351/httpd
tcp 0 0 :::22 :::* LISTEN 1279/sshd
udp 0 0 0.0.0.0:68 0.0.0.0:* 1106/dhclient
可以看见haproxy已经监听起来了,监听在了一个不是自己实际ip的地址上
查看node1的vip信息:
[root@node1 files]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:86:2C:63
inet addr:192.168.44.134 Bcast:192.168.44.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe86:2c63/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:230013 errors:0 dropped:0 overruns:0 frame:0
TX packets:172530 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:130350592 (124.3 MiB) TX bytes:19244347 (18.3 MiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:86:2C:63
inet addr:192.168.44.10 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:145196 errors:0 dropped:0 overruns:0 frame:0
TX packets:145196 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:12285984 (11.7 MiB) TX bytes:12285984 (11.7 MiB)
可以看见eth0:0就是vip,手动将keepalived停止,查看vip是否漂移到nide2?
[root@node1 files]# /etc/init.d/keepalived stop
Stopping keepalived: [ OK ]
查看node2状态:
[root@node2 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:34:32:CB
inet addr:192.168.44.135 Bcast:192.168.44.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe34:32cb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:494815 errors:0 dropped:0 overruns:0 frame:0
TX packets:357301 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:250265303 (238.6 MiB) TX bytes:98088504 (93.5 MiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:34:32:CB
inet addr:192.168.44.10 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2953 errors:0 dropped:0 overruns:0 frame:0
TX packets:2953 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1272983 (1.2 MiB) TX bytes:1272983 (1.2 MiB)
于是haproxy结合keepalived的高可用基于saltstack安装成功,下面为haproxy和keepalived的简单配置文件:
haproxy配置文件:
[root@node1 files]# pwd
/srv/salt/prod/cluster/files
[root@node1 files]# cat haproxy-outside.cfg
#
# This is a sample configuration. It illustrates how to separate static objects
# traffic from dynamic traffic, and how to dynamically regulate the server load.
#
# It listens on 192.168.1.10:80, and directs all requests for Host 'img' or
# URIs starting with /img or /css to a dedicated group of servers. URIs
# starting with /admin/stats deliver the stats page.
# global
maxconn 10000
stats socket /var/run/haproxy.stat mode 600 level admin
log 127.0.0.1 local0
uid 200
gid 200
chroot /var/empty
daemon defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms # The public 'www' address in the DMZ
frontend webserver
bind 192.168.44.10:80
default_backend web
#bind 192.168.1.10:443 ssl crt /etc/haproxy/haproxy.pem
mode http listen base_stats
bind *:8090
stats enable
stats hide-version
stats uri /haproxy?stats
stats realm "haproxy statistics"
stats auth wadeson:redhat # The static backend backend for 'Host: img', /img and /css.
backend web
balance roundrobin
retries 2
server web1 192.168.44.134:8080 check inter 1000
server web2 192.168.44.135:8080 check inter 1000
keepalived配置文件:
[root@node1 files]# cat haproxy-outside-keepalived.conf
! Configuration File for keepalived global_defs {
notification_email {
json_hc@163.com
}
notification_email_from json_hc@163.com
smtp_server smtp.163.com
smtp_connect_timeout 30
router_id {{ ROUTEID }}
} vrrp_instance VI_1 {
state {{ STATEID }}
interface eth0
virtual_router_id 51
priority {{ PRIORITYID }}
advert_int 1
authentication {
auth_type PASS
auth_pass password
}
virtual_ipaddress {
192.168.44.10/24 dev eth0 label eth0:0
}
}
查看高可用的负载效果:
saltstack之keepalived的安装配置的更多相关文章
- keepalived+haproxy 安装配置
1.安装配置keepalived 修改配置文件/etc/keepalived/keepalived.conf ! Configuration File for keepalived global_de ...
- keepalived+nginx安装配置
软件版本号: pcre8.36 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz keepalived1.2 ...
- saltstack之haproxy的安装配置
使用saltstack编译安装haproxy: 由于编译安装haproxy,所以安装之前需要建立编译环境,将编译环境需要安装的包单独放置在一个目录中,当编译haproxy或其他时,直接include这 ...
- Saltstack系列1:安装配置
安装 安装EPEL作为安装Ansible的yum源(CentOS6.4) rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/i386/epel-release ...
- Linux上安装配置Keepalived
Linux上安装配置Keepalived 1.下载 自行去Keepalived官网进行下载,也可以通过如下链接进行下载2.0.18版本(目前的稳定版) 链接:https://pan.baidu.com ...
- saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy的Keepalived
saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy的Keepalived 安装配置Keepalived 1.编写功能模块 #创建keepalived目录# mkdir -p ...
- SaltStack自动化安装配置haproxy的Keepalived
keepalived配置安装 什么是vrrp,阿里云不支持组播,所以阿里云上不能配置keepalived,但是它有自己的slb.运维的大忌,在命令行复制粘贴,一般是先复制到文本中查看确认以后salt编 ...
- saltstack安装配置(halite)
saltstack官方提供了一个简单的web UI--halite.但是给出的安装配置方法实在没法实现,在网上找了几篇博客,见文章末尾的参考链接,可以用起来了.但是功能有点简单.这篇文章记录安装配置h ...
- Keepalived安装配置
一. 介绍 keepalived:是一个类似于 layer3, 4 & 7 交换机制的软件,也就是我们平时说的第 3 层.第 4 层和第 7层交换. Keepalived 的作用是检测 we ...
随机推荐
- Django学习笔记第二篇--关于请求获取
#细节都在代码段里面讲解 零.绪论: HTTP协议是一种请求响应的协议,一次请求一次响应.所以这部分的讲解将分为三个部分:请求获取,分析处理.返回响应. 一.获取请求数据: 1.POST和GET类型 ...
- 如何使用iOS 开发证书 和 Profile 文件
如果你想在 iOS 设备(iPhone/iPad/iTouch)上调试, 需要有 iOS 开发证书和 Profile 文件. 在你拿到这两个文件之后,该如何使用呢? 证书使用说明: 1. iOS 开 ...
- eclipse控制台不限制显示的行数
在Preferences中搜索Console,设置Limit console output没有限制即可.
- 高性能流媒体服务器EasyDSS前端重构(一)-从零开始搭建 webpack + vue + AdminLTE 多页面脚手架
本文围绕着实现EasyDSS高性能流媒体服务器的前端框架来展开的,具体EasyDSS的相关信息可在:www.easydss.com 找到! EasyDSS 高性能流媒体服务器前端架构概述 EasyDS ...
- Angular2+学习第2篇 cli 环境搭建过程
Angular-cli是angular团队针对Angular2提供的脚手架,用于环境搭建,运行等:具体参考Angular-cli GitHub Angular的启动过程,需要先回答三个问题: 启动时加 ...
- cocos2dx-draw绘制
[一]:函数 //1.设置绘制颜色 1.ccDrawColor4B("红","绿","蓝","透明"); //2.设 ...
- CentOS开启telnet连接
开启telnet连接通道 yum安装telnet yum -y install telnet-server* 关闭防火墙 /etc/init.d/iptables stop 编辑配置文件 vim /e ...
- Ubuntu 16.04修改配置静态IP和DNS
Ubuntu 16.04修改配置静态IP和DNS 1.修改interfaces 文件 sudo gedit /etc/network/interfaces 2.添加 例如: auto enp0s25 ...
- Hadoop伪分布安装详解(二)
目录: 1.修改主机名和用户名 2.配置静态IP地址 3.配置SSH无密码连接 4.安装JDK1.7 5.配置Hadoop 6.安装Mysql 7.安装Hive 8.安装Hbase 9.安装Sqoop ...
- react setstate
1.prevstate参数 https://segmentfault.com/q/1010000008177874 2.不是实时渲染 http://bbs.reactnative.cn/topic/3 ...