|
环境:
192.168.2.249 CentOS Linux release 7.2.1511 (Core) x86_64 角色:master slave 注:机器有限,192.168.2.249 同为 master slave安装:
安装epel源
# yum -y install epel-release #安装源# yum search salt #搜索Loaded plugins: fastestmirror, priorities, product-id, search-disabled-repos, subscription-managerThis system is not registered with Subscription Management. You can use subscription-manager to register.Loading mirror speeds from cached hostfile * elrepo: mirrors.tuna.tsinghua.edu.cn * epel: ftp.cuhk.edu.hk======================================== N/S matched: salt ==========================================perl-Crypt-SaltedHash.noarch : Perl interface to functions that assist in working with salted hashespython-salttesting.noarch : Testing library for SaltStack projectssalt-api.noarch : REST API for Salt, a parallel remote execution systemsalt-cloud.noarch : Cloud provisioner for Salt, a parallel remote execution systemsalt-master.noarch : Management component for salt, a parallel remote execution systemsalt-minion.noarch : Client component for Salt, a parallel remote execution systemsalt-ssh.noarch : Agentless SSH-based version of Salt, a parallel remote execution systemsalt-syndic.noarch : Master-of-master component for Salt, a parallel remote execution systemsalt.noarch : A parallel remote execution system安装master
yum -y install salt-master安装slave
yum -y install salt-minion配置master
vim /etc/salt/masterdefault_include: master.d/*.confinterface: 0.0.0.0ipv6: Falsepublish_port: 4505 #监听端口号cachedir: /data/cache/salt/masterauto_accept: True #自动接受file_roots: base: - /data/salt/salt/ file_ignore_regex: - '/\.svn($|/)' - '/\.git($|/)' file_ignore_glob: - '*.pyc' - '*.swp' pillar_roots: base: - /data/salt/pillar 注:部分配置文件省略创建目录
mkdir -p /data/salt/pillar/mkdir -p /data/salt/salt/mkdir -p /data/cache/salt/master/配置minion
vim /etc/salt/minionmaster: 127.0.0.1id: localhost启动
service salt-master startservice salt-minion start查看
# salt-key Accepted Keys:localhost Denied Keys:Unaccepted Keys:Rejected Keys:常用命令
salt '*' test.ping #测试master与minion链接 * 表示匹配所有主机salt '*' cmd.run 'sehll命令' #远程执行命令 salt '*' disk.usage #查看磁盘使用情况salt '*' grains.items #查看grains所有信息salt '*' state.highstate #可以理解成同步# salt '*' test.pinglocalhost: True salt '*' cmd.run "df -h"localhost: Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 50G 3.4G 47G 7% / devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.8G 16K 3.8G 1% /dev/shm tmpfs 3.8G 8.5M 3.8G 1% /run tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup /dev/mapper/centos-home 408G 391M 407G 1% /home /dev/sda1 494M 195M 300M 40% /boot # salt '*' grains.itemslocalhost: ......................... host: hostname hwaddr_interfaces: ---------- enp2s0: xx:xx:xx:xx:xx:xx lo: 00:00:00:00:00:00 id: localhost init: systemd ip4_interfaces: ---------- enp2s0: - 192.168.2.249 - 192.168.2.216 lo: - 127.0.0.1 ip6_interfaces: ---------- enp2s0: - xxxx::xxxx:xxxx:xxxx:xxxx lo: - ::1 ip_interfaces: ---------- enp2s0: - 192.168.2.249 - 192.168.2.216 - xxxx::xxxx:xxxx:xxxx:xxxx lo: - 127.0.0.1 - ::1 ipv4: - 127.0.0.1 - 192.168.2.216 - 192.168.2.249 ipv6: - ::1 - xxxx::xxxx:xxxx:xxxx:xxxx kernel: Linux kernelrelease: 3.10.0-327.10.1.el7.x86_64 locale_info: ---------- defaultencoding: UTF-8 defaultlanguage: en_US detectedencoding: UTF-8 localhost: hostname lsb_distrib_id: CentOS Linux machine_id: e6c3365ab74743f399d46200f52480d5 manufacturer: Gigabyte Technology Co., Ltd. master: 127.0.0.1 mdadm: mem_total: 7692 nodename: admin-node num_cpus: 4 num_gpus: 1 os: CentOS os_family: RedHat osarch: x86_64 oscodename: Core osfinger: CentOS Linux-7 osfullname: CentOS Linux osmajorrelease: 7 osrelease: 7.2.1511 osrelease_info: - 7 - 2 - 1511 path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin ...........................同步文件配置:
# cd /data/salt/salt# vim top.sls # top 为入口文件base: '*': # '*' 表示匹配所有主机 - base.repo #同步软件源# mkdir base# vim base/repo.sls /etc/yum.repos.d/remi-php70.repo: #同步一个源 file.managed: - source: salt://base/files/etc/yum.repos.d/remi-php70.repo - user: root - group: root - mode: 644 - order: 1# mkdir base/files/etc/yum.repos.d/# vim base/files/etc/yum.repos.d/remi-php70.repo[remi-php70]name=Remi's PHP 7.0 RPM repository for Enterprise Linux $releasever - $basearchbaseurl=http://repo.55haitao.com:62080/remi/enterprise/$releasever/php70/$basearch/#mirrorlist=http://repo.55haitao.com:62080/remi/enterprise/$releasever/php70/mirrorenabled=0gpgcheck=0[remi-php70-debuginfo]name=Remi's PHP 7.0 RPM repository for Enterprise Linux $releasever - $basearch - debuginfobaseurl=http://repo.55haitao.com:62080/remi/enterprise/$releasever/debug-php70/$basearch/enabled=0gpgcheck=0[remi-php70-test]name=Remi's PHP 7.0 test RPM repository for Enterprise Linux $releasever - $basearchbaseurl=http://repo.55haitao.com:62080/remi/enterprise/$releasever/test70/$basearch/#mirrorlist=http://repo.55haitao.com:62080/remi/enterprise/$releasever/test70/mirrorenabled=0gpgcheck=0[remi-php70-test-debuginfo]name=Remi's PHP 7.0 test RPM repository for Enterprise Linux $releasever - $basearch - debuginfobaseurl=http://repo.55haitao.com:62080/remi/enterprise/$releasever/debug-test70/$basearch/enabled=0gpgcheck=0执行同步:
# salt '*' state.highstatelocalhost:---------- ID: /etc/yum.repos.d/remi-php70.repo Function: file.managed Result: True Comment: File /etc/yum.repos.d/remi-php70.repo is in the correct state Started: 15:06:41.837987 Duration: 17.243 ms Changes: Summary------------Succeeded: 1Failed: 0------------Total states run: 1设置自动同步
# cd /data/salt/pillar/# vim top.slsbase: '*': - schedule.highstate# mkdir schedule# vim schedule/highstate.sls schedule: highstate: function: state.highstate minutes: 1在master上修改Pilla文件后,需要用以下命令刷新minion上的数据
# salt '*' saltutil.refresh_pillarlocalhost: True查看minion拥有哪些Pillar数据
# salt '*' pillar.datalocalhost: ---------- schedule: ---------- highstate: ---------- function: state.highstate minutes: 1测试自动同步
# vim /data/salt/salt/base/files/etc/yum.repos.d/remi-php70.repo [remi-php70]name=Remi's PHP 7.0 RPM repository for Enterprise Linux $releasever - $basearchbaseurl=http://repo.55haitao.com:62080/remi/enterprise/$releasever/php70/$basearch/#mirrorlist=http://repo.55haitao.com:62080/remi/enterprise/$releasever/php70/mirrorenabled=1 #启用gpgcheck=0....................检测自动同步
# cat /etc/yum.repos.d/remi-php70.repo [remi-php70]name=Remi's PHP 7.0 RPM repository for Enterprise Linux $releasever - $basearchbaseurl=http://repo.55haitao.com:62080/remi/enterprise/$releasever/php70/$basearch/#mirrorlist=http://repo.55haitao.com:62080/remi/enterprise/$releasever/php70/mirrorenabled=1 #才修改的gpgcheck=0.................
|
|
|