Get the App
SLTechnology News&Howtos  ›  Servers  › 

Saltstack deployment nginx Advanced

Shulou Source: shulou.com Published: 2022-06-02 19:36:25 11月14日 Update

The previous article actually demonstrated the deployment of nginx through saltstack, but it may still be a little different from my current environment, and then the structure of sls is not very clear, so it has been changed and optimized, called Advanced may be a bit of a gimmick, but the record is as follows:

Nginx installation target:

1) install the necessary dependencies

2) prepare the pcre installation package

2) install pcre with source code

3) prepare the nginx installation package

4) install nginx with source code

Nginx configuration:

1) copy the nginx.conf configuration file

2) copy the start and stop script

3) add system services and set boot

4) copy the log cutting script

5) add scheduled tasks

The directory structure on salt master is as follows:

[root@salt-master base] # tree / srv/salt/base//srv/salt/base/ ├── cron │ ├── files │ │ └── nginx_cut_log.sh │ └── nginx.sls ├── nginx │ ├── files │ │ ├── nginx │ │ ├── nginx-1.6.3.tar.gz │ │ nginx.conf install .sls │ └── service.sls ├── packages │ └── install.sls ├── pcre │ ├── files │ │ └── pcre-8.37.tar.gz │ └── install.sls └── user └── nginx.sls8 directories 11 files

Install the necessary software packages:

[root@salt-master base] # cat packages/install.sls yum_pcre_packages: pkg.installed:-names:-gcc- gcc-c++-autoconf-automake-zlib- zlib-devel-make-openssl- openssl-devel-libpng- libpng-devel-freetype- freetype-devel-libxml2- libxml2-devel -glibc- glibc-devel-glib2-glib-devel-bzip2- bzip2-devel-ncurses- ncurses-devel-curl-cmake

Compile and install pcre:

[root@salt-master base] # cat pcre/install.sls include:-packages.installpcre-source-install: 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

Create nginx users and groups:

[root@salt-master base] # cat user/nginx.sls nginx-user-group: group.present:-name: nginx- gid: 601 user.present:-name: nginx- fullname: nginx- shell: / sbin/nologin-uid: 601-gid: 601

Compile and install nginx:

[root@salt-master base] # cat nginx/install.sls include:-pcre.install-user.nginxnginx-source-install: 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-install

Add scheduled tasks:

[root@salt-master base] # cat cron/nginx.sls / opt/tools/scripts/: file.directory:-user: root-group: root-mode: 644-makedirs: Truenginx-crond-job: file.managed:-name: / opt/tools/scripts/nginx_cut_log.sh-source: salt://cron/files/nginx_cut_log.sh-user: root-group: root-mode: 755 / bin/bash / opt/tools/scripts/nginx_cut_log.sh > / dev/null 2 > & 1: cron.present:-identifier: SUPERCRON-user: root-minute: 0-hour: 0

Start nginx and set up boot:

[root@salt-master base] # cat nginx/service.sls include:-nginx.install-cron.nginxnginx-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

Deployment command: [root@salt-master base] # salt 'salt-minion02.contoso.com' state.sls nginx.service

Deployment results:

[root@salt-minion02 logs] # ll / usr/local/pcre/total 16drwxr-xr-x 2 root root 4096 Jun 8 10:29 bindrwxr-xr-x 2 root root 4096 Jun 8 10:29 includedrwxr-xr-x 3 root root 4096 Jun 8 10:29 libdrwxr-xr-x 4 root root 4096 Jun 8 10:29 share [root@salt-minion02 logs] # id nginxuid=601 (nginx) gid=601 (nginx) groups=601 (nginx) [root@salt-minion02 logs] # ll / usr/local/nginx/total 32drwxr-xr-x 2 nginx nginx 4096 Jun 8 10:30 confdrwxr-xr-x 2 root root 4096 Jun 8 10:30 conf.ddrwxr-xr-x 2 nginx nginx 4096 Jun 8 10:30 htmldrwxr-xr-x 2 nginx nginx 4096 Jun 8 10:30 logsdrwxr-xr-x 2 nginx nginx 4096 Jun 8 10:30 sbindrwx- 2 nginx root 4096 Jun 8 10:30 scgi_tempdrwxr-xr-x 5 nginx nginx 4096 Jun 8 10:29 tmpdrwx- 2 nginx root 4096 Jun 8 10:30 uwsgi_ temp[root Salt-minion02 logs] # / usr/local/nginx/sbin/nginx-Vnginx version: nginx/1.6.3built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) TLS SNI support enabledconfigure arguments:-- 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 [root@salt-minion02 logs] # / etc/init.d/nginx statusnginx (pid 11422 11421 11420 11419 11416) is running... [root@salt-minion02 logs] # chkconfig-list | grep nginxnginx 0:off1:off2:on3:on4:on5:on6:off [root@salt-minion02 logs] # crontab-l0 * / usr/sbin/ntpdate 210.72.145.44 64.147.116.229 time.nist.gov > / dev/null 2 > & Lines below here are managed by Salt Do not edit# SALT_CRON_IDENTIFIER:SUPERCRON0 0 * / bin/bash / opt/tools/scripts/nginx_cut_log.sh > / dev/null 2 > & 1 [root@salt-minion02 logs] # ll / opt/tools/scripts/nginx_cut_log.sh-rwxr-xr-x 1 root root 1100 Jun 8 10:30 / opt/tools/scripts/nginx_cut_log.sh

Tags: Copy necessity task source code structure script or prepare compile configure advanced command gimmick file log environment user directory target system Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Huawei vpn Apple Shulou Technology