Salzstapel im Zusammenhang

vermuten:

Salt-Server: AMH

salt-minion: AMH , client1741 , cdn-nginx , cdn-varnish

查看salt-minion是否 在线

[root @ AMH ~]# Salz '*’ test.ping

cdn-nginx:

True

client1741:

True

AMH:

True

cdn-varnish:

True

 

查看所有的minion,包括认证的和没有认证的

[root @ AMH ~]# salt-key -L

Accepted Keys:

AMH

cdn-nginx

cdn-varnish

client1741

Denied Keys:

Unaccepted Keys:

Rejected Keys:

 

添加一个minion

[root @ AMH ~]# salt-key -a

添加所有的minion

[root @ AMH ~]# salt-key -A

删除一个minion

[root @ AMH ~]# salt-key -d

Z.B:

[root @ AMH ~]# salt-key -d 192.168.17.111

The following keys are going to be deleted:

Accepted Keys:

192.168.17.111

Proceed? [N/y] Ja

Key for minion 192.168.17.111 gelöscht.

删除所有的minion

[root @ AMH ~]# salt-key -D

执行salt-keyhelp 可以看到更多用法

 

cmd.run

执行简单的命令

[root @ AMH ~]# Salz '*’ cmd.run ‘date

cdn-nginx:

Tue Apr 17 14:11:31 CST 2018

client1741:

Tue Apr 17 14:11:31 CST 2018

AMH:

Tue Apr 17 14:11:31 CST 2018

cdn-varnish:

Tue Apr 17 14:11:32 CST 2018

[root @ AMH ~]# Salz '*’ cmd.run ‘df -h

client1741:

Verwendete Dateisystemgröße Verfügbar Verwenden Sie% Mounted on

/dev/mapper/VolGroup-lv_root 28G 7.3G 19G 29% /

tmpfs 242M 12K 242M 1% /dev / shm

/dev / sda1 485M 35M 426M 8% /booten

cdn-varnish:

Verwendete Dateisystemgröße Verfügbar Verwenden Sie% Mounted on

/dev/mapper/VolGroup-lv_root 28G 7.3G 19G 29% /

tmpfs 242M 12K 242M 1% /dev / shm

/dev / sda1 485M 35M 426M 8% /booten

AMH:

Verwendete Dateisystemgröße Verfügbar Verwenden Sie% Mounted on

/dev/mapper/VolGroup-lv_root 28G 13G 14G 47% /

tmpfs 301M 16K 301M 1% /dev / shm

/dev / sda1 485M 35M 426M 8% /booten

cdn-nginx:

Verwendete Dateisystemgröße Verfügbar Verwenden Sie% Mounted on

/dev/mapper/VolGroup-lv_root 28G 9.4G 17G 37% /

tmpfs 242M 12K 242M 1% /dev / shm

/dev/sda1 477M 55M 398M 12% /booten

 

让master上的脚本在远程执行

vim /etc/salt/master配置文件

添加红框中的内容

conf1

/etc/init.d/salt-master restart

在/srv/salt/下创建script目录编辑查看日期的脚本

vim /srv/salt/script/date.sh

#!/bin / bash

echo “show current time”

Wir können die Konfigurationsdatei my.cnf hinzufügen

#end

salt_config2

master执行这个脚本

Salz '*’ cmd.script salt://script/data.sh

salt_config3

 

[root@AMH script]# Salz '*’ cmd.script salt://script/date.sh

AMH:

———-

pid:

2022

retcode:

0

stderr:

stdout:

show current time

Tue Apr 17 14:28:51 CST 2018

cdn-nginx:

———-

pid:

50672

retcode:

0

stderr:

stdout:

show current time

Tue Apr 17 14:28:51 CST 2018

client1741:

———-

pid:

2488

retcode:

0

stderr:

stdout:

show current time

Tue Apr 17 14:28:51 CST 2018

cdn-varnish:

———-

pid:

3195

retcode:

0

stderr:

stdout:

show current time

Tue Apr 17 14:28:51 CST 2018

 

cp.get_file和cp.get_dir

将master上的脚本传到远程服务器的/opt目录下

假设脚本sysinfo.sh 放在 /srv/salt/上

[root@AMH salt]# Salz '*’ cp.get_file salt://sysinfo.sh /opt/sysinfo.sh

或者采用gzip压缩方式分发该脚本

[root@AMH salt]# Salz '*’ cp.get_file salt://sysinfo.sh /opt/sysinfo.sh gzip=6

然后执行 salt ‘*cmd.run ‘ls /opt/sysinfo.sh看每台服务器是否存在该文件

salt_config4

 

每一台minion执行此脚本

[root@AMH salt]# Salz '*’ cmd.script ‘/opt/sysinfo.sh

salt_config5

 

将test_dir目录传到 minion的/tmp下

[root@AMH salt]#salt '*' cp.get_dir salt://test_dir /tmp gzip=6 

 

pkg模块

相当于RHEL的yum 和ubuntu的apt-get

Salz '*’ pkg.install package

Salz '*’ pkg.remove package

举例

[root@AMH salt]# Salz '*’ pkg.install httpd

client1741:

———-

AMH:

———-

cdn-nginx:

———-

httpd:

———-

new:

2.2.15-60.el6.centos.6

old:

2.2.15-29.el6.centos

httpd-manual:

———-

new:

2.2.15-60.el6.centos.6

old:

2.2.15-29.el6.centos

httpd-tools:

———-

new:

2.2.15-60.el6.centos.6

old:

2.2.15-29.el6.centos

mod_ssl:

———-

new:

1:2.2.15-60.el6.centos.6

old:

1:2.2.15-29.el6.centos

cdn-varnish:

———-

httpd:

———-

new:

2.2.15-60.el6.centos.6

old:

2.2.15-29.el6.centos

httpd-manual:

———-

new:

2.2.15-60.el6.centos.6

old:

2.2.15-29.el6.centos

httpd-tools:

———-

new:

2.2.15-60.el6.centos.6

old:

2.2.15-29.el6.centos

mod_ssl:

———-

new:

1:2.2.15-60.el6.centos.6

old:

1:2.2.15-29.el6.centos

[root@AMH salt]# Salz '*’ cmd.run ‘rpm -qa | grep httpd

cdn-nginx:

httpd-tools-2.2.15-60.el6.centos.6.x86_64

httpd-2.2.15-60.el6.centos.6.x86_64

httpd-manual-2.2.15-60.el6.centos.6.noarch

cdn-varnish:

httpd-manual-2.2.15-60.el6.centos.6.noarch

httpd-tools-2.2.15-60.el6.centos.6.x86_64

httpd-2.2.15-60.el6.centos.6.x86_64

client1741:

httpd-manual-2.2.15-60.el6.centos.6.noarch

httpd-2.2.15-60.el6.centos.6.x86_64

httpd-tools-2.2.15-60.el6.centos.6.x86_64

httpd-devel-2.2.15-60.el6.centos.6.x86_64

AMH:

httpd-tools-2.2.15-60.el6.centos.6.x86_64

httpd-2.2.15-60.el6.centos.6.x86_64

httpd-devel-2.2.15-60.el6.centos.6.x86_64

 

[root@AMH salt]# Salz '*’ pkg.remove httpd

cdn-nginx:

———-

gnome-user-share:

———-

new:

old:

2.28.2-3.el6

httpd:

———-

new:

old:

2.2.15-60.el6.centos.6

httpd-manual:

———-

new:

old:

2.2.15-60.el6.centos.6

mod_auth_kerb:

———-
new:

old:

5.4-10.el6

mod_perl:

———-

new:

old:

2.0.4-10.el6

mod_ssl

———-

new

old:

1:2.2.15-60.el6.centos.6

mod_wsgi:

———-

new:

old:

3.2-3.el6

php:

———-
new:

old:

5.3.3-26.el6

piranha:

———-

new:

old:

0.8.6-4.el6

AMH:

———-

httpd:

———-

new:

old:

2.2.15-60.el6.centos.6

httpd-devel

———-
new:

old:

2.2.15-60.el6.centos.6

php

———-

new:

old:

5.3.3-49.el6

client1741:

———-
gnome-user-share:
———-
new

old:

2.28.2-3.el6

httpd:

———-

new:

old:

2.2.15-60.el6.centos.6

httpd-devel:

———-

new:

old:

2.2.15-60.el6.centos.6

httpd-manual:

———-

new:

old:

2.2.15-60.el6.centos.6

ipa-server:

———-

new:

old:

3.0.0-37.el6

ipa-server-selinux:

———-

new:

old:

3.0.0-37.el6

mod_auth_kerb:

———-

new:

old:

5.4-10.el6

mod_perl:

———-

new:

old:

2.0.4-10.el6

mod_ssl:

———-

new:

old:

1:2.2.15-60.el6.centos.6

mod_wsgi:

———-
new:

old:

3.2-3.el6

php:

———-

new:

old:

5.3.3-26.el6

piranha:

———-

new:

old:

0.8.6-4.el6

webalizer:

———-

new:

old:

2.21_02-3.3.el6

cdn-varnish:

———-

gnome-user-share:

———-

new:

old:

2.28.2-3.el6

httpd:

———-

new:

old:

2.2.15-60.el6.centos.6

httpd-manual:

———-

new:

old:

2.2.15-60.el6.centos.6

ipa-server:

———-

new:

old:

3.0.0-37.el6

ipa-server-selinux:

———-

new:

old:

3.0.0-37.el6

mod_auth_kerb:

———-

new:

old:

5.4-10.el6

mod_perl:

———-

new:

old:

2.0.4-10.el6

mod_ssl:

———-

new:

old:

1:2.2.15-60.el6.centos.6

mod_wsgi:

———-

new:

old:

3.2-3.el6

php:

———-

new:

old:

5.3.3-26.el6

piranha:

———-

new:

old:

0.8.6-4.el6

webalizer:

———-

new:

old:

2.21_02-3.3.el6

 

service模块

salt ‘*’ service.enable service_name

salt ‘*’ service.disable service_name

salt ‘*’ service.start service_name

salt ‘*’ service.stop service_name

salt ‘*’ service.restart service_name

举例

salt_config7

salt_config8

 

Hinterlasse eine Antwort