15 interface: 0.0.0.0 22 publish_port: 4505 32 ret_port: 4506
#!/bin/bash
cd /usr/local/src/
wget http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum install python-devel
yum install salt-master -y
sed -i -r 's/^#interface: 0.0.0.0/interface: 0.0.0.0/' master
sed -i -r 's/^#publish_port: 4505/publish_port: 4505/' master
sed -i -r 's/^#worker_threads: 5/worker_threads: 5/' master
sed -i -r 's/^#ret_port: 4506/ret_port: 4506/' master
iptables -I INPUT -p tcp --dport 4505 -j ACCEPT
iptables -I INPUT -p tcp --dport 4506 -j ACCEPT
iptables-save > /etc/sysconfig/iptables
chkconfig salt-master on
service salt-master start
-
作者:燕涛 链接:http://www.jianshu.com/p/df98836f46e9 來源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
ssh-copy-id root@server3 ssh-copy-di root@server2 scp /etc/yum.repo.d/salt-latest.repo root@serve3:/etc/yum.repo.d/ scp /etc/yum.repo.d/salt-latest.repo root@serve2:/etc/yum.repo.d/ yum clean all yum install -y salt-minion vim /etc/salt/minion master: master IP id: minion自己的IP vim /etc/salt/master master : master自己的IP
-
key:values
-
-
- Name1
- Name2
- Name3
-
language:
- python
- C
- C++
website:
YAML: yaml.org
Perl:perl.org
- - 纯量:单个不可再分的值(字符串、布尔值、整数、浮点数、Null、时间、日期)
-
number:12.30
str:memgran is a guapi
wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar zxcvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
tar zxcvf Python-2.7.8.tgz
cd Python-2.7.8
./configure --prefix=/usr/local
make
make install
cd /usr/local/include/python2.7
cp -a ./* /usr/local/include/
- - 安装 setuptools:
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.tar.gz
tar xvzf setuptools-7.0.tar.gz
cd setuptools-7.0
python setup.py install
- - 安装 pycrypto:
wget https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.1.tar.gz
tar xvzf pycrypto-2.6.1.tar.gz
cd pycrypto-2.6.1
python setup.py install
-
wget http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz
tar xvzf yaml-0.1.5.tar.gz
cd yaml-0.1.5
./configure --prefix=/usr/local
make
make install
-
wget https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.11.tar.gz
tar xvzf PyYAML-3.11.tar.gz
cd PyYAML-3.11
python setup.py install
-
wget https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-0.9.3.tar.gz
tar xvzf MarkupSafe-0.9.3.tar.gz
cd MarkupSafe-0.9.3
python setup.py install
wget https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.3.tar.gz
tar xvzf Jinja2-2.7.3.tar.gz
cd Jinja2-2.7.3
python setup.py install
- - paramiko模块安装
wget https://pypi.python.org/packages/source/e/ecdsa/ecdsa-0.11.tar.gz
tar xvzf ecdsa-0.11.tar.gz
cd ecdsa-0.11
python setup.py install
wget https://pypi.python.org/packages/source/p/paramiko/paramiko-1.15.1.tar.gz
tar xvzf paramiko-1.15.1.tar.gz
cd paramiko-1.15.1
python setup.py install
-
wget https://pypi.python.org/packages/source/s/simplejson/simplejson-3.6.5.tar.gz
tar xvzf simplejson-3.6.5.tar.gz
cd simplejson-3.6.5
python setup.py install
-
wget https://github.com/ansible/ansible/archive/v1.7.2.tar.gz
tar xvzf ansible-1.7.2.tar.gz
cd ansible-1.7.2
python setup.py install
ssh-keygen
ssh-copy-id root@server5
scp -r .ssh/ root@server3:
ssh root@server3
mdkir -p /etc/ansible
vim /etc/ansible/ansible.cfg
[defaults]
host_key_checking = False
vim /etc/ansible/hosts
[servers]
192.168.109.131
192.168.109.138
-
Options:
-a MODULE_ARGS, --args=MODULE_ARGS
module arguments
-k, --ask-pass ask for SSH password
--ask-su-pass ask for su password
-K, --ask-sudo-pass ask for sudo password
--ask-vault-pass ask for vault password
-B SECONDS, --background=SECONDS
run asynchronously, failing after X seconds
(default=N/A)
-C, --check don't make any changes; instead, try to predict some
of the changes that may occur
-c CONNECTION, --connection=CONNECTION
connection type to use (default=smart)
-f FORKS, --forks=FORKS
specify number of parallel processes to use
(default=5)
-h, --help show this help message and exit
-i INVENTORY, --inventory-file=INVENTORY
specify inventory host file
(default=/etc/ansible/hosts)
-l SUBSET, --limit=SUBSET
further limit selected hosts to an additional pattern
--list-hosts outputs a list of matching hosts; does not execute
anything else
-m MODULE_NAME, --module-name=MODULE_NAME
module name to execute (default=command)
-M MODULE_PATH, --module-path=MODULE_PATH
specify path(s) to module library
(default=/usr/share/ansible/)
-o, --one-line condense output
-P POLL_INTERVAL, --poll=POLL_INTERVAL
set the poll interval if using -B (default=15)
--private-key=PRIVATE_KEY_FILE
use this file to authenticate the connection
-S, --su run operations with su
-R SU_USER, --su-user=SU_USER
run operations with su as this user (default=root)
-s, --sudo run operations with sudo (nopasswd)
-U SUDO_USER, --sudo-user=SUDO_USER
desired sudo user (default=root)
-T TIMEOUT, --timeout=TIMEOUT
override the SSH timeout in seconds (default=10)
-t TREE, --tree=TREE log output to this directory
-u REMOTE_USER, --user=REMOTE_USER
connect as this user (default=root)
--vault-password-file=VAULT_PASSWORD_FILE
vault password file
-v, --verbose verbose mode (-vvv for more, -vvvv to enable
connection debugging)
--version show program's version number and exit
- - 测试 - ping
[root@server5 ~]# ansible servers -m ping
192.168.109.131 | success >> {
"changed": false,
"ping": "pong"
}
192.168.109.138 | success >> {
"changed": false,
"ping": "pong"
}
- - command
[root@server5 ~]# ansible servers -m command -a 'uptime'
192.168.109.131 | success | rc=0 >>
23:15:59 up 1:38, 5 users, load average: 0.05, 0.04, 0.05
192.168.109.138 | success | rc=0 >>
23:15:59 up 3:59, 6 users, load average: 0.00, 0.01, 0.05
-
[root@server5 ~]# ansible servers -m setup
192.168.109.131 | success >> {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"192.168.122.1",
"192.168.109.131"
],
"ansible_all_ipv6_addresses": [
"fe80::52c2:81e3:8c97:2e0"
],
"ansible_architecture": "x86_64",
"ansible_bios_date": "07/02/2015",
"ansible_bios_version": "6.00",
"ansible_cmdline": {
"BOOT_IMAGE": "/vmlinuz-3.10.0-514.el7.x86_64",
"LANG": "en_US.UTF-8",
"crashkernel": "auto",
"quiet": true,
"rhgb": true,
"ro": true,
"root": "UUID=8a43bc9e-303d-4271-92b8-bbb171dcf551"
},
-
-
[root@server5 ~]# ansible servers -m file -a "src=/etc/hosts dest=/tmp/hosts state=link"
192.168.109.131 | success >> {
"changed": true,
"dest": "/tmp/hosts",
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"secontext": "unconfined_u:object_r:user_tmp_t:s0",
"size": 10,
"src": "/etc/hosts",
"state": "link",
"uid": 0
}
192.168.109.138 | success >> {
-
[root@server5 ~]# ll /tmp/hosts
lrwxrwxrwx. 1 root root 10 Aug 14 14:28 /tmp/hosts -> /etc/hosts
[root@server3 ~]# ll /tmp/hosts
lrwxrwxrwx. 1 root root 10 Aug 13 23:28 /tmp/hosts -> /etc/hosts
-
-
[root@server5 ~]# ansible servers -m copy -a "src=/etc/ansible/ansible.cfg dest=/tmp/ansible.cfg owner=root group=root mode=0644"
[root@server3 ~]# ll /tmp/ansible.cfg
-rw-r--r--. 1 root root 37 Aug 13 23:33 /tmp/ansible.cfg
[root@server5 ~]# ansible servers -m copy -a "src=/root/test.sh dest=/root/test.sh owner=root group=root mode=0755"
192.168.109.138 | success >> {
"changed": false,
"dest": "/root/test.sh",
"gid": 0,
"group": "root",
"md5sum": "7c73186c5baeeced9773809d51f55903",
"mode": "0755",
"owner": "root",
"path": "/root/test.sh",
"secontext": "unconfined_u:object_r:admin_home_t:s0",
"size": 17,
"state": "file",
"uid": 0
}
192.168.109.131 | success >> {
"changed": true,
"dest": "/root/test.sh",
"gid": 0,
"group": "root",
"md5sum": "7c73186c5baeeced9773809d51f55903",
"mode": "0755",
"owner": "root",
"secontext": "system_u:object_r:admin_home_t:s0",
"size": 17,
"src": "/root/.ansible/tmp/ansible-tmp-1502692717.29-206531122290598/source",
"state": "file",
"uid": 0
}
-
[root@server5 ~]# ansible servers -m shell -a "/root/test.sh"
192.168.109.138 | success | rc=0 >>
Sun Aug 13 23:40:29 PDT 2017
192.168.109.131 | success | rc=0 >>
Sun Aug 13 23:40:29 PDT 2017
[root@server5 ~]# ansible-doc -l
acl Sets and retrieves file ACL information.
add_host add a host (and alternatively a group) to
airbrake_deployment Notify airbrake about app deployments
alternatives Manages alternative programs for common c