saltstack部署nginx
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,1、前期规划准备nginx安装准备:1)安装必要依赖2)准备pcre安装包2)源码安装pcre3)准备nginx安装包4)源码安装nginxnginx配置:1)拷贝nginx.conf配置文件2)拷贝
千家信息网最后更新 2026年11月01日saltstack部署nginx
1、前期规划准备
nginx安装准备:
1)安装必要依赖
2)准备pcre安装包
2)源码安装pcre
3)准备nginx安装包
4)源码安装nginx
nginx配置:
1)拷贝nginx.conf配置文件
2)拷贝启停脚本
3)添加系统服务并设置开机启动
2、部署过程
1)准备安装包
[root@salt-master base]# cd /srv/salt/base[root@salt-master base]# mkdir -p pcre/files[root@salt-master base]# mkdir -p nginx/files[root@salt-master base]# cd /srv/salt/base/pcre/files[root@salt-master base]# wget https://ftp.pcre.org/pub/pcre/pcre-8.37.tar.gz[root@salt-master base]# cd /srv/salt/base/nginx/files[root@salt-master base]# wget http://nginx.org/download/nginx-1.6.3.tar.gz
2)编写sls文件
[root@salt-master base]# cd nginx/[root@salt-master nginx]# vi install.sls [root@salt-master nginx]# vi service.sls[root@salt-master nginx]# cd ../pcre/[root@salt-master pcre]# vi install.sls
3)测试sls
[root@salt-master base]# salt 'salt-minion01.contoso.com' state.sls nginx.service test=Truesalt-minion01.contoso.com:---------- ID: pcre-source-install Function: pkg.installed Name: zlib-devel Result: None Comment: The following packages are set to be installed/updated: zlib-devel Started: 14:41:07.540210 Duration: 18297.782 ms Changes: ---------- ID: pcre-source-install Function: pkg.installed Name: glibc-devel Result: True Comment: Package glibc-devel is already installed. Started: 14:41:25.838187 Duration: 0.536 ms Changes: ---------- ID: pcre-source-install Function: pkg.installed Name: gcc Result: True Comment: Package gcc is already installed. Started: 14:41:25.838783 Duration: 0.294 ms Changes: ---------- ID: pcre-source-install Function: pkg.installed Name: cmake Result: True Comment: Package cmake is already installed. Started: 14:41:25.839133 Duration: 0.241 ms Changes: ---------- ID: pcre-source-install Function: pkg.installed Name: glibc Result: True Comment: Package glibc is already installed. Started: 14:41:25.839432 Duration: 0.241 ms Changes: ---------- ID: pcre-source-install Function: pkg.installed Name: zlib Result: True Comment: Package zlib is already installed. Started: 14:41:25.839727 Duration: 0.305 ms Changes: ---------- ID: pcre-source-install Function: pkg.installed Name: autoconf Result: None Comment: The following packages are set to be installed/updated: autoconf Started: 14:41:25.840087 Duration: 0.281 ms Changes: ---------- ID: pcre-source-install Function: pkg.installed Name: gcc-c++ Result: True Comment: Package gcc-c++ is already installed. Started: 14:41:25.840422 Duration: 0.239 ms Changes: ---------- ID: pcre-source-install Function: pkg.installed Name: make Result: True Comment: Package make is already installed. Started: 14:41:25.840709 Duration: 0.282 ms Changes: ---------- ID: pcre-source-install Function: file.managed Name: /opt/tools/pcre-8.37.tar.gz Result: None Comment: The file /opt/tools/pcre-8.37.tar.gz is set to be changed Started: 14:41:25.888753 Duration: 17.582 ms Changes: ---------- newfile: /opt/tools/pcre-8.37.tar.gz---------- ID: pcre-source-install Function: cmd.run Name: cd /opt/tools/ && tar -zxf pcre-8.37.tar.gz && cd pcre-8.37 && ./configure --prefix=/usr/local/pcre && make && make install Result: None Comment: Command "cd /opt/tools/ && tar -zxf pcre-8.37.tar.gz && cd pcre-8.37 && ./configure --prefix=/usr/local/pcre && make && make install" would have been executed Started: 14:41:25.910768 Duration: 10.909 ms Changes: ---------- ID: nginx-source-install Function: pkg.installed Name: zlib-devel Result: None Comment: The following packages are set to be installed/updated: zlib-devel Started: 14:41:25.922254 Duration: 2.483 ms Changes: ---------- ID: nginx-source-install Function: pkg.installed Name: gcc Result: True Comment: Package gcc is already installed. Started: 14:41:25.925010 Duration: 0.926 ms Changes: ---------- ID: nginx-source-install Function: pkg.installed Name: make Result: True Comment: Package make is already installed. Started: 14:41:25.926183 Duration: 0.975 ms Changes: ---------- ID: nginx-source-install Function: pkg.installed Name: zlib Result: True Comment: Package zlib is already installed. Started: 14:41:25.927407 Duration: 1.276 ms Changes: ---------- ID: nginx-source-install Function: pkg.installed Name: openssl Result: True Comment: Package openssl is already installed. Started: 14:41:25.929287 Duration: 1.331 ms Changes: ---------- ID: nginx-source-install Function: pkg.installed Name: openssl-devel Result: None Comment: The following packages are set to be installed/updated: openssl-devel Started: 14:41:25.930830 Duration: 1.027 ms Changes: ---------- ID: nginx-source-install Function: pkg.installed Name: automake Result: None Comment: The following packages are set to be installed/updated: automake Started: 14:41:25.931943 Duration: 0.392 ms Changes: ---------- ID: nginx-source-install Function: pkg.installed Name: autoconf Result: None Comment: The following packages are set to be installed/updated: autoconf Started: 14:41:25.932402 Duration: 0.385 ms Changes: ---------- ID: nginx-source-install Function: pkg.installed Name: gcc-c++ Result: True Comment: Package gcc-c++ is already installed. Started: 14:41:25.932851 Duration: 0.33 ms Changes: ---------- ID: nginx-source-install Function: group.present Name: nginx Result: None Comment: The following group attributes are set to be changed: gid: 601 Started: 14:41:25.934673 Duration: 0.425 ms Changes: ---------- ID: nginx-source-install Function: user.present Name: nginx Result: None Comment: The following user attributes are set to be changed: homeDoesNotExist: /home/nginx gid: 601 fullname: nginx uid: 601 Started: 14:41:25.943129 Duration: 10.523 ms Changes: ---------- ID: nginx-source-install Function: file.managed Name: /opt/tools/nginx-1.6.3.tar.gz Result: None Comment: The file /opt/tools/nginx-1.6.3.tar.gz is set to be changed Started: 14:41:25.953761 Duration: 3.461 ms Changes: ---------- newfile: /opt/tools/nginx-1.6.3.tar.gz---------- ID: nginx-source-install Function: cmd.run Name: cd /opt/tools/ && tar -zxf nginx-1.6.3.tar.gz && mkdir -p /usr/local/nginx/tmp/{client,proxy,fcgi} && cd nginx-1.6.3 && ./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/tmp/client/ --http-proxy-temp-path=/usr/local/nginx/tmp/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/tmp/fcgi/ --with-poll_module --with-file-aio --with-http_realip_module --with-http_addition_module --with-http_addition_module --with-http_random_index_module --with-http_stub_status_module --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/scgi_temp --with-pcre=/opt/tools/pcre-8.37 && make && make install && chown -R nginx:nginx /usr/local/nginx/ Result: None Comment: Command "cd /opt/tools/ && tar -zxf nginx-1.6.3.tar.gz && mkdir -p /usr/local/nginx/tmp/{client,proxy,fcgi} && cd nginx-1.6.3 && ./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/tmp/client/ --http-proxy-temp-path=/usr/local/nginx/tmp/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/tmp/fcgi/ --with-poll_module --with-file-aio --with-http_realip_module --with-http_addition_module --with-http_addition_module --with-http_random_index_module --with-http_stub_status_module --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/scgi_temp --with-pcre=/opt/tools/pcre-8.37 && make && make install && chown -R nginx:nginx /usr/local/nginx/" would have been executed Started: 14:41:25.958142 Duration: 4.665 ms Changes: ---------- ID: nginx-init Function: file.managed Name: /etc/init.d/nginx Result: None Comment: The file /etc/init.d/nginx is set to be changed Started: 14:41:25.963238 Duration: 3.005 ms Changes: ---------- newfile: /etc/init.d/nginx---------- ID: nginx-init Function: cmd.run Name: chkconfig --add nginx Result: None Comment: Command "chkconfig --add nginx" would have been executed Started: 14:41:25.966786 Duration: 293.959 ms Changes: ---------- ID: /usr/local/nginx/conf/nginx.conf Function: file.managed Result: None Comment: The file /usr/local/nginx/conf/nginx.conf is set to be changed Started: 14:41:26.261344 Duration: 2.984 ms Changes: ---------- newfile: /usr/local/nginx/conf/nginx.conf---------- ID: nginx-service Function: file.directory Name: /usr/local/nginx/conf.d Result: None Comment: The following files will be changed: /usr/local/nginx/conf.d: directory - new Started: 14:41:26.264670 Duration: 0.371 ms Changes: ---------- ID: nginx-service Function: service.running Name: nginx Result: None Comment: Service is set to be started Started: 14:41:26.286912 Duration: 53.579 ms Changes: Summary-------------Succeeded: 29 (unchanged=17, changed=4)Failed: 0-------------Total states run: 294)正式部署
[root@salt-master base]# salt 'salt-minion01.contoso.com' state.sls nginx.service
5)sls代码
目录结构如下:
[root@salt-master salt]# tree /srv/salt/base//srv/salt/base/├── nginx│ ├── files│ │ ├── nginx│ │ ├── nginx-1.6.3.tar.gz│ │ └── nginx.conf│ ├── install.sls│ └── service.sls└── pcre ├── files │ └── pcre-8.37.tar.gz └── install.sls4 directories, 7 files
pcre install.sls代码:
[root@salt-master base]# cat pcre/install.sls pcre-source-install: pkg.installed: - names: - gcc - gcc-c++ - autoconf - zlib - zlib-devel - glibc - glibc-devel - make - cmake file.managed: - source: salt://pcre/files/pcre-8.37.tar.gz - name: /opt/tools/pcre-8.37.tar.gz - user: root - group: root - mode: 755 - makedirs: True - dir_mode: 644 cmd.run: - name: cd /opt/tools/ && tar -zxf pcre-8.37.tar.gz && cd pcre-8.37 && ./configure --prefix=/usr/local/pcre && make && make install - unless: test -d /usr/local/pcre - require: - file: pcre-source-install
nginx install.sls代码:
[root@salt-master base]# cat nginx/install.sls include: - pcre.installnginx-source-install: pkg.installed: - names: - gcc - gcc-c++ - autoconf - automake - zlib - zlib-devel - make - openssl - openssl-devel group.present: - name: nginx - gid: 601 user.present: - name: nginx - fullname: nginx - shell: /sbin/nologin - uid: 601 - gid: 601 file.managed: - source: salt://nginx/files/nginx-1.6.3.tar.gz - name: /opt/tools/nginx-1.6.3.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: cd /opt/tools/ && tar -zxf nginx-1.6.3.tar.gz && mkdir -p /usr/local/nginx/tmp/{client,proxy,fcgi} && cd nginx-1.6.3 && ./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/tmp/client/ --http-proxy-temp-path=/usr/local/nginx/tmp/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/tmp/fcgi/ --with-poll_module --with-file-aio --with-http_realip_module --with-http_addition_module --with-http_addition_module --with-http_random_index_module --with-http_stub_status_module --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/scgi_temp --with-pcre=/opt/tools/pcre-8.37 && make && make install && chown -R nginx:nginx /usr/local/nginx/ - unless: test -e /usr/local/nginx/sbin/nginx - require: - file: nginx-source-install - cmd: pcre-source-installnginx service.sls代码:
[root@salt-master base]# cat nginx/service.sls include: - nginx.installnginx-init: file.managed: - name: /etc/init.d/nginx - source: salt://nginx/files/nginx - user: root - group: root - mode: 755 cmd.run: - name: chkconfig --add nginx - unless: chkconfig --list|grep nginx - require: - file: nginx-init/usr/local/nginx/conf/nginx.conf: file.managed: - source: salt://nginx/files/nginx.conf - user: nginx - group: nginx - mode: 644nginx-service: file.directory: - name: /usr/local/nginx/conf.d - require: - cmd: nginx-source-install service.running: - name: nginx - enable: True - reload: True - require: - cmd: nginx-init - watch: - file: /usr/local/nginx/conf/nginx.conf
3、部署结果验收
[root@salt-minion01 ~]# service nginx statusnginx (pid 11406 11405 11404 11403 11400) is running...[root@salt-minion01 ~]# ps -ef|grep nginxroot 11494 1 0 14:22 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.confnginx 11496 11494 0 14:22 ? 00:00:00 nginx: worker process nginx 11497 11494 0 14:22 ? 00:00:00 nginx: worker process nginx 11498 11494 0 14:22 ? 00:00:00 nginx: worker process nginx 11499 11494 0 14:22 ? 00:00:00 nginx: worker process root 11503 1049 0 14:22 pts/0 00:00:00 grep nginx[root@salt-minion01 ~]# chkconfig --list|grep nginxnginx 0:off1:off2:on3:on4:on5:on6:off[root@salt-minion01 ~]# service nginx checkChecking config file: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@salt-minion01 ~]# service nginx reloadReloading nginx: [ OK ][root@salt-minion01 ~]# service nginx restartStopping nginx: [ OK ]Starting nginx: [ OK ]
准备
代码
拷贝
文件
源码
配置
必要
前期
目录
系统
结构
结果
脚本
过程
服务
测试
规划
验收
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
云南咖啡
互联网科技产业
互联网属科技
疫情对互联网科技公司影响
互联网科技垄断
互联网与未来科技
丰台科技园 互联网
互联网科技汛
顺网科技2021年互联网排名
青海省互联网新科技
互联网经济与金融科技
世界互联网科技公司市值排名
南平创想时代互联网科技有限公司
辽宁互联网新科技
恒生互联网科技指数跳水
互联网科技人工智能实验室
翼展科技 首家互联网医院
济南有互联网科技公司吗
上海乐五互联网科技有限公司
西安左小互联网科技有限公司
互联网科技
互联网科技的英文
洛阳共同富裕互联网科技有限公司
朱啸虎曾投资哪些互联网科技企业
美国互联网科技实力
锡山区互联网智能科技产品供应
小米互联网科技园入驻
广州梦谷互联网科技有限公司领导
杭州融税互联网科技有限公司
科技互联网专业务虚会材料