saltstack
CENTOS 6
i386 rpm -Uvh
x86_64 rpm-Uvh ftp://ftp.linux.ncsu.edu/pub/epel/6Server/x86_64/epel-release-6-8.noarch.rpm
yum install salt-master # 服务端
yum install salt-minion # 客户端
========== 报错
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
修改文件“/etc/yum.repos.d/epel.repo”, 将baseurl的注释取消, mirrorlist注释掉。必要时将enabled=0取消验证
====================
配置文件
/etc/salt/master
/etc/salt/minion
# 服务端
[root@localhost salt]# egrep -v '(^#|^$)' /etc/salt/master
publish_port: 4505
user: root
worker_threads: 5
ret_port: 4506
pidfile: /var/run/salt-master.pid
root_dir: /
pki_dir: /etc/salt/pki/master
cachedir: /var/cache/salt/master
auto_accept: True # 自动识别和信任salt客户端
file_roots: # salt提供服务的路径配置
base:
- /srv/salt
pillar_roots:
base:
- /srv/pillar
log_file: /var/log/salt/master.log
# 客户端
[root@localhost salt]# egrep -v '(^#|^$)' /etc/salt/minion
master: 10.10.10.133
master_port: 4506
user: root
pidfile: /var/run/salt-minion.pid
id: 10.10.10.133 #客户端ID,这里用IP显示
cachedir: /var/cache/salt/minion
output: nested
acceptance_wait_time: 10
acceptance_wait_time_max: 0
random_reauth_delay: 60
log_file: /var/log/salt/minion.log
====salt采用YAML语法,对tab支持不是很好,建议采用空格,一个两个空格都行,但必须保持代码块一致
============================================== salt自动部署配置nginx ======
mkdir /srv/salt/nginx -p
[root@localhost salt]# ls *
top.sls
#top.sls是告知salt,自动部署的入口所在
#由于master配置文件定义了file路径为/srv/salt,则top就必须放在/srv/salt下,否则salt执行异常
nginx:
install.sls nginx-1.6.2.tar.gz pcre-8.35.tar.gz
#提供给客户端文件,软件包需要放在/srv/salt/nginx下
[root@localhost salt]# cat top.sls
base: #base: 默认的的起点配置项:
'*': # '*': 这个引号内的是匹配对象,针对所有受控主机
- nginx.install
# 此处nginx为/srv/salt/nginx,install为/srv/salt/nginx/install.sls
[root@localhost salt]# cat install.sls.bak
#test
nginx_source:
file.recurse: # file.managed:用于单文件,file.recurse用于目录
- name: /tmp/
- source: salt://nginx/
extract_nginx:
cmd.run:
- cwd: /tmp
- names: # 多命令用names,单命令用name
- tar xf nginx-1.6.2.tar.gz
- tar xf pcre-8.35.tar.gz
- require:
- file: nginx_source
nginx_compile:
cmd.run:
- cwd: /tmp/nginx-1.6.2
- names:
- ./configure --prefix=/usr/local/nginx --with-pcre=/tmp/pcre-8.35 && make
- make install
- require:
- cmd: extract_nginx
========================================= salt 添加用户
#test_user:
# user.present:
# - name: test
# - uid: 1000
# - createhome: False
# - gid_from_name: True
# - shell: /sbin/nologin
阅读(3421) | 评论(0) | 转发(0) |