1、安装前分析
主要内容:
a、依赖包(使用yum安装);
b、源码包(pcre也使用源码安装、nginx源码包);
c、配置文件与启动脚本(使用file.managed模块方法分发到目标机相应目录);
d、使用cmd.run模块方法对源码包编译安装;
e、使用service.running模块方法,启动对应服务。
2、安装依赖
编译安装pcre
[[email protected] salt]# pwd /srv/salt [[email protected] salt]# cat pcre.sls pcre_install: file.managed: - name: /usr/local/src/pcre-8.30.tar.gz //文件目标分发的位置 - source: salt://pcre-8.30.tar.gz //文件源头 - user: root - group: root - mode: 755 cmd.run: - cwd: /usr/local/src //模板方法执行初始路径 - name: tar xf pcre-8.30.tar.gz &&cd pcre-8.30 &&./configure &&make &&make install
安装其他依赖
[[email protected] salt]# cat install.sls nginx_yum: pkg.installed: //yum安装 - name: openssl - name: openssl-devel - name: pcre - name: pcre-devel - name: zlib - name: zlib-devel
3、nginx.sls状态文件全览
[[email protected] salt]# pwd /srv/salt [[email protected] salt]# cat nginx.sls include: //加载其他状态文件 - install - pcre nginx_init: file.managed: - name: /etc/init.d/nginx //nginx启动叫脚本文件 - source: salt://nginx - user: root - group: root - mode: 755 nginx.tar.gz_file: file.managed: - name: /usr/local/src/nginx-1.8.1.tar.gz //nginx安装包 - source: salt://nginx-1.8.1.tar.gz - user: root - group: root - mode: 755 nginx_install: cmd.run: - name: cd /usr/local/src && useradd -s /sbin/nologin nginx && tar xf nginx-1.8.1.tar.gz && cd nginx-1.8.1 && ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre && make && make install && ln -s /lib64/libpcre.so.0.0.1 /lib64/libpcre.so.1 - unless: test -d /usr/local/src/nginx-1.8.1.tar.gz //判断文件是否存在,存在方可执行 service.running: - name: nginx - enable: True //启动nginx服务
4、补充
在master端执行安装任务时,我们可以使用-v选项查看到jid,也可以通过命令
salt ‘*‘ saltutil.running 查看到当前的job id
[[email protected] salt]# salt ‘192.168.24.67‘ state.sls nginx -v Executing job with jid 20160705132643772244 -------------------------------------------
[[email protected] ~]# salt ‘*‘ saltutil.running 192.168.24.67: |_ ---------- arg: - nginx fun: state.sls jid: 20160705132432763991 pid: 3712 ret: tgt: 192.168.24.67 tgt_type: glob user: root
我们也可以使用如下命令结束一个job
[[email protected] ~]# salt ‘*‘ saltutil.kill_job 20160705132432763991
时间: 2024-10-27 03:01:10