saltstack
1、介绍:
SaltStack是一个新的基础平台管理工具,只需要花费数分钟即可运行起来,可以支撑管理上万台服务器的规模,数秒钟即可完成数据传递。SaltStack是使用Python语言开发的,同时提供RestAPI方便二次开发以及和其它平台进行集成,同时官方也发布了一个Web管理界面halite。
2、SaltStack常用网址:
官方网站:http://www.saltstack.com
官方文档:http://docs.saltstack.com
GitHub:https://github.com/saltstack
中国SaltStack户组:http://www.saltstack.cn
3、SaltStack有三种运行方式:
Local
Master/Minion
Salt SSH
SaltStack的传统运行模式为Master/Minion(C/S结构),需要在被管理的节点上安装Minion。
同时SaltStack也支持SSH的方式,无需安装Agent,通过SSH实现管理。
4、SaltStack目前拥有三大主要功能:
远程执行
配置管理
云管理
前期工作准备
1、练习环境
环境 | LINUX |
系统 | CentOS release 6.8 (Final) |
内核版本 | 2.6.32-642.el6.x86_64 |
epel源 | wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo |
selinux | Disabled |
ip tables | Firewall is not running. |
节点 | IP |
管理机(m01) | 172.16.1.130 |
被管理机(web01) | 172.16.1.131 |
被管理机(web02) | 172.16.1.132 |
被管理机(web03) | 172.16.1.133 |
被管理机(web04) | 172.16.1.134 |
被管理机(web05) | 172.16.1.135 |
2、首先更新epel(RHEL 6)
每台node上都要更新!阿里源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
3、hosts解析
cat>/etc/hosts<<eof127.0.0.1 localhost.localdomain localhost.localdomain localhost4 localhost4.localdomain4 localhost::1 localhost.localdomain localhost.localdomain localhost6 localhost6.localdomain6 localhost172.16.1.131 web01172.16.1.132 web02172.16.1.133 web03172.16.1.134 web04172.16.1.130 m01eof
配置
1、管理机
yum install -y salt-master
2 、被管理机
yum -y install salt-minion
3、开机自启动
管理机和被管理机都要设置开机自启动
chkconfig salt-master on chkconfig salt-minion on
4 、管理机修改配置文件/etc/salt/master
vim /etc/salt/masterfile_roots: base: ##这行前必须2个空格 -/srv/salt ##这行前必须4个空格pillar_roots: base: ##这行前必须2个空格 - /srv/pillar ##这行前必须4个空格
注意修改的位置!!
5、管理机开启salt-master
[root@m01 scripts]# /etc/init.d/salt-master startStarting salt-master daemon: [ OK ][root@m01 scripts]#
6、被管理机修改配置文件/etc/salt/minion
echo -e "master: 172.16.1.130\nid: web01">> /etc/salt/minionecho -e "master: 172.16.1.130\nid: web02">> /etc/salt/minionecho -e "master: 172.16.1.130\nid: web03">> /etc/salt/minionecho -e "master: 172.16.1.130\nid: web04">> /etc/salt/minionecho -e "master: 172.16.1.130\nid: web05">> /etc/salt/minion
查看
[root@backup ~]# egrep -v "^#|^$"/etc/salt/minionmaster:172.16.1.30 ==》注意后面的空格(下同)id:backup vim /etc/salt/minionmaster: m01 #master: 领主机的IP或主机名 :后面必须要有1个空格id: nfs01 #id: 下属名称,可以不配置,默认使用主机名称。
7、被管理机启动
[root@web02 ~]# /etc/init.d/salt-minion startStarting salt-minion daemon: [ OK ][root@web02 ~]#
验证
1、管理机(m01)验证
[root@m01 ~]# salt-key -LAccepted Keys:Denied Keys:Unaccepted Keys:web01web02web03web04web05Rejected Keys:
2、客户端开启debug、master加载key
[root@m01 scripts]# salt-key -AThe following keys are going to be accepted:Unaccepted Keys:backupnfsweb01web02Proceed? [n/Y] yesKey for minion backup accepted.Key for minion nfs accepted.Key for minion web01 accepted.Key for minion web02 accepted.[root@m01 scripts]#
3、确认主机是否存活True为存活
[root@m01 ~]# salt '*' test.pingweb03: Trueweb01: Trueweb04: Trueweb05: Trueweb02:True
4、单个机台测试
[root@m01 ~]# salt 'web01'test.ping #salt '*' test.pingweb01: True[root@m01 ~]# salt 'web01'cmd.run 'df -h'web01: Filesystem Size Used Avail Use% Mounted on /dev/sda2 19G 1.5G 17G 9% / tmpfs 491M 12K 491M 1% /dev/shm /dev/sda1 190M 33M 147M 19% /boot[root@m01 ~]#
5、查看帮助
[root@m01 ~]# salt-key -help
===================================
SaltStack 模块单独发布~~
本文出自 “宋某人c” 博客,请务必保留此出处http://syaving.blog.51cto.com/5614476/1864797