看到网上有很多关于saltstack的介绍,官网文档也是相当不错。但是可以参考的实例确实不多啊,那我就共享一个关于源码安装tengine的案例,希望对大家有帮助。
目录结构如下:
[root@litong_test tengine]# tree.├── conf.sls├── files│ ├── nginx│ ├── nginx.conf│ ├── pcre-8.33.tar.bz2│ └── tengine-1.5.2.tar.gz├── init.sls└── install.sls1 directory, 7 files
首先下载tengine源码包和pcre依赖包,放在files文件夹下。
下面是具体的源码:
#init.sls
[root@litong_test tengine]# cat init.sls include: - tengine.install #具体指tengine目录下的install.sls文件。tengine.conf同义 - tengine.conf
#install.sls
[root@litong_test tengine]# cat install.sls tengine_source: file.managed: - name: /tmp/tengine-1.5.2.tar.gz - unless: test -e /tmp/tengine-1.5.2.tar.gz - source: salt://tengine/files/tengine-1.5.2.tar.gzpcre_source: file.managed: - name: /tmp/pcre-8.33.tar.bz2 - unless: test -e /tmp/pcre-8.33.tar.bz2 - source: salt://tengine/files/pcre-8.33.tar.bz2extract_tengine: cmd.run: - cwd: /tmp - names: - tar zxf tengine-1.5.2.tar.gz - unless: - test -d tengine-1.5.2 - require: - file: tengine_sourceextract_pcre: cmd.run: - cwd: /tmp - names: - tar jxf pcre-8.33.tar.bz2 -C /usr/local/ - unless: - test -d pcre-8.33 - require: - file: tengine_sourcepcre_compile: cmd.run: - cwd: /usr/local/pcre-8.33 - names: - ./configure --prefix=/usr/local/pcre && make && make install - require: - cmd: extract_pcre - unless: test -d /usr/local/pcretengine_compile: cmd.run: - cwd: /tmp/tengine-1.5.2 - names: - ./configure --prefix=/usr/local/tengine --with-pcre=/usr/local/pcre-8.33 && make && make install - require: - cmd: extract_tengine - unless: test -d /usr/local/tengine
注解:
- names: - ./configure --prefix=/usr/local/pcre && make && make install 这块建议使用‘&&’链接 ,不要是用如下格式 - names: - ./configure --prefix=/usr/local/pcre - make - make install 因为在用的过程中,salt不用按从上到下的顺序执行,除非你使用require、unless之类的流程控制
#conf.sls
[root@litong_test tengine]# cat conf.sls include: - tengine.installtengine_conf: file.managed: - name: /usr/local/tengine/conf/nginx.conf - source: salt://tengine/files/nginx.conf - template: jinjatengine_service: file.managed: - source: salt://tengine/files/nginx - name: /etc/init.d/nginx - mode: 755 - user: root - backup: minion service.running: - name: nginx - enable: True - reload: True - watch: - file: /usr/local/tengine/conf/*.conf
接下来是top.sls的配置:
[root@litong_test salt]# cat top.sls base: '*': - tengine
在bash中执行:
#salt '*' state.sls tengine
这样既可实现安装。
详细源码间附件,如有问题,留言沟通!
3ky
源码位置: