SALTStack · 3 min read · Jan 07, 2026

SALTStack 설치 및 사용 - 혼합 환경 - 페이지 2

설치된 SaltStack 테스트

Salt Master에서 모든 실행 중인 미니언에 PING:

root@salt-master:~# salt '*' test.ping

이름에 regexp를 사용할 수 있습니다:

root@salt-master:~# salt 'salt-[m]*' test.ping

결과는 다음과 같아야 합니다:

salt-minion1.test.local:
    True
salt-minion2.test.local:
    True
root@salt-master:~# salt 'salt-[!m]*' test.ping

결과는 다음과 같아야 합니다:

salt-centos:
    True

SaltStack의 단일 사용

다음 예제는 Salt-Master에서 Salt-Minions를 관리합니다.

호스트 이름 요청:

root@salt-master:~# salt '*' grains.item host
salt-minion1.test.local:
  host: salt-minion1
salt-minion2.test.local:
  host: salt-minion2
salt-centos:
  host: salt-centos

운영 체제 요청:

root@salt-master:~# salt '*' grains.item os
salt-minion2.test.local:
  os: Debian
salt-minion1.test.local:
  os: Debian
salt-centos:
  os: CentOS

이름으로 파일 찾기:

root@salt-master:~# salt '*' file.find /etc name=host\*.*
salt-centos:
    - /etc/host.conf
    - /etc/hosts.allow
    - /etc/hosts.deny
salt-minion2.test.local:
    - /etc/host.conf
    - /etc/hosts.allow
    - /etc/hosts.deny
    - /etc/init.d/hostname.sh
salt-minion1.test.local:
    - /etc/host.conf
    - /etc/hosts.allow
    - /etc/hosts.deny
    - /etc/init.d/hostname.sh

텍스트 파일의 내용 찾기:

root@salt-master:~# salt '*' file.contains /etc/ssh/sshd_config 'Port'
salt-centos:
    True
salt-minion1.test.local:
    True
salt-minion2.test.local:
    True

텍스트 파일의 내용 편집:

root@salt-master:~# salt '*' file.sed /etc/ssh/sshd_config 'Port 22' 'Port 2201'
salt-minion2.test.local:
    ----------
    pid:
        2555
    retcode:
        0
    stderr:
        
    stdout:
        
salt-minion1.test.local:
    ----------
    pid:
        2476
    retcode:
        0
    stderr:
        
    stdout:
        
salt-centos:
    ----------
    pid:
        1490
    retcode:
        0
    stderr:
        
    stdout:

폴더 생성:

root@salt-master:~# salt '*' file.makedirs /tmp/testFolder/
salt-minion2.test.local:
    None
salt-minion1.test.local:
    None
salt-centos:
    None

빈 파일 생성:

root@salt-master:~# salt '*' file.touch /tmp/testFolder/emptyFile
salt-centos:
    True
salt-minion1.test.local:
    True
salt-minion2.test.local:
    True

디렉토리 트리 제거:

root@salt-master:~# salt '*' file.remove /tmp/testFolder/
salt-minion1.test.local:
    True
salt-minion2.test.local:
    True
salt-centos:
    True

/etc/hosts 파일 관리:

root@salt-master:~# salt '*' hosts.add_host 192.168.122.1 kvmhost.test.local
salt-minion2.test.local:
    True
salt-centos:
    True
salt-minion1.test.local:
    True

마스터에서 미니언의 서비스 관리:

salt '*' service.get_all
salt '*' service.status nginx
salt '*' service.reload ssh
salt '*' service.disable rsync
salt '*' service.get_disabled

서비스가 설치되지 않은 경우 실패가 발생합니다.

마스터에서 미니언으로 패키지 설치:

다양한 배포판에서 한 번의 명령으로 패키지를 설치할 수 있습니다:

root@salt-master:/srv/salt# salt '*' pkg.install subversion
salt-centos:
    ----------
    apr:
        ----------
        new:
            1.3.9-5.el6_2
        old:
    apr-util:
        ----------
        new:
            1.3.9-3.el6_0.1
        old:
    gnutls:
        ----------
        new:
            2.8.5-10.el6_4.2
        old:
    libproxy:
        ----------
        new:
            0.3.0-4.el6_3
        old:
    libproxy-bin:
        ----------
        new:
            0.3.0-4.el6_3
        old:
    libproxy-python:
        ----------
        new:
            0.3.0-4.el6_3
        old:
    libtasn1:
        ----------
        new:
            2.3-3.el6_2.1
        old:
    neon:
        ----------
        new:
            0.29.3-3.el6_4
        old:
    pakchois:
        ----------
        new:
            0.4-3.2.el6
        old:
    perl-URI:
        ----------
        new:
            1.40-2.el6
        old:
    subversion:
        ----------
        new:
            1.6.11-9.el6_4
        old:

salt-minion1.test.local:
    ----------
    libapr1:
        ----------
        new:
            1.4.6-3+deb7u1
        old:
    libaprutil1:
        ----------
        new:
            1.4.1-3
        old:
    libneon27-gnutls:
        ----------
        new:
            0.29.6-3
        old:
    libsvn1:
        ----------
        new:
            1.6.17dfsg-4+deb7u4
        old:
    subversion:
        ----------
        new:
            1.6.17dfsg-4+deb7u4
        old:

설치 후 결과를 확인할 수 있습니다:

root@salt-master:/srv/salt# salt '*' cmd.run "svn --version --quiet"
salt-minion2.test.local:
    1.6.17
salt-minion1.test.local:
    1.6.17
salt-centos:
    1.6.11

Debian 미니언에 MYSQL 설치

단일 패키지보다 약간 복잡합니다.

root@salt-master:~# salt 'salt-mini*' pkg.install python-mysqldb
salt-minion1.test.local:
    ----------
    libmysqlclient18:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
            
    mysql-common:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
            
    python-mysqldb:
        ----------
        new:
            1.2.3-2
        old:
            

salt-minion2.test.local:
    ----------
    libmysqlclient18:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
            
    mysql-common:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    python-mysqldb: 
        ----------
        new:
            1.2.3-2
        old:

이 명령을 모든 서버에서 실행하면 CentOS에서 문제가 발생한 것을 볼 수 있습니다.

/var/log/salt/minion에서 세부 정보를 확인할 수 있습니다. 충분하지 않으면 /etc/salt/minion에서 로그 레벨을 높이십시오.

자세한 내용은 다루지 않겠지만, 해결하기 어렵지 않습니다.

SaltStack으로 mysql을 관리하려면 mysql_salt.conf 파일이 있어야 합니다.

앞서 언급했듯이, 원격으로도 관리할 수 있습니다:

root@salt-master:~# salt 'salt-mini*' file.append /etc/salt/minion.d/mysql_salt.conf \ "mysql.host: 'localhost'" \ "mysql.port: 3306" \ "mysql.user: 'root'" \ "mysql.pass: ''" \ "mysql.db: 'mysql'"
salt-minion2.test.local:
    Wrote 5 lines to "/etc/salt/minion.d/mysql_salt.conf"
salt-minion1.test.local:
    Wrote 5 lines to "/etc/salt/minion.d/mysql_salt.conf"

이 시점에서 Salt-Minion을 재시작해야 합니다.

salt는 “salt ‘salt-mini*’ service.restart salt-minion”으로 스스로 재시작할 수 없으므로, 트릭을 사용해야 합니다:

root@salt-master:~# salt 'salt-mini*' cmd.run "/etc/init.d/salt-minion restart"
salt-minion2.test.local:
    Restarting salt minion control daemon: salt-minion.
salt-minion1.test.local:
    Restarting salt minion control daemon: salt-minion.
root@salt-master:~# salt 'salt-mini*' pkg.install mysql-server
salt-minion1.test.local:
    ----------
    libaio1:
        ----------
        new:
            0.3.109-3
        old:
    libdbd-mysql-perl:
        ----------
        new:
            4.021-1+b1
        old:
    libdbi-perl:
        ----------
        new:
            1.622-1
        old:
    libhtml-template-perl:
        ----------
        new:
            2.91-1
        old:
    libnet-daemon-perl:
        ----------
        new:
            0.48-1
        old:
    libplrpc-perl:
        ----------
        new:
            0.2020-2
        old:
    mysql-client-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-core-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:

salt-minion2.test.local:
    ----------
    libaio1:
        ----------
        new:
            0.3.109-3
        old:
    libdbd-mysql-perl:
        ----------
        new:
            4.021-1+b1
        old:
    libdbi-perl:
        ----------
        new:
            1.622-1
        old:
    libhtml-template-perl:
        ----------
        new:
            2.91-1
        old:
    libnet-daemon-perl:
        ----------
        new:
            0.48-1
        old:
    libplrpc-perl:
        ----------
        new:
            0.2020-2
        old:
    mysql-client-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:
    mysql-server-core-5.5:
        ----------
        new:
            5.5.31+dfsg-0+wheezy1
        old:

Salt-master에서 미니언의 MySQL 관리

이제 Debian 머신에서 SaltStack DB 관리 명령을 사용할 수 있습니다:

root@salt-master:~# salt 'salt-mini*' mysql.db_create 'dbname'
salt-minion2.test.local:
    True
salt-minion1.test.local:
    True
root@salt-master:~# salt 'salt-mini*' mysql.db_list
salt-minion2.test.local:
    - information_schema
    - dbname
    - mysql
    - performance_schema
    - test
salt-minion1.test.local:
    - information_schema
    - dbname
    - mysql
    - performance_schema
    - test
Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.