salt 之 学习环境搭建
快速开始
新到一家公司使用了salt,这打破了我一直使用ansible的习惯,硬着头皮快速开始吧
-
使用docker环境快速学习
master的DockerfileFROM centos:7 RUN curl -fsSL https://repo.saltproject.io/py3/redhat/7/x86_64/3004.repo | tee /etc/yum.repos.d/salt.repo && \ sed -i "s/repo.saltproject.com/mirrors.aliyun.com\/saltstack/g" /etc/yum.repos.d/salt.repo &&\ yum install salt-master -y
minion的Dockerfile
FROM centos:7 RUN curl -fsSL https://repo.saltproject.io/py3/redhat/7/x86_64/3004.repo | tee /etc/yum.repos.d/salt.repo && \ sed -i "s/repo.saltproject.com/mirrors.aliyun.com\/saltstack/g" /etc/yum.repos.d/salt.repo &&\ yum install salt-minion -y
-
启动容器
#!/bin/bash docker rm -f salt-master docker rm -f salt-minion docker network rm bridmv docker network create -d macvlan --subnet=10.4.7.0/24 --gateway=10.4.7.254 -o parent=eth0 -o macvlan_mode=bridge bridmv docker run -d --net=bridmv --privileged --name=salt-minion --ip 10.4.7.60 centos7:salt-minio tail -f /dev/null docker run -d --net=bridmv --privileged --name=salt-master --ip 10.4.7.61 centos7:salt-master /usr/bin/salt-master --log-level=debug
-
配置minion连接到master
3.1修改minion配置文件docker exec -it salt-minion bash [root@9b3d6af908c2 /]# vi /etc/salt/minion master: - 10.4.7.61
3.2启动minion服务
docker exec -it salt-minion bash [root@9b3d6af908c2 /]# /usr/bin/salt-minion
3.3服务端接受minion发起的连接
[root@allinone salt]# docker exec -it salt-master salt-key -a 9b3d6af908c2 The following keys are going to be accepted: Unaccepted Keys: 9b3d6af908c2 Proceed? [n/Y] y Key for minion 9b3d6af908c2 accepted.
查看已接受的key
[root@allinone salt]# docker exec -it salt-master salt-key Accepted Keys: 9b3d6af908c2 Denied Keys: Unaccepted Keys: Rejected Keys:
-
master端测试
[root@allinone salt]# docker exec -it salt-master salt '*' test.ping 9b3d6af908c2: True
至此已经完成了salt的学习环境搭建