设为首页 收藏本站
查看: 965|回复: 0

[经验分享] Saltstack 安装应用笔记一

[复制链接]

尚未签到

发表于 2018-7-31 11:45:27 | 显示全部楼层 |阅读模式
  Saltstack 安装应用
  master 10.10.10.96
  minion 10.10.10.97
  一、系统准备
  [root@master ~]# uname -r
  2.6.32-504.el6.x86_64
  # salt --version
  salt 2016.3.3 (Boron)
  1、设置关闭 selinux
  [root@master ~]# cat /etc/sysconfig/selinux |grep -v ^#
  SELINUX=disabled
  SELINUXTYPE=targeted
  2、设置iptables
  # iptables -A INPUT -p tcp --dport 4505 -j ACCEPT
  # iptables -A INPUT -p tcp --dport 4506 -j ACCEPT
  # /etc/init.d/iptables save
  3、安装 gcc c++
  # yum install gcc gcc-c++ -y
  4、配置yum 源
  # cat /etc/yum.repos.d/saltstack.repo
  [saltstack]
  name=saltstack
  baseurl=https://repo.saltstack.com/yum/rhel6/
  enabled=1
  gpgcheck=0
  # rhel7 可以以此更改URL 安装源;
  5、安装配置
  master:
  # yum install salt-master salt-minion salt-ssh salt-syndic salt-cloud -y
  6、配置master
  # mkdir /srv/{salt,pillar}
  # cat /etc/salt/master
  interface: 10.10.10.96
  # 绑定master通信IP
  publish_port: 4505
  master_id: master
  auto_accept: True
  # 打开key的自动验证
  pidfile: /var/run/salt-master.pid
  pki_dir: /etc/salt/pki
  file_roots:
  base:
  - /srv/salt
  # 指定saltstack文件根目录位置
  pillar_roots:
  base:
  - /srv/pillar
  # 指定pillar的配置目录
  #
  当/etc/salt/master没有配置auto_accept: True时,需要通过salt-key命令来进行证书认证操作
  salt-key -L 显示已认证或未认证的被控端id
  salt-key -D 删除所有认证主机id证书

  salt-key -d>  salt-key -A 接受所有id证书

  salt-key -a>
  salt-key -j>  salt-key –J 拒绝所有id证书
  #
  7、启动
  # service salt-master start
  # chkconfig salt-master on
  8、minion 端:
  # yum install salt-minion -y
  配置 minion
  [root@client ~]# cat /etc/salt/minion
  master: 10.10.10.96
  id: client
  9、启动
  # service salt-minion start
  # chkconfig salt-minion on
  10、向客户端发送命令检测;
  [root@master ~]# salt-key -L
  # 查看minion 列表
  [root@master ~]# salt 'client' test.ping
DSC0000.png

  二、提示问题:
  # salt '*' test.ping
  [ERROR] Salt request timed out. If this error persists, worker_threads may need to be increased.
  Failed to authenticate!  This is most likely because this user is not permitted to execute commands, but there is a small possibility that a disk error occurred (check disk/inode usage).
  Salt因为握手不成功报错[要求增加线程]解决办法?一般都是配置问题
  解决方法:
  检测配置文件 /etc/salt/master里面的worker_threads 参数
  检测 IPtables和4506 4505 端口;
  三、常用模块及API
  通过sys模块列出当前版本支持的模块
  #salt '*' sys.list_modules
  1、archive模块:实现系统层面的压缩包调用
  # salt ‘*’ archive.gzip /tmp/sourcefile.txt
  # salt ‘*’ archive.gunzip /tmp/sourcefile.txt.gz
  2、cmd模块:实现远程的命令行调用执行(默认具有root权限)
  # salt ‘*’ cmd.run ‘free -m’
  在远程主机运行test.sh脚本,其中script/test.sh存放在file_roots指定的目录,该命令会有两个动作,首先同步test.sh到minion的cache目录(/var/cache/salt/minion/files/base/script/),其次运行该脚本
  # salt ‘nginx_update’ cmd.script salt://script/test.sh
  3、cp模块:实现远程文件、目录的复制,以及下载URL文件等操作
  将指定被控主机的/etc/hosts文件复制到被控主机本地的salt cache目录/var/cache/salt/minion/localfiles
  # salt ‘*’ cp.cache_local_file /etc/hosts
  将主服务器file_roots指定位置下的目录复制到被控主机
  # salt ‘*’ cp.get_dir salt://path/to/dir /minion/dest
  将主服务器file_roots指定位置下的文件复制到被控主机
  # salt ‘*’ cp.get_file salt://path/to/file /minion/dest
  下载URL内容到被控主机指定位置
  # salt ‘*’ cp.get_url http://www.slashdot.org /tmp/index.html
  删除 文件
  salt '*' file.remove /tmp/test
  4、cron模块:实现被控主机的crontab操作
  查看指定被控主机root用户的crontab清单
  # salt ‘nginx_update’ cron.raw_cron root
  为指定的被控主机root用户添加/usr/local/weekly任务作业
  # salt ‘nginx_update’ cron.set_job root ‘*’ ‘*’ ‘*’ ‘*’ 1 /usr/local/weekly
  删除指定的被控主机root用户的crontab的/usr/local/weekly任务作业
  # salt ‘nginx_update’ cron.rm_job root /usr/local/weekly
  5、dnsutil模块:实现被控主机通用DNS相关操作
  添加指定被控主机hosts的主机配置项
  # salt ‘nginx_update’ dnsutil.hosts_append /etc/hosts 127.0.0.1 localhost.com
  删除指定被控主机hosts的主机配置项
  # salt ‘nginx_update’ dnsutil.hosts_remove /etc/hosts localhost.com
  6、file模块:被控主机文件常见操作,包括文件读写,权限,查找,校验等
  # salt ‘*’ file.chown /etc/passwd root root
  # salt ‘*’ file.copy /path/to/src /path/to/dst
  # salt '*' file.directory_exists /etc/
  # salt '*' file.file_exists /etc/passwd
  # salt '*' file.stats /etc/passwd
  # salt '*' file.get_mode /etc/passwd
  # salt '*' file.set_mode /etc/passwd 0644
  # salt '*' file.mkdir /tmp/test
  # salt ‘*’ file.sed /etc/httpd/httpd.conf ‘LogLevel warn’ ‘LogLevel info’
  # salt '*' file.append /tmp/test/testfile 'maxclient 100'
  # salt '*' file.remove /tmp/test/testfile
  7、pkg包管理模块:被控主机程序包管理,如yum
  # salt ‘*’ pkg.install php
  # salt ‘*’ pkg.remove php
  # salt ‘*’ pkg.upgrade
  8、service服务模块:被控主机程序包服务管理
  # salt ‘*’ service.enable nginx
  # salt ‘*’ service.disable nginx
  # salt ‘*’ service.reload nginx
  # salt ‘*’ service.restart nginx
  # salt ‘*’ service.start nginx
  # salt ‘*’ service.stop nginx
  # salt ‘*’ service.status nginx
  9、iptables模块

  # salt ‘*’ iptables.append filter INPUT rule=’-m state -state>
  # salt ‘*’ iptables.insert filter INPUT position=3 rule=’-m state -state>  # salt ‘*’ iptables.delete filter INPUT position=3

  # salt ‘*’ iptables.delete filter INPUT rule=’ -m state -state>  # salt ‘*’ iptables.save /etcsysconfig/iptables
  四、官方参考:
  http://docs.saltstack.cn/topics/installation/rhel.html

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-544115-1-1.html 上篇帖子: Installation saltstack on RHEL CentOS-12213582 下篇帖子: Saltstack 基础模块记录二
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表