标签:saltstack jinja apache httpd template
1,安装saltstack
服务端:salt-master
客户端:salt-minion
yum install -y salt-master yum install -y salt-minion
2,开放服务端iptables
iptables -A INPUT -m state --state new -m tcp -p tcp --dport 4505 -j ACCEPT iptables -A INPUT -m state --state new -m tcp -p tcp --dport 4506 -j ACCEPT
3,启动服务
服务端:
vim /etc/salt/master interface: 服务器监听IP,#默认0.0.0.0
启动服务:
/etc/init.d/salt-master start
开机启动:
chkconfig salt-master on
调试模式:
salt-master -l dubeg
后台运行:
salt-master -d
监听端口:
4505(publish_port):salt消息发布系统
4506(ret_port):salt客户端与服务端通信端口
客户端:
vim /etc/salt/minion master: 服务端主机名 id: 客户端主机名(在服务端看到客户端的名字)
启动服务:
/etc/init.d/salt-minion start
开机启动:
chkconfig salt-minion on
4,key颁发
salt-key Accepted Keys: Unaccepted Keys: test.itnihao.com Rejected Keys: salt-key -A #添加所有客户端 salt-key -a minion-id #添加单独一个minion id
5,测试
salt \* test.ping VM-243: True VM-244: True VM-245: True VM-242: True
以上步骤是安装saltstack完成,并正常通信
下面要配置客户端服务安装,文件同步等
6,安装apache
创建入口文件:
mkdir /srv/salt -p vim /srv/salt/top.sls base: ‘*‘: #匹配客户端,"*"匹配表示匹配所有 - web.apache #web目录下apache.sls文件 mkdir /srv/salt/web vim /srv/salt/web/apache.sls apache_install: pkg: - name: httpd - installed service: - name: httpd - running - reload: True - watch: - file: /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf: file.managed: - source: salt://web/httpd.conf.jinja - template: jinja - user: root - group: root - mode: 644 - backup: minion /var/www/html/index.html: file.managed: - source: salt://web/index.html.jinja - template: jinja vim /srv/salt/web/httpd.conf.jinja <VirtualHost *:80> ServerName {{ salt[‘network.interfaces‘]()[‘eth0‘][‘inet‘][0][‘address‘] }} DocumentRoot /var/www/html/ ErrorLog logs/error.log CustomLog logs/access.log common </VirtualHost> vim /srv/salt/web/index.html.jinja <h1>Welcome to {{ grains[‘fqdn‘] }}</h1>
运行命令
salt \* state.sls web.apache VM-242: ---------- ID: apache_install Function: pkg.installed Name: httpd Result: True Comment: Package httpd is already installed. Started: 13:52:15.979353 Duration: 639.22 ms Changes: ---------- ID: /etc/httpd/conf/httpd.conf Function: file.managed Result: True Comment: File /etc/httpd/conf/httpd.conf is in the correct state Started: 13:52:16.723650 Duration: 80.393 ms Changes: ---------- ID: apache_install Function: service.running Name: httpd Result: True Comment: The service httpd is already running Started: 13:52:16.807976 Duration: 41.296 ms Changes: ---------- ID: /var/www/html/index.html Function: file.managed Result: True Comment: File /var/www/html/index.html updated Started: 13:52:16.853234 Duration: 16.49 ms Changes: ---------- diff: New file mode: 0644 Summary ------------ Succeeded: 4 (changed=1) Failed: 0 ------------ Total states run: 4
测试,打开网页访问
本文出自 “charlie_cen” 博客,请务必保留此出处http://charlie928.blog.51cto.com/3741218/1682682
标签:saltstack jinja apache httpd template
原文地址:http://charlie928.blog.51cto.com/3741218/1682682