SaltStack管理工具常用命令

2018年7月18日10:52:16 發(fā)表評(píng)論 4,507 ℃

salt-key -L      # 查看當(dāng)前證書簽證情況

salt-key -A -y   #同意簽證所有沒有接受的簽證請(qǐng)求

salt-key -d      #刪除指定的key

salt-key -D      #刪除所有的key

salt-minion -l debug

salt 'Minion' test.ping    #測試連通情況

salt '*' grains.item os     #顯示被控主機(jī)的操作系統(tǒng)

salt -G 'os:Centos' test.ping #根據(jù)被控主機(jī)的grains信息進(jìn)行匹配過濾

salt -G 'lsb_distrib_release:15.4' 

salt -G 'lsb_distrib_description:Deepin 15.4' #匹配系統(tǒng)為15.4版本的主機(jī)

salt '*' cmd.exec_code python 'import sys; print sys.version' #遠(yuǎn)程代碼執(zhí)行測試

salt -S '192.168.1.0/24' test.ping

倉庫目錄:file_roots (/etc/salt/master定義目錄,默認(rèn)/srv/salt)

salt '*' cp.get_dir salt://mastertest /root/mastertest #將file_roots目錄下的mastertest目錄復(fù)制到 被控制端/root/目錄下面

salt '*' cp.get_file salt://master/test.txt /root/test.txt #....

salt '*' cp.get_url http://mirrors.sohu.com/apache/httpd-2.4.25.tar.gz /root/httpd-2.4.25.tar.gz #下載指定內(nèi)容到被控制端服務(wù)器目錄

##遠(yuǎn)程命令調(diào)用執(zhí)行

salt '*' cmd.run 'uptime'  

salt '*' cmd.run 'netstat -ntlp'

## 為指定的被控主機(jī)、root用戶添加crontab信息

salt '*' cron.set_job root '*/5' '*' '*' '*' '*' 'date >/dev/null 2>&1'

salt '*' cron.raw_cron root

## 刪除指定的被控主機(jī)、root用戶的crontab信息

salt '*' cron.rm_job root 'date >/dev/null 2>&1'

salt '*' cron.raw_cron root

## 為被控主機(jī)添加指定的hosts主機(jī)配置項(xiàng)

salt '*' dnsutil.hosts_append /etc/hosts 127.0.0.1 master

salt '*' hosts.add_host 1.1.1.1 test.com

##file模塊(被控主機(jī)文件常見操作,包括文件讀寫、權(quán)限、查找、校驗(yàn)等)

salt '*' file.get_sum /etc/resolv.conf md5

salt '*' file.stats /etc/resolv.conf

##network模塊(返回被控主機(jī)網(wǎng)絡(luò)信息)

salt '*' network.ip_addrs  #顯示IP地址

salt '*' network.interfaces

##pkg包管理模塊(被控主機(jī)程序包管理,如yum、apt-get等)

salt '*' pkg.install httpd   #安裝httpd服務(wù)

salt '*' pkg.file_list httpd   #查看軟件安裝以后生成的路徑文件

##service 服務(wù)模塊(被控主機(jī)程序包服務(wù)管理)

salt '*' service.enable httpd

salt '*' service.disable httpd

salt '*' service.status httpd

salt '*' service.stop httpd

salt '*' service.start httpd

salt '*' service.restart httpd

salt '*' service.reload httpd

salt 'Minion' state.sls one (one.sls)


saltstack YAML樣例

[root@master base]# cat init/zabbix_agent.sls 

zabbix-agent:

 pkg.installed:

  - name: zabbix-agent

 file.managed:

  - name: /etc/zabbix_agentd.conf

  - source: salt://zabbix/files/zabbix_agentd.conf

  - template: jinja

  - defaults: 

  - Server: {{ pillar['zabbix-agent']['Zabbix_Server'] }}

  - require:

   - pkg: zabbix-agent

 service.running:

  - enable: True

  - watch:

   - pkg: zabbix-agent

   - file: zabbix-agent 

zabbix_agentd.conf.d:

 file.directory:

  - name: /etc/zabbix_agentd.conf.d

  - watch_in:

   - service: zabbix-agent

  - require:

   - pkg: zabbix-agent

   - file: zabbix-agent

[root@master init]# cat history.sls 

/etc/profile:

 file.append:

  - text:

   - export HISTTIMEFORMAT="%F %T `whoami` "

[root@master init]# cat sysctl.sls 

net.ipv4.ip_local_port_range:

 sysctl.present:

  - value: 10000 65000

fs.file-max:

 sysctl.present: 

  - value: 2000000

net.ipv4.ip_forward:

 sysctl.present:

  - value: 1

vm.swappiness:

 sysctl.present:

  - value: 0

[root@master init]# cat epel.sls 

yum_repo_release:

 pkg.installed:

  - sources:

   - epel-release: http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm

  - unless: rpm -qa | grep 'zabbix-release-3.2-1.el6'

./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/sbin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts --with-gd --with-png-dir --with-jpeg-dir --with-freetype-dir -enable-bcmath --with-gettext

【騰訊云】云服務(wù)器、云數(shù)據(jù)庫、COS、CDN、短信等云產(chǎn)品特惠熱賣中

發(fā)表評(píng)論

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: