Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Saltstack (the return value is written to the database)

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Goal (targeting Minions)

1. Match Minions Id

Match all (*)

[root@node1 salt] # salt'* 'test.pingnode2.minion:True

After the Standard PvP match is .minion.

[root@node1 salt] # salt'* .minion 'test.pingnode2.minion:True

Match a (? )

[root@node1 salt] # salt'* node?.minion' test.pingnode2.minion:True

Match multiple [1-5]

[root@node1 salt] # salt 'node [1-5] .minion' test.pingnode2.minion:True

Match a host with a host

[root@node1 salt] # salt 'node [2je 3] .minion' test.pingnode2.minion:True

Match aMuz

[root@node1 salt] # salt 'node2.minio [NMurz]' test.pingnode2.minion:True

two。 Regular matching:

-E

# hosts that match node2 or node3 followed by .minion [root@node1 salt] # salt-E'(node2 | node3) .minion 'test.pingnode2.minion: True can be used in the configuration file of sls to modify vim / etc/salt/states/top.slsbase: # match node2 or node3 followed by .minion host' (node2 | node3). Minion': # use regular-match: pcre-init.pkg

-L

# match multiple hosts, separated by commas [root@node1 states] # salt-L 'node2.minion,node3,minion' test.pingnode2.minion: True

-S ip address matching

Salt-S '0.0.0.0amp 24' test.ping

2. Module

1.hosts module

# get the IP address [root@node1 states] # salt'* 'hosts.get_ip node2node2.minion:127.0.0.1

2.service module

Get all minion host services [root@node1 states] # salt'* 'service.get_allnode2.minion:-abrt-ccpp-abrt-oops-abrtd-acpid-atd-auditd-blk-availability-control-alt-delete-crond-cups-elasticsearch-exim-halt-htcacheclean-httpd-init-system-dbus-ip6tables-ipmi-iptables-irqbalance-kexec-disable-killall-logstash-lvm2-lvmetad-lvm2-monitor-messagebus-netconsole-netfs-network-ntpd-ntpdate-php-fpm-php-fpm- Portreserve-pptpd-prefdm-psacct-quit-plymouth-quota_nld-rc-rcS- rcS-emergency-rcS-sulogin-rdisc-readahead- readahead-collector-readahead-disable-services-restorecond-rsyslog-salt-minion-sandbox-saslauthd-serial-shellinaboxd-single-smartd-snmpd-snmptrapd-splash-manager-sshd-start-ttys-svnserve-sysstat-tty-ttyS0-udev-post-zabbix-agent-zabbix-agentd-zabbix_agentd-zabbix_server to check the running status of the service [root@node1 states] # root@node1 states' * 'service.status sshdnode2.minion:True restart a service [root@node1 states] # salt' * 'service.reload sshdnode2.minion:True

3.salt-cp

Root@node1 minions] # salt-cp'*'/ etc/passwd / tmp/passwd {'node2.minion': {' / tmp/passwd': True}} [root@node1 minions] #

Return to write to database

Returners.mysql

By default, the result of command execution sent to salt minion is returned to salt master. Exe.

The interface of Saltstack Returner allows the result to be sent to any system

Install mysql on 1.master side

The first: omit the source package installation steps. The second: yum install mysql-server-y starts the mysql service.

Deploy MySQL-python on the 2.minion side

The principle of yum install MySQL-python is that minion pushes the data directly into master's database.

3. Create a database on the masterside

Access to the database

Create a library name

CREATE DATABASE `salt` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci

two。 Create a jid table

USE `salt`

DROP TABLE IF EXISTS `jids`

CREATE TABLE `jids` (`jid` varchar (255) NOT NULL, `load` mediumtext NOT NULL, UNIQUE KEY `jid` (`jid`))

ENGINE=InnoDB DEFAULT CHARSET=utf8

3. Create a return table

Store the returned data

DROP TABLE IF EXISTS `salt_ roomns`

CREATE TABLE `salt_ Secretns` (`fun` varchar (50) NOT NULL, `jid` varchar (25551) NOT NULL, `funn` mediumtext NOT NULL, `id`varchar (2555i) NOT NULL, `room`varchar (10) NOT NULL, `full_ ret` mediumtext NOT NULL, `alter_ time`TIMESTAMP DEFAULT CURRENT_TIMESTAMP, KEY `id` (`id`), KEY `jid` (`jid`), KEY `fun` (`fun`) ENGINE=InnoDB DEFAULT CHARSET=utf8

4. Create an event table

DROP TABLE IF EXISTS `salt_ events`

CREATE TABLE `salt_ events` (`id` BIGINT NOT NULL AUTO_INCREMENT, `tag` varchar (255) NOT NULL, `data` mediumtext NOT NULL, `alter_ time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `master_ id` varchar (255) NOT NULL,PRIMARY KEY (`id`), KEY `tag` (`tag`) ENGINE=InnoDB DEFAULT CHARSET=utf8

5. Authorized access

Grant all on salt.* to salt@'%' identified by 'salt'

Note:% does not include localhosts

4. Modify the configuration file in master

# vi / etc/salt/master

Append the following to the configuration file

Mysql.host: '115.29.51.8'

Mysql.user: 'salt'

Mysql.pass: 'salt'

Mysql.db: 'salt'

Mysql.port: 3306

5. Modify the configuration file in minion

# vi / etc/salt/minion

Append the following to the configuration file

Mysql.host: '115.29.51.8'

Mysql.user: 'salt'

Mysql.pass: 'salt'

Mysql.db: 'salt'

Mysql.port: 3306

Both the 6.master and Minion end restart the service

Master: # service salt-master restart

Minion side: # / etc/init.d/salt-minion restart

7. test

# salt'* 'test.ping-- return

Mysqlnode2.minion: True#

Salt'* 'cmd.run' df-TH'-return=mysql

Node2.minion: Filesystem Type Size Used Avail Use% Mounted on / dev/vda1 ext3 8.5G 4.3G 3.8G 54% /

Check it in the database

Method 2:

If the return=mysql is not added for each execution, the returned data is written to the database by the master side

1. Modify master configuration file

# vi / etc/salt/master append the following to the configuration file: master_job_cache: mysql

two。 Restart master

# service salt-master restart

3. test

Process outline

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report