最近在研究saltstack,尝试安装一下nginx,代码如下:
master配置:
0 1 2 3 4 5 6 7 8 9 10 11 |
[root@SaltM ~]# salt 'Salt1.t4x.org' state.highstate [root@SaltM ~]# head -414 /etc/salt/master | tail # Example: file_roots: base: - /srv/salt/ dev: - /srv/salt/dev/services - /srv/salt/dev/states prod: - /srv/salt/prod/services - /srv/salt/prod/states |
目录结构:
0 1 2 3 4 5 6 7 8 |
[root@SaltM salt]# tree . ├── nginx │ ├── files │ │ ├── nginx-1.7.4.tar.gz │ │ └── nginx.conf │ ├── nginx.sls │ └── pkg.sls └── top.sls |
top.sls配置:
0 1 2 3 4 |
[root@SaltM salt]# cat top.sls base: 'Salt1.t4x.org': - nginx.pkg - nginx.nginx |
pkg.sls配置:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@SaltM salt]# cat nginx/pkg.sls nginx.installation: pkg.installed: - names: - gcc - gcc-c++ - lrzsz - vim-enhanced - tree - wget - unzip - dos2unix - openssl - pcre - pcre-devel - openssl-devel |
nginx.sls配置:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
[root@SaltM salt]# cat nginx/nginx.sls include: - nginx.pkg ngixn_user: user.present: - name: http - uid: 498 - gid: 498 - system: True - shell: /sbin/nologin - gid_from_name: True - createhome: False nginx_install: file.managed: - name: /usr/local/src/nginx-1.7.4.tar.gz - source: salt://nginx/files/nginx-1.7.4.tar.gz - user: root - group: root - mode: 644 cmd.run: - cwd: /usr/local/src/ - names: - tar zxf nginx-1.7.4.tar.gz - echo `pwd` >> /tmp/1.2 - cd /usr/local/src/nginx-1.7.4 && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/client/ --http-proxy-temp-path=/usr/local/nginx/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ --with-poll_module --with-file-aio --with-http_realip_module --with-http_addition_module --with-http_random_index_module --with-pcre --with-http_stub_status_module && make && make install - unless: test -f /usr/local/nginx/conf/nginx.conf nginx_config_file: file.managed: - name: /usr/local/nginx/conf/nginx.conf - source: salt://nginx/files/nginx.conf - user: root - group: root - mode: 644 service.running: - name: nginx - enable: True - reload: True - watch: - file: /usr/local/nginx/conf/*.conf |
客户端脚本:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx start() { /usr/local/nginx/sbin/nginx } stop() { /usr/local/nginx/sbin/nginx -s stop } reload() { /usr/local/nginx/sbin/nginx -s reload } case $1 in start) start && exit 0 ;; stop) stop ;; reload) stop start ;; esac |
完整版:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
[root@Test1 /]# tree srv/ srv/ └── salt ├── prod │ ├── files │ │ ├── hosts │ │ ├── nginx.conf │ │ └── profile │ ├── hosts.sls │ ├── java.sls │ ├── nginx.sls │ ├── nginx.sls.bk │ ├── nginx.sls.bo2 │ ├── package │ │ ├── apache-tomcat-8.0.35.tar.gz │ │ ├── GeoIP.tar.gz │ │ ├── GeoLiteCity.dat │ │ ├── jdk-8u101-linux-x64.tar.gz │ │ ├── lua-5.3.3.tar.gz │ │ ├── LuaJIT-2.0.4.tar.gz │ │ ├── nginx-1.10.1.tar.gz │ │ ├── ngx_cache_purge-2.3.tar.gz │ │ ├── ngx_http_substitutions_filter_module-master.zip │ │ ├── openssl-1.0.2j.tar.gz │ │ ├── pcre-8.39.tar.gz │ │ ├── v0.10.6.tar.gz │ │ └── v0.3.0.tar.gz │ ├── pkg.sls │ └── tomcat.sls └── top.sls |
下载地址(实验基于centos 6.8):链接: http://pan.baidu.com/s/1boNiraZ 密码: p6zrSourceByrd's Weblog-https://note.t4x.org/basic/saltstack-install-nginx/ SourceByrd's Weblog-https://note.t4x.org/basic/saltstack-install-nginx/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!