SaltStack自动化运维初涉--安装简用篇

简介:

  很久之前,用过一段时间的Puppet,也就是简单用了用,后来慢慢就丢了,然后就去搞mysql的一些东西了,或许,很多事情就是注定的,以为再来不会用它了的时候,任务来了,说要继续研究这玩意,后面遇到一个牛X的同事,说用SaltStack比较好,而且他已经用这个做了不少实际游泳的案例了,他说,Puppet注重于最终状态,SaltStack注重于实时命令的运行,SaltStack=Puppet+Func,且SaltStack还是使用Python开发的,入手以及后续的功能自定义开发都是非常方便的。于是乎,就看看咯.

官网链接是:http://www.saltstack.com/


角色       操作系统           主机名      IP地址

Master【服务端】    RHEL6U3 X86_64    DemoServer    192.168.153.38

Minion【客户端】     RHEL6U3 X86_64    oracle        192.168.153.137


1. 安装SaltStack Master

 [1] 配置本地YUM源

1
2
3
4
5
6
7
[root@DemoServer ~] # cat /etc/yum.repos.d/rhel-source.repo
[rhel]
name=rhel
baseurl=http: //192 .168.150.3 /rhel6 .3core/
enabled=1
gpgcheck=1
gpgkey= file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta , file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

额外下载包:python-jinja2-2.2.1-1.el6.x86_64.rpm  

[2] 安装EPEL源

1
[root@DemoServer ~] #  rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/i386/epel-release-6-8.noarch.rpm

[3] 开启YUM缓存,保存安装包

1
2
3
4
5
6
7
8
9
10
11
[root@DemoServer ~] # cat /etc/yum.conf
[main]
cachedir= /var/cache/yum/ $basearch/$releasever
keepcache=0  修改为  keepcache=1
debuglevel=2
logfile= /var/log/yum .log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3

[4] 安装SaltStack Master 软件包

1
[root@DemoServer ~] # yum install python-jinja2-2.2.1-1.el6.x86_64.rpm   salt-master salt-minion -y  //本节点即作为Master,也作为Minion使用

[5] 保存所有依赖包,用于离线安装

1
2
3
4
5
6
7
8
9
10
11
12
[root@DemoServer packages] # ll /var/cache/yum/x86_64/6Server/epel/packages
total 3356
-rw-r--r--. 1 root root   52880 May 19  2010 libyaml-0.1.3-1.el6.x86_64.rpm
-rw-r--r--. 1 root root  169348 Dec 26  2012 openpgm-5.1.118-3.el6.x86_64.rpm
-rw-r--r--. 1 root root   29556 Jun  2  2013 python-msgpack-0.1.13-3.el6.x86_64.rpm
-rw-r--r--. 1 root root  433896 Dec 15  2012 python-zmq-2.2.0.1-1.el6.x86_64.rpm
-rw-r--r--. 1 root root  161120 Apr 28  2012 PyYAML-3.10-3.el6.x86_64.rpm
-rw-r--r--. 1 root root 2156412 Nov 20 22:46 salt-0.17.2-2.el6.noarch.rpm
-rw-r--r--. 1 root root   32124 Nov 20 22:46 salt-master-0.17.2-2.el6.noarch.rpm
-rw-r--r--. 1 root root   20956 Nov 20 22:46 salt-minion-0.17.2-2.el6.noarch.rpm
-rw-r--r--. 1 root root   19292 Aug 31  2011 sshpass-1.05-1.el6.x86_64.rpm
-rw-r--r--. 1 root root  341724 Sep 22 02:18 zeromq3-3.2.4-1.el6.x86_64.rpm
1
2
[root@DemoServer ~] # ll /var/cache/yum/x86_64/6Server/rhel/packages
-rw-r--r--. 1 root root 1494848 Aug 17  2010 python-babel-0.9.4-5.1.el6.noarch.rpm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@DemoServer ~] # ll saltstack0.17.4  //共计如下软件包
total 5288
-rw-r--r--. 1 root root   52880 Jan  2 16:35 libyaml-0.1.3-1.el6.x86_64.rpm
-rw-r--r--. 1 root root  169348 Jan  2 16:35 openpgm-5.1.118-3.el6.x86_64.rpm
-rw-r--r--. 1 root root 1494848 Jan  2 16:36 python-babel-0.9.4-5.1.el6.noarch.rpm
-rwxr--r--. 1 root root  476200 Jan  2 16:36 python-jinja2-2.2.1-1.el6.x86_64.rpm
-rw-r--r--. 1 root root   29556 Jan  2 16:35 python-msgpack-0.1.13-3.el6.x86_64.rpm
-rw-r--r--. 1 root root  433896 Jan  2 16:35 python-zmq-2.2.0.1-1.el6.x86_64.rpm
-rw-r--r--. 1 root root  161120 Jan  2 16:35 PyYAML-3.10-3.el6.x86_64.rpm
drwxr-xr-x. 2 root root    4096 Jan  2 16:36 repodata
-rw-r--r--. 1 root root 2156412 Jan  2 16:35 salt-0.17.2-2.el6.noarch.rpm
-rw-r--r--. 1 root root   32124 Jan  2 16:35 salt-master-0.17.2-2.el6.noarch.rpm
-rw-r--r--. 1 root root   20956 Jan  2 16:35 salt-minion-0.17.2-2.el6.noarch.rpm
-rw-r--r--. 1 root root   19292 Jan  2 16:35 sshpass-1.05-1.el6.x86_64.rpm
-rw-r--r--. 1 root root  341724 Jan  2 16:35 zeromq3-3.2.4-1.el6.x86_64.rpm

[6] 制作SaltStack安装YUM源

1
2
3
4
5
6
7
8
9
10
[root@DemoServer ~] # mv saltstack0.17.4  /var/www/html/saltstack/
[root@DemoServer ~] # yum install createrepo -y
[root@DemoServer ~] # createrepo -p -d -o /var/www/html/saltstack/ \
/var/www/html/saltstack/
12 /12  - salt-minion-0.17.2-2.el6.noarch.rpm                                  
Saving Primary metadata
Saving  file  lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

[7] 启动httpd服务

1
[root@DemoServer ~] # service httpd start


[8] 安装oracle节点的salt-minion

(1) 配置YUM源

1
2
3
4
5
6
7
8
9
10
11
12
[root@oracle ~] # cat /etc/yum.repos.d/rhel-source.repo
[rhel]
name=rhel
baseurl=http: //192 .168.150.3 /rhel6 .3core/
enabled=1
gpgcheck=1
gpgkey= file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta , file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[saltstack]
name=saltstack
baseurl=http: //192 .168.153.38 /saltstack
enabled=1
gpgcheck=0

(2) 安装salt-minion 软件包

1
[root@oracle ~] # yum  install salt-minion -y

2. 启动服务

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@DemoServer ~] # iptables  -F ; service iptables save ; service iptables restart //清空所有IPTABLES规则,或者开放4505与4506端口
[root@DemoServer ~] # setenforce  0 //手动设置SELINUX状态
[root@DemoServer ~] # sed -i 's/enforcing/disabled/g'  /etc/sysconfig/selinux //修改SELINUX状态为disabled,重启生效
[root@DemoServer ~] # grep 'SELINUX=' /etc/sysconfig/selinux
# SELINUX= can take one of these three values:
SELINUX=disabled
[root@DemoServer ~] # service salt-master start //启动salt-master
[root@DemoServer ~] # chkconfig  salt-master on //设置salt-master开机启动
[root@DemoServer ~] # service salt-minion start //启动salt-minion
[root@DemoServer ~] # chkconfig salt-minion on //设置salt-minion开机启动
[root@DemoServer ~] # netstat  -nltup |grep python //查看端口是否被监听
tcp   0   0 192.168.153.38:4505   0.0.0.0:*   LISTEN  882 /python       
tcp   0   0 192.168.153.38:4506   0.0.0.0:*   LISTEN  874 /python

oracle节点上面同样启动

1
2
[root@oracle ~] # service salt-minion start //启动salt-minion服务
[root@oracle ~] # chkconfig salt-minion on //设为开机启动

3. 修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Master:
[root@DemoServer ~] # cat  /etc/salt/master  |grep -v '#' |grep interface
interface: 192.168.153.38   // 修改监听IP
[root@DemoServer ~] # service salt-master restart //重启salt-master服务
两个 Minion:
[root@DemoServer ~] # cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.153.38DemoServer
[root@DemoServer ~] # cat   /etc/salt/minion |grep -v '#'|grep  master
master: DemoServer   // 指定master的可解析的主机名或者IP地址
[root@DemoServer ~] # service salt-minion restart //重启 salt-minion 服务
[root@oracle ~] # cat /etc/salt/minion |grep -v '#' |grep  master
master: 192.168.153.38
[root@oracle ~] #  service salt-minion restart //重启 salt-minion 服务


4. 密钥验证



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[root@DemoServer ~] # salt-key  -L   //列出所有请求key
Accepted Keys:
Unaccepted Keys:
DemoServer  == 本机
oracle            ==新主机,主机名为oracle IP为192.168.153.37
Rejected Keys:
【 上面识别到的 id  默认取客户端的主机名的FQDN值,如果在客户端的 /etc/salt/minion_id 中进行修改,则会显示自定义的 id 值 】
[root@DemoServer ~] # salt-key  -a  DemoServer  //批准DemoServer
The following keys are going to be accepted:
Unaccepted Keys:
DemoServer
Proceed? [n /Y ] y
Key  for  minion DemoServer accepted.
[root@DemoServer ~] # salt-key  -L
Accepted Keys:
DemoServer
Unaccepted Keys:
oracle
Rejected Keys:
[root@DemoServer ~] # salt-key  -A  //批准接受全部
The following keys are going to be accepted:
Unaccepted Keys:
oracle
Proceed? [n /Y ] y
Key  for  minion oracle accepted.
[root@DemoServer ~] # salt-key  -L  //再次查看,全部被接受
Accepted Keys:
DemoServer
oracle
Unaccepted Keys:
Rejected Keys:

5. 简单命令尝试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@DemoServer ~] # salt oracle test.ping
oracle:
     True
[root@DemoServer ~] # salt '*' test.ping
DemoServer:
     True
oracle:
     True
或者
[root@DemoServer ~] # salt -L 'oracle153_37,DemoServer' test.ping
oracle153_37:
     True
DemoServer:
     True
Grains 类似于Puppet中的facter
[root@DemoServer ~] # salt -G 'cpuarch:x86_64' grains.item num_cpus
DemoServer:
   num_cpus: 4
oracle153_37:
   num_cpus: 4
[root@DemoServer ~] # salt '*' grains.ls  //查看有哪些参数可以显示
[root@DemoServer ~] # salt '*' grains.items  //列出所有参数的条目,item复数
  // 列出具体的参数值,item单数
[root@DemoServer ~] # salt '*'  grains.item os
DemoServer:
   os: RedHat
oracle153_37:
   os: RedHat


昨天对SaltStack的探讨就这些,记录下来,再深究。










本文转自 暗黑魔君 51CTO博客,原文链接:http://blog.51cto.com/clovemfong/1347951,如需转载请自行联系原作者
目录
打赏
0
0
0
0
234
分享
相关文章
阿里云系统运维管理OOS一键安装宝塔面板,这个功能太牛了!
宝塔面板是实用的服务器管理工具,支持多种操作系统(如Ubuntu、CentOS等)。通过阿里云OOS可一键安装。安装前提包括ECS实例运行中且有公网,安全组需开放8888端口。安装步骤简单,进入ECS控制台选择预装应用并确认下单,完成后在控制台查看详情和登录信息。最后验证安装结果,确保能成功访问宝塔面板URL。
206 82
阿里云服务器一键安装Docker社区版教程,基于系统运维管理OOS
阿里云服务器一键安装Docker社区版教程,基于系统运维管理OOS自动化部署。支持Ubuntu 22.04/20.04、CentOS 7.7-7.9及Alibaba Cloud Linux 3.2104 LTS。前提条件:ECS实例需运行中且有公网。步骤:选择Docker扩展并安装,验证成功通过命令`docker -v`查看版本号。
329 79
HTTPS 证书自动化运维:https证书管理系统- 自动化监控
本文介绍如何设置和查看域名或证书监控。步骤1:根据证书状态选择新增域名或证书监控,线上部署推荐域名监控,未部署选择证书监控。步骤2:查询监控记录详情。步骤3:在详情页查看每日定时检测结果或手动测试。
HTTPS 证书自动化运维:https证书管理系统- 自动化监控
HTTPS 证书自动化运维:https证书管理系统-自动化部署
本指南介绍如何部署Linux服务器节点。首先复制生成的Linux脚本命令,然后将其粘贴到目标服务器上运行。接着刷新页面查看节点记录,并点击“配置证书”选择证书以自动部署。最后,节点部署完成,后续将自动调度,无需人工干预。
HTTPS 证书自动化运维:https证书管理系统-自动化部署
HTTPS 证书自动化运维:https证书管理系统之自动化签发
通过访问【https://www.lingyanspace.com】注册账户,进入证书服务菜单并新增证书。填写域名(单域名、多域名或泛域名),创建订单后添加云解析DNS记录进行质检。确认完成后可下载证书,并支持后续查看、更新和定时更新功能。证书过期前15天自动更新,需配置邮箱接收通知。
HTTPS 证书自动化运维:https证书管理系统之自动化签发
基于AI的自动化服务器管理:解锁运维的未来
基于AI的自动化服务器管理:解锁运维的未来
46 0
基于AI的自动化事件响应:智慧运维新时代
基于AI的自动化事件响应:智慧运维新时代
127 11
AI辅助的运维流程自动化:实现智能化管理的新篇章
AI辅助的运维流程自动化:实现智能化管理的新篇章
611 22
ChatMCP:基于 MCP 协议开发的 AI 聊天客户端,支持多语言和自动化安装 MCP 服务器
ChatMCP 是一款基于模型上下文协议(MCP)的 AI 聊天客户端,支持多语言和自动化安装。它能够与多种大型语言模型(LLM)如 OpenAI、Claude 和 OLLama 等进行交互,具备自动化安装 MCP 服务器、SSE 传输支持、自动选择服务器、聊天记录管理等功能。
372 15
ChatMCP:基于 MCP 协议开发的 AI 聊天客户端,支持多语言和自动化安装 MCP 服务器
小团队 CI/CD 实践:无需运维,Java Web应用的自动化部署
本文介绍如何使用GitHub Actions和阿里云Kubernetes(ACK)实现Java Web应用的自动化部署。通过CI/CD流程,开发人员无需手动处理复杂的运维任务,从而提高效率并减少错误。文中详细讲解了Docker与Kubernetes的概念,并演示了从创建Kubernetes集群、配置容器镜像服务到设置GitHub仓库Secrets及编写GitHub Actions工作流的具体步骤。最终实现了代码提交后自动构建、推送镜像并部署到Kubernetes集群的功能。整个过程不仅简化了部署流程,还确保了应用在不同环境中的稳定运行。
92 9

热门文章

最新文章

推荐镜像

更多
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等