1、创建目录

cd /srv/salt/package

mkdir haproxy

mkdir -p haproxy/files

mkdir -p haproxy/pkg

saltstack-haproxy安装_第1张图片


2、编写依赖包模块

cat pkg/pkg-init.sls

pkg-init:               

  pkg.installed:        

    - names:            

      - gcc

      - gcc-c++

      - glibc

      - make

      - autoconf

      - openssl

      - openssl-devel

      - htop

      - vim

      - lrzsz

saltstack-haproxy安装_第2张图片


3、安装包准备

ls -l haproxy/files

-rw-r--r-- 1 root root 1538976 Nov 23 02:16 haproxy-1.6.2.tar.gz

wKioL1iBsx_TJ4DYAAAGEHgqOlU239.png


4、启动脚本获取

在master端

cp haproxy/files/haproxy-1.6.2.tar.gz /usr/local/src/ 

cd /usr/local/src 

tar xvf haproxy-1.6.2.tar.gz  

cd haproxy-1.6.2/examples 

sed -i 's/\/usr\/sbin\/'\$BASENAME'/\/usr\/local\/haproxy\/sbin\/'\$BASENAME'/g' haproxy.init

cp haproxy.init /srv/salt/package/haproxy/files/


5、编写haproxy安装文件

cat /srv/salt/package/haproxy/init.sls


include:

  - package.haproxy.pkg.pkg-init

haproxy_source:

  file.managed:

    - name: /usr/local/src/haproxy-1.6.2.tar.gz

    - source: salt://package/haproxy/files/haproxy-1.6.2.tar.gz

    - user: root

    - group: root

    - mode: 755

  cmd.run:

    - name: cd /usr/local/src && tar zvxf haproxy-1.6.2.tar.gz && cd haproxy-1.6.2 && make TARGET=linux26 PREFIX=/usr/local/haproxy && make install PREFIX=/usr/local/haproxy

    - unless: test -d /usr/local/haproxy

    - require:

      - file: haproxy_source


haproxy_init:

  file.managed:

    - name:  /usr/lib/systemd/system/haproxy.service

    - source: salt://package/haproxy/files/haproxy.init

    - user: root

    - group: root

    - mode: 755


haproxy-config-dir:

  file.directory:

    - name: /etc/haproxy

    - user: root

    - group: root

    - mode: 755

saltstack-haproxy安装_第3张图片


6、入口文件

cat /srv/salt/package/init.sls

include:

  - package.http

  - package.haproxy

saltstack-haproxy安装_第4张图片


7、执行

salt 'salt-minion' state.sls package.haproxy

saltstack-haproxy安装_第5张图片

saltstack-haproxy安装_第6张图片

那个错误是因为vim已经装过了

saltstack-haproxy安装_第7张图片


8、检查minion端

在master使用salt命令检查:

wKioL1iBsyCi4fnlAAAJjDYGi7s570.png

saltstack-haproxy安装_第8张图片