Hi 你好,欢迎访问!登录
当前位置:首页 - Linux - 正文 忍人所不忍,能人所不能。

Linux自动化工具之SaltStack 实战项目4(业务引用_keepalived)

2020-03-03Linux90root175°c
A+ A-

1.下载Keepalived软件包,并安装(初学salt, 建议先找台测试机器安装软件包,记录操作命令)

[[email protected] ~]# cd /usr/local/src/
[[email protected] src]# wget http://www.keepalived.org/software/keepalived-1.2.19.tar.gz
[[email protected] src]# tar zxvf keepalived-1.2.19.tar.gz
[[email protected] src]# cd keepalived-1.2.19 
[[email protected] keepalived-1.2.19]# ./configure --prefix=/usr/local/keepalived --disable-fwmark 
[[email protected] keepalived-1.2.19]# make
[[email protected] keepalived-1.2.19]# make install

2. 创建keepalived目录,拷贝配置文件,修改keepalived启动脚本

[[email protected] ~]# mkdir /etc/salt/states/keepalived/files -p
[[email protected] ~]# cp /usr/local/src/keepalived-1.2.19/keepalived/etc/init.d/keepalived.init /etc/salt/states/keepalived/files/
[[email protected] ~]# cp /usr/local/src/keepalived-1.2.19/keepalived/etc/keepalived/keepalived.conf /etc/salt/states/keepalived/files/
[[email protected] ~]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/salt/states/keepalived/files/keepalived.sysconfig
[[email protected] ~]# cp /usr/local/src/keepalived-1.2.19.tar.gz /etc/salt/states/keepalived/files/
[[email protected] ~]# cd /etc/salt/states/keepalived/files
[[email protected] files]# vim keepalived.init
 23     daemon /usr/local/keepalived/sbin/keepalived ${KEEPALIVED_OPTIONS}      #修改后样子

3. 编写keepalived salt文件

[[email protected] ~]# vim /etc/salt/states/pkg/pkg-init.sls
pkg-init:
  pkg.installed:
    - names:
      - …………                #省略
      - openssl-devel       #安装keepalived需要它
[[email protected] ~]# cd /etc/salt/states/keepalived/
[[email protected] keepalived]# vim install.sls
include:
  - pkg.pkg-init
keepalived-install:
  file.managed:
    - name: /usr/local/src/keepalived-1.2.19.tar.gz
    - source: salt://keepalived/files/keepalived-1.2.19.tar.gz
    - user: root
    - group: root
    - mode: 755
  cmd.run:
    - name: cd /usr/local/src &&  tar zxvf keepalived-1.2.19.tar.gz && cd keepalived-1.2.19 &&
 ./configure --prefix=/usr/local/keepalived --disable-fwmark && make && make install
    - unless: test -d /usr/local/keepalived
    - require:
      - pkg: pkg-init 
      - file: keepalived-install
##Keepalived服务管理脚本
keepalived-init:
  file.managed:
    - name: /etc/init.d/keepalived
    - source: salt://keepalived/files/keepalived.init
    - user: root 
    - group: root 
    - mode: 755 
## 将Keepalived加入系统服务管理
  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

4. 用salt测试keepalived是否报错

[[email protected] keepalived]# salt 'node2.90root.com' state.sls keepalived.install test=True

Linux自动化工具之SaltStack 实战项目4(业务引用 keepalived) SaltStack Linux Linux 第1张

5. salt安装keepalived(这一步暂且可以不做)

[[email protected] keepalived]# cd /etc/salt/states/
[[email protected] states]# vim top.sls
base: 
  '*': 
    - …………                          #省略 
    - keepalived.install
[[email protected] states]# salt '*' state.highstate
[[email protected] states]# salt '*' cmd.run 'ls /etc/init.d/keepalived'
node2.90root.com: 
    /etc/init.d/keepalived 
node3.90root.com: 
    /etc/init.d/keepalived          #说明2个节点已经安装上keepalived
  移步手机端
Linux自动化工具之SaltStack 实战项目4(业务引用_keepalived)

1、打开你手机的二维码扫描APP
2、扫描左则的二维码
3、点击扫描获得的网址
4、可以在手机端阅读此文章
标签:

发表评论

选填

必填

必填

选填

请拖动滑块解锁
>>


  用户登录