1)软件下载
[admin@master files]$ pwd
/srv/salt/prod/keepalived/files
[admin@master files]$ sudo wget http://www.keepalived.org/software/keepalived-1.4.0.tar.gz
--2018-01-29 18:00:05-- http://www.keepalived.org/software/keepalived-1.4.0.tar.gz
Resolving www.keepalived.org (www.keepalived.org)... 37.59.63.157, 2001:41d0:8:7a9d::1
Connecting to www.keepalived.org (www.keepalived.org)|37.59.63.157|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 731936 (715K) [application/x-gzip]
Saving to: ‘keepalived-1.4.0.tar.gz’
100%[==============================================>] 731,936 735KB/s in 1.0s
2018-01-29 18:00:07 (735 KB/s) - ‘keepalived-1.4.0.tar.gz’ saved [731936/731936]
一般情况找一台机器手工安装一下keepalived,然后把配置文件和启动脚本拷贝到/srv/salt/prod/keepalived/files
配置文件和启动脚本,默认在这个目录里:
[admin@proxy02 etc]$ pwd
/usr/local/src/keepalived-1.4.0/keepalived/etc
[admin@proxy02 etc]$ ll
total 64
drwxrwxr-x. 2 1000 1000 4096 Feb 3 16:56 init
drwxrwxr-x. 2 1000 1000 4096 Feb 3 16:55 init.d
drwxrwxr-x. 2 1000 1000 4096 Dec 11 19:16 keepalived
-rw-r--r--. 1 root root 18459 Feb 3 16:55 Makefile
-rw-rw-r--. 1 1000 1000 181 Dec 11 19:16 Makefile.am
-rw-rw-r--. 1 1000 1000 18206 Dec 30 02:00 Makefile.in
drwxrwxr-x. 2 1000 1000 4096 Dec 11 19:16 openrc
drwxrwxr-x. 2 1000 1000 4096 Dec 11 19:16 sysconfig
[admin@proxy02 src]$ cd /usr/local/keepalived/etc/sysconfig/
[admin@proxy02 sysconfig]$ ll
total 4
-rw-r--r--. 1 root root 667 Feb 3 16:56 keepalived
2)创建目录
[admin@master ~]$ sudo mkdir /srv/salt/prod/keepalived
[admin@master ~]$ sudo mkdir /srv/salt/prod/keepalived/files
总之要有下面几个文件
[admin@master files]$ ll
total 728
-rw-r--r--. 1 root root 731936 Dec 30 02:02 keepalived-1.4.0.tar.gz
-rw-r--r--. 1 root root 3550 Jan 29 18:22 keepalived.conf
-rwxr-xr-x. 1 root root 1335 Jan 29 18:26 keepalived.init
-rwxr-xr-x. 1 root root 667 Jan 29 18:36 keepalived.sysconfig
更改一下脚本:
~~~
start() {
echo -n $"Starting $prog: "
daemon /usr/local/keepalived/sbin/keepalived ${KEEPALIVED_OPTIONS}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
}
~~~
3)编写keepalived的sls文件
~~~
include:
- pkg.pkg-init
Dependency_package_installation:
pkg.installed:
- names:
- libnl-devel
- libnfnetlink-devel
keepalived-install:
file.managed:
- name: /usr/local/src/keepalived-1.4.0.tar.gz
- source: salt://keepalived/files/keepalived-1.4.0.tar.gz
- user: root
- group: root
- mode: 755
cmd.run:
- name: cd /usr/local/src && sudo tar xf keepalived-1.4.0.tar.gz && cd keepalived-1.4.0 && sudo ./configure --prefix=/usr/local/keepalived && sudo make && sudo make install
- unless: test -d /usr/local/keepalived
- require:
- pkg: pkg-init
- pkg: Dependency_package_installation
- 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: keepalived-init
/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
~~~
- 第一章:saltstack的基本介绍
- 第二章:saltstack的安装部署
- 第一节:在centos7系统上安装saltstack工具
- 第二节:在windows server 2008上安装salt-minion
- 第三章: saltstack的配置管理
- 第一节:salt-master配置
- 第二节:salt-minion配置
- 第三节:了解YAML
- 第四节:salt-master配置文件详解
- 第五节:了解Jinja2
- 第六节:配置普通用户可以运行saltstack的模块
- 第四章:远程执行
- 第一节:远程执行基础介绍
- 第二节:目标定位
- 一、全局及正则表达式匹配
- 二、列表匹配
- 三、Grains
- 四: Pillar
- 五:subnet and ip
- 六:组合匹配
- 七: node group
- 第三节:常用模块
- 一、查看帮助
- 二、Network模块
- 三、Service模块
- 四:State模块
- 五、Cron模块
- 六、File模块
- 七、iptables模块
- 八、pkg包管理
- 第四节:Salt其他命令
- 一、salt-cp(拷贝文件)
- 二、salt-ssh
- 三、salt-key
- 第五节:saltstack返回程序
- 第一节:返回保持到数据库(mysql)
- 第五章:配置管理
- 第一节:简单入门
- 第二节:状态间关系
- 第六章:数据系统
- 第一节:grains
- 第二节:pillar
- 第七章:saltstack配置管理
- 第一节:系统初始化操作
- 第二节:功能模块
- 一、haproxy模块
- 二、keepalived模块
- 三、nginx模块
- 四: pcre模块
- 五: zlib模块
- 六:user模块
- 七:php模块
- 第三节:业务模块
- 第一节:haproxy代理
- 第二节:keepalived业务
- 第八章:自动化管理工具saltstack
- 第一节:文件管理
- 第二节:软件管理
- 第三节:服务管理
- 第四节:sysctl模块管理