一、为不同的环境设置不同的文件目录

1.1 修改配置文件 /etc/salt/master

[root@node1 salt]# vim /etc/salt/master

 file_roots:
base:
- /srv/salt/base
dev:
- /srv/salt/dev
prod:
- /srv/salt/prod

1.2 创建对应的文件夹

[root@node1 salt]# mkdir -p /srv/salt/{base,dev,prod}

1.3 重启服务

[root@node1 salt]# systemctl restart salt-master

二、文件管理

2.1准备入口文件

更改 base 环境的 dns 配置,首先在 base 文件夹下创建入口文件 top.sls

[root@node1 salt]# cd /srv/salt/base/

[root@node1 base]# vim top.sls

base:
'web1':
- dns_file

2.2 配置分发文件说明

[root@node1 base]# vim dns_file.sls

resolv_conf:
file.managed:
- name: /etc/resolv.conf
- source: salt://files/resolv.conf
- user: root
- group: root
- mode:

2.3 执行文件分发操作

[root@node1 base]# mkdir files

[root@node1 base]# vim files/resolv.conf

nameserver 8.8.8.8

2.4 测试

[root@node1 base]# salt '*' state.highstate saltenv=base test

web2:
----------
ID: states
Function: no.None
Result: False
Comment: No Top file or master_tops data matches found.
Changes: Summary for web2
------------
Succeeded:
Failed:
------------
Total states run:
Total run time: 0.000 ms
web3:
----------
ID: states
Function: no.None
Result: False
Comment: No Top file or master_tops data matches found.
Changes:
…………
web1:
----------
ID: resolv_conf
Function: file.managed
Name: /etc/resolv.conf
Result: None
Comment: The file /etc/resolv.conf is set to be changed
Started: ::30.626072
Duration: 48.745 ms
Changes:
----------
diff:
---
+++
@@ -, + @@
-# Generated by NetworkManager
-search localdomain
-nameserver 172.25.254.2
+nameserver 8.8.8.8 Summary for web1
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
Total run time: 48.745 ms

2.5 运行

[root@node1 base]# salt '*' state.highstate saltenv=base False

2.6 检测

[root@node1 base]# salt 'web1' cmd.run 'cat /etc/resolv.conf'

2.7 修改所有节点 的 resolv.conf 配置

给issue 文件追加内容

[root@node1 base]# vim top.sls

base:
'L@web1,web2,web3,db1,db2':
- dns- issue
- rpm_pkgs

[root@node1 base]# vim dns_file.sls

resolv_conf:
file.managed:
- name: /etc/resolv.conf
- source: salt://files/resolv.conf
- user: root
- group: root
- mode:
- template: jinja
- defaults:
DNS_IP: 192.168.113.254

[root@node1 base]# mkdir -p /srv/salt/base/files

[root@node1 base]# vim files/resolv.conf

nameserver 8.8.4.4

[root@node1 base]# vim issue.sls

issue_file:
file.append:
- name: /etc/issue
- text:
- Red Hat Enterprise Linux
- Tedu Ltd Server

[root@node1 base]# vim rpm_pkgs.sls

rpms:
file.directory:
- name: /opt/rpm_pkgs
- user: root
- group: root
- dir_mode:
- file_mode:

[root@node1 base]# salt '*' state.highstate saltenv=base test=True

web1:
----------
ID: resolv_conf
Function: file.managed
Name: /etc/resolv.conf
Result: None
Comment: The file /etc/resolv.conf is set to be changed
Started: ::06.189301
Duration: 893.458 ms
Changes:
----------
diff:
---
+++
@@ -, + @@
-# Generated by NetworkManager
-search localdomain
-nameserver 172.25.254.2
+nameserver 8.8.4.4
----------
ID: issue_file
Function: file.append
Name: /etc/issue
Result: None
Comment: File /etc/issue is set to be updated
Started: ::07.082933
Duration: 2.67 ms
Changes:
----------
diff:
--- +++ @@ -, +, @@ \S
Kernel \r on an \m +Red Hat Enterprise Linux
+Tedu Ltd Server
----------
ID: rpms
Function: file.directory
Name: /opt/rpm_pkgs
Result: None
Comment: The following files will be changed:
/opt/rpm_pkgs: directory - new
Started: ::07.085724
Duration: 0.432 ms
Changes: Summary for web1
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
Total run time: 896.560 ms
web2:
----------
ID: resolv_conf
Function: file.managed
Name: /etc/resolv.conf
Result: None
Comment: The file /etc/resolv.conf is set to be changed
Started: ::06.520386
Duration: 1121.741 ms
Changes:
----------
diff:
---
+++
@@ -, + @@
-# Generated by NetworkManager
-search localdomain
-nameserver 172.25.254.2
+nameserver 8.8.4.4
----------
ID: issue_file
Function: file.append
Name: /etc/issue
Result: None
Comment: File /etc/issue is set to be updated
Started: ::07.642292
Duration: 2.611 ms
Changes:
----------
diff:
--- +++ @@ -, +, @@ \S
Kernel \r on an \m +Red Hat Enterprise Linux
+Tedu Ltd Server
----------
ID: rpms
Function: file.directory
Name: /opt/rpm_pkgs
Result: None
Comment: The following files will be changed:
/opt/rpm_pkgs: directory - new
Started: ::07.645019
Duration: 0.426 ms
Changes: Summary for web2
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
Total run time: 1.125 s
db1:
----------
ID: resolv_conf
Function: file.managed
Name: /etc/resolv.conf
Result: None
Comment: The file /etc/resolv.conf is set to be changed
Started: ::06.055239
Duration: 1069.927 ms
Changes:
----------
diff:
---
+++
@@ -, + @@
-# Generated by NetworkManager
-search localdomain
-nameserver 192.168.2.1
-nameserver 172.25.254.2
+nameserver 8.8.4.4
----------
ID: issue_file
Function: file.append
Name: /etc/issue
Result: None
Comment: File /etc/issue is set to be updated
Started: ::07.125304
Duration: 2.857 ms
Changes:
----------
diff:
--- +++ @@ -, +, @@ \S
Kernel \r on an \m +Red Hat Enterprise Linux
+Tedu Ltd Server
----------
ID: rpms
Function: file.directory
Name: /opt/rpm_pkgs
Result: None
Comment: The following files will be changed:
/opt/rpm_pkgs: directory - new
Started: ::07.128287
Duration: 0.441 ms
Changes: Summary for db1
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
Total run time: 1.073 s
web3:
----------
ID: resolv_conf
Function: file.managed
Name: /etc/resolv.conf
Result: None
Comment: The file /etc/resolv.conf is set to be changed
Started: ::06.368308
Duration: 915.69 ms
Changes:
----------
diff:
---
+++
@@ -, + @@
-# Generated by NetworkManager
-search localdomain
-nameserver 172.25.254.2
+nameserver 8.8.4.4
----------
ID: issue_file
Function: file.append
Name: /etc/issue
Result: None
Comment: File /etc/issue is set to be updated
Started: ::07.284136
Duration: 3.062 ms
Changes:
----------
diff:
--- +++ @@ -, +, @@ \S
Kernel \r on an \m +Red Hat Enterprise Linux
+Tedu Ltd Server
----------
ID: rpms
Function: file.directory
Name: /opt/rpm_pkgs
Result: None
Comment: The following files will be changed:
/opt/rpm_pkgs: directory - new
Started: ::07.287324
Duration: 0.45 ms
Changes: Summary for web3
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
Total run time: 919.202 ms
db2:
----------
ID: resolv_conf
Function: file.managed
Name: /etc/resolv.conf
Result: None
Comment: The file /etc/resolv.conf is set to be changed
Started: ::06.578547
Duration: 493.823 ms
Changes:
----------
diff:
---
+++
@@ -, + @@
-# Generated by NetworkManager
-search localdomain
-nameserver 172.25.254.2
+nameserver 8.8.4.4
----------
ID: issue_file
Function: file.append
Name: /etc/issue
Result: None
Comment: File /etc/issue is set to be updated
Started: ::07.072509
Duration: 2.762 ms
Changes:
----------
diff:
--- +++ @@ -, +, @@ \S
Kernel \r on an \m +Red Hat Enterprise Linux
+Tedu Ltd Server
----------
ID: rpms
Function: file.directory
Name: /opt/rpm_pkgs
Result: None
Comment: The following files will be changed:
/opt/rpm_pkgs: directory - new
Started: ::07.075408
Duration: 0.423 ms
Changes: Summary for db2
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
Total run time: 497.008 ms

[root@node1 base]# salt '*' state.highstate saltenv=base test=False

[root@node1 base]# salt '*' cmd.run 'cat /etc/resolv.conf'

[root@node1 base]# salt '*' cmd.run 'ls -l /opt/'

[root@node1 base]# salt '*' cmd.run "cat /etc/issue |grep -A 2 Red"

三、配置项目

配置history命令显示时间

配置系统内核参数 net.ipv4.ip_forward 打开路由转发

创建用户zhang3

设置初始化密码为123456

配置用户初次登陆必须修改密码

3.1 配置top.sls

[root@node1 base]# vim top.sls

base:
'L@web1,web2,web3,db1,db2':
- init/history
- init/sysctl
- init/add_user

3.2 配置history.sls

[root@node1 base]# vim init/history.sls

history_file:
file.append:
- name: /etc/profile
- text:
- export HISTORYFORMAT="[%F_%T]:"

3.3 配置sysctl.sls

[root@node1 base]# vim init/sysctl.sls

net_ipv4.ip_forward:
sysctl.present:
- value:

3.4 配置add_user.sls

[root@node1 base]# vim init/add_user.sls

useradd zhang3:      #添加用户
cmd.run:
- unless: id zhang3
echo |passwd --stdin root: #修改密碼
cmd.run:
- onlyif: id zhang3
chage -d0 zhang3: #设置初次登录修改密码策略
cmd.run:
- onlyif: id zhang3

3.5 测试

[root@node1 base]# salt '*' state.highstate saltenv=base test=True

web2:
----------
ID: history_file
Function: file.append
Name: /etc/profile
Result: None
Comment: File /etc/profile is set to be updated
Started: ::48.826389
Duration: 6.303 ms
Changes:
----------
diff:
--- +++ @@ -, +, @@ unset i
unset -f pathmunge
+export HISTORYFORMAT="[%F_%T]:"
----------
ID: net_ipv4.ip_forward
Function: sysctl.present
Result: None
Comment: Sysctl option net_ipv4.ip_forward might be changed, we failed to check config file at /etc/sysctl.d/-salt.conf. The file is either unreadable, or missing.
Started: ::48.834509
Duration: 444.162 ms
Changes:
----------
ID: useradd_zhang3
Function: cmd.run
Result: None
Comment: Command "useradd_zhang3" would have been executed
Started: ::49.279489
Duration: 21.675 ms
Changes:
----------
ID: echo |passwd --stdin root
Function: cmd.run
Result: True
Comment: onlyif execution failed
Started: ::49.301337
Duration: 8.862 ms
Changes:
----------
ID: chage -d0 zhang3
Function: cmd.run
Result: True
Comment: onlyif execution failed
Started: ::49.310391
Duration: 8.55 ms
Changes: Summary for web2
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
Total run time: 489.552 ms
web3:
----------
ID: history_file
Function: file.append
Name: /etc/profile
Result: None
Comment: File /etc/profile is set to be updated
Started: ::49.189855
Duration: 7.214 ms
Changes:
----------
diff:
--- +++ @@ -, +, @@ unset i
unset -f pathmunge
+export HISTORYFORMAT="[%F_%T]:"
----------
ID: net_ipv4.ip_forward
Function: sysctl.present
Result: None
Comment: Sysctl option net_ipv4.ip_forward might be changed, we failed to check config file at /etc/sysctl.d/-salt.conf. The file is either unreadable, or missing.
Started: ::49.198787
Duration: 47.317 ms
Changes:
----------
ID: useradd_zhang3
Function: cmd.run
Result: None
Comment: Command "useradd_zhang3" would have been executed
Started: ::49.247100
Duration: 8.712 ms
Changes:
----------
ID: echo |passwd --stdin root
Function: cmd.run
Result: True
Comment: onlyif execution failed
Started: ::49.255980
Duration: 10.439 ms
Changes:
----------
ID: chage -d0 zhang3
Function: cmd.run
Result: True
Comment: onlyif execution failed
Started: ::49.266583
Duration: 15.065 ms
Changes: Summary for web3
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
Total run time: 88.747 ms
db1:
----------
ID: history_file
Function: file.append
Name: /etc/profile
Result: None
Comment: File /etc/profile is set to be updated
Started: ::49.934751
Duration: 6.928 ms
Changes:
----------
diff:
--- +++ @@ -, +, @@ unset i
unset -f pathmunge
+export HISTORYFORMAT="[%F_%T]:"
----------
ID: net_ipv4.ip_forward
Function: sysctl.present
Result: None
Comment: Sysctl option net_ipv4.ip_forward might be changed, we failed to check config file at /etc/sysctl.d/-salt.conf. The file is either unreadable, or missing.
Started: ::49.943448
Duration: 572.594 ms
Changes:
----------
ID: useradd_zhang3
Function: cmd.run
Result: None
Comment: Command "useradd_zhang3" would have been executed
Started: ::50.516913
Duration: 7.899 ms
Changes:
----------
ID: echo |passwd --stdin root
Function: cmd.run
Result: True
Comment: onlyif execution failed
Started: ::50.524982
Duration: 8.226 ms
Changes:
----------
ID: chage -d0 zhang3
Function: cmd.run
Result: True
Comment: onlyif execution failed
Started: ::50.533404
Duration: 8.202 ms
Changes: Summary for db1
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
Total run time: 603.849 ms
web1:
----------
ID: history_file
Function: file.append
Name: /etc/profile
Result: None
Comment: File /etc/profile is set to be updated
Started: ::52.297910
Duration: 6.668 ms
Changes:
----------
diff:
--- +++ @@ -, +, @@ unset i
unset -f pathmunge
+export HISTORYFORMAT="[%F_%T]:"
----------
ID: net_ipv4.ip_forward
Function: sysctl.present
Result: None
Comment: Sysctl option net_ipv4.ip_forward might be changed, we failed to check config file at /etc/sysctl.d/-salt.conf. The file is either unreadable, or missing.
Started: ::52.306369
Duration: 149.86 ms
Changes:
----------
ID: useradd_zhang3
Function: cmd.run
Result: None
Comment: Command "useradd_zhang3" would have been executed
Started: ::52.457076
Duration: 9.451 ms
Changes:
----------
ID: echo |passwd --stdin root
Function: cmd.run
Result: True
Comment: onlyif execution failed
Started: ::52.466704
Duration: 8.66 ms
Changes:
----------
ID: chage -d0 zhang3
Function: cmd.run
Result: True
Comment: onlyif execution failed
Started: ::52.475542
Duration: 9.109 ms
Changes: Summary for web1
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
Total run time: 183.748 ms
db2:
----------
ID: history_file
Function: file.append
Name: /etc/profile
Result: None
Comment: File /etc/profile is set to be updated
Started: ::50.796859
Duration: 7.861 ms
Changes:
----------
diff:
--- +++ @@ -, +, @@ unset i
unset -f pathmunge
+export HISTORYFORMAT="[%F_%T]:"
----------
ID: net_ipv4.ip_forward
Function: sysctl.present
Result: None
Comment: Sysctl option net_ipv4.ip_forward might be changed, we failed to check config file at /etc/sysctl.d/-salt.conf. The file is either unreadable, or missing.
Started: ::50.806454
Duration: 219.199 ms
Changes:
----------
ID: useradd_zhang3
Function: cmd.run
Result: None
Comment: Command "useradd_zhang3" would have been executed
Started: ::51.026499
Duration: 10.024 ms
Changes:
----------
ID: echo |passwd --stdin root
Function: cmd.run
Result: True
Comment: onlyif execution failed
Started: ::51.036731
Duration: 166.817 ms
Changes:
----------
ID: chage -d0 zhang3
Function: cmd.run
Result: True
Comment: onlyif execution failed
Started: ::51.203873
Duration: 11.691 ms
Changes: Summary for db2
------------
Succeeded: (unchanged=, changed=)
Failed:
------------
Total states run:
Total run time: 415.592 ms

3.6 运行检测

[root@node1 base]# salt '*' state.highstate saltenv=base test=False

web1:
----------
ID: history_file
Function: file.append
Name: /etc/profile
Result: True
Comment: File /etc/profile is in correct state
Started: ::02.816332
Duration: 6.71 ms
Changes:
----------
ID: net.ipv4.ip_forward
Function: sysctl.present
Result: True
Comment: Sysctl value net.ipv4.ip_forward = is already set
Started: ::02.824619
Duration: 119.326 ms
Changes:
----------
ID: useradd zhang3
Function: cmd.run
Result: True
Comment: Command "useradd zhang3" run
Started: ::02.944856
Duration: 238.726 ms
Changes:
----------
pid: retcode: stderr:
stdout:
----------
ID: echo |passwd --stdin root
Function: cmd.run
Result: True
Comment: Command "echo 123456|passwd --stdin root" run
Started: ::03.183785
Duration: 441.791 ms
Changes:
----------
pid: retcode: stderr:
stdout:
Changing password for user root.
passwd: all authentication tokens updated successfully.
----------
ID: chage -d0 zhang3
Function: cmd.run
Result: True
Comment: Command "chage -d0 zhang3" run
Started: ::03.625769
Duration: 142.791 ms
Changes:
----------
pid: retcode: stderr:
stdout: Summary for web1
------------
Succeeded: (changed=)
Failed:
------------
Total states run:
Total run time: 949.344 ms
web2:
----------
ID: history_file
Function: file.append
Name: /etc/profile
Result: True
Comment: File /etc/profile is in correct state
Started: ::03.052625
Duration: 6.965 ms
Changes:
----------
ID: net.ipv4.ip_forward
Function: sysctl.present
Result: True
Comment: Sysctl value net.ipv4.ip_forward = is already set
Started: ::03.061223
Duration: 31.778 ms
Changes:
----------
ID: useradd zhang3
Function: cmd.run
Result: True
Comment: Command "useradd zhang3" run
Started: ::03.094172
Duration: 898.344 ms
Changes:
----------
pid: retcode: stderr:
stdout:
----------
ID: echo |passwd --stdin root
Function: cmd.run
Result: True
Comment: Command "echo 123456|passwd --stdin root" run
Started: ::03.992757
Duration: 285.178 ms
Changes:
----------
pid: retcode: stderr:
stdout:
Changing password for user root.
passwd: all authentication tokens updated successfully.
----------
ID: chage -d0 zhang3
Function: cmd.run
Result: True
Comment: Command "chage -d0 zhang3" run
Started: ::04.278136
Duration: 200.56 ms
Changes:
----------
pid: retcode: stderr:
stdout: Summary for web2
------------
Succeeded: (changed=)
Failed:
------------
Total states run:
Total run time: 1.423 s
db2:
----------
ID: history_file
Function: file.append
Name: /etc/profile
Result: True
Comment: File /etc/profile is in correct state
Started: ::01.635525
Duration: 6.95 ms
Changes:
----------
ID: net.ipv4.ip_forward
Function: sysctl.present
Result: True
Comment: Sysctl value net.ipv4.ip_forward = is already set
Started: ::01.645388
Duration: 411.074 ms
Changes:
----------
ID: useradd zhang3
Function: cmd.run
Result: True
Comment: Command "useradd zhang3" run
Started: ::02.057348
Duration: 1223.669 ms
Changes:
----------
pid: retcode: stderr:
stdout:
----------
ID: echo |passwd --stdin root
Function: cmd.run
Result: True
Comment: Command "echo 123456|passwd --stdin root" run
Started: ::03.281214
Duration: 1104.784 ms
Changes:
----------
pid: retcode: stderr:
stdout:
Changing password for user root.
passwd: all authentication tokens updated successfully.
----------
ID: chage -d0 zhang3
Function: cmd.run
Result: True
Comment: Command "chage -d0 zhang3" run
Started: ::04.386271
Duration: 41.183 ms
Changes:
----------
pid: retcode: stderr:
stdout: Summary for db2
------------
Succeeded: (changed=)
Failed:
------------
Total states run:
Total run time: 2.788 s
web3:
----------
ID: history_file
Function: file.append
Name: /etc/profile
Result: True
Comment: File /etc/profile is in correct state
Started: ::03.435729
Duration: 6.858 ms
Changes:
----------
ID: net.ipv4.ip_forward
Function: sysctl.present
Result: True
Comment: Sysctl value net.ipv4.ip_forward = is already set
Started: ::03.444273
Duration: 31.748 ms
Changes:
----------
ID: useradd zhang3
Function: cmd.run
Result: True
Comment: Command "useradd zhang3" run
Started: ::03.477440
Duration: 376.603 ms
Changes:
----------
pid: retcode: stderr:
stdout:
----------
ID: echo |passwd --stdin root
Function: cmd.run
Result: True
Comment: Command "echo 123456|passwd --stdin root" run
Started: ::03.854320
Duration: 988.137 ms
Changes:
----------
pid: retcode: stderr:
stdout:
Changing password for user root.
passwd: all authentication tokens updated successfully.
----------
ID: chage -d0 zhang3
Function: cmd.run
Result: True
Comment: Command "chage -d0 zhang3" run
Started: ::04.842672
Duration: 616.962 ms
Changes:
----------
pid: retcode: stderr:
stdout: Summary for web3
------------
Succeeded: (changed=)
Failed:
------------
Total states run:
Total run time: 2.020 s
db1:
----------
ID: history_file
Function: file.append
Name: /etc/profile
Result: True
Comment: File /etc/profile is in correct state
Started: ::04.695357
Duration: 6.211 ms
Changes:
----------
ID: net.ipv4.ip_forward
Function: sysctl.present
Result: True
Comment: Sysctl value net.ipv4.ip_forward = is already set
Started: ::04.703099
Duration: 268.77 ms
Changes:
----------
ID: useradd zhang3
Function: cmd.run
Result: True
Comment: Command "useradd zhang3" run
Started: ::04.973150
Duration: 274.212 ms
Changes:
----------
pid: retcode: stderr:
stdout:
----------
ID: echo |passwd --stdin root
Function: cmd.run
Result: True
Comment: Command "echo 123456|passwd --stdin root" run
Started: ::05.247554
Duration: 257.399 ms
Changes:
----------
pid: retcode: stderr:
stdout:
Changing password for user root.
passwd: all authentication tokens updated successfully.
----------
ID: chage -d0 zhang3
Function: cmd.run
Result: True
Comment: Command "chage -d0 zhang3" run
Started: ::05.505137
Duration: 144.971 ms
Changes:
----------
pid: retcode: stderr:
stdout: Summary for db1
------------
Succeeded: (changed=)
Failed:
------------
Total states run:
Total run time: 951.563 ms

[root@node1 base]# salt '*' cmd.run 'id  zhang3'

[root@node1 base]# salt '*' cmd.run 'sysctl -a|grep "net.ipv4.ip_forward = 1"'

四、 源码安裝nginx

使用Dev环境

编译源码安装步骤

由于 nginx 源码安装是一个独立工作,我们建立一个项目

4.1 创建项目

[root@node1 dev]# mkdir initpkg

[root@node1 dev]# vim initpkg/pkg_install.sls

init_pkg_install:
pkg.installed:
- names:
- gcc
- gcc-c++
- make
- autoconf
- openssl-devel
- pcre-devel

4.2 安装依赖包 initpkg.sls

[root@node1 dev]# mkdir initpkg

[root@node1 dev]# vim initpkg/install.sls

init-pkg-install:
pkg.installed:
- names:
- gcc
- gcc-c++
- make
- autoconf
- openssl
- openssl-devel
- lsof
- tree
- lrzsz

4.3 源码编译安装 pcre

[root@node1 dev]# mkdir pcre

[root@node1 dev]# vim pcre/install.sls

include:
- initpkg.install pcre-source-install:
file.managed:
- name: /usr/local/src/pcre-8.38.tar.gz
- source: salt://pcre/files/pcre-8.38.tar.gz
- user: root
- group: root
- mode:
cmd.run:
- name: cd /usr/local/src && tar xf pcre-8.38.tar.gz && cd pcre-8.38 && ./configure --prefix=/usr/local/pcre && make && make install
- unless: test -d /usr/local/pcre
- reuqire:
- file: pcre-source-install

4.4 编译安装nginx

[root@node1 dev]# mkdir nginx

[root@node1 dev]# vim nginx/install.sls

include:
- initpkg.install
- pcre.install nginx-source-install:
file.managed:
- name: /usr/local/src/nginx-1.12..tar.gz
- source: salt://nginx/files/nginx-1.12.2.tar.gz
- user: root
- group: root
- mode:
cmd.run:
- name: cd /usr/local/src && tar xf nginx-1.12..tar.gz && cd nginx-1.12. && ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module --with-pcre=/usr/local/src/pcre-8.38 && make && make install
- unless: test -d /usr/local/nginx
- require:
- file: nginx-source-install
- pkg: init-pkg-install
- file: pcre-source-install
nginx-init:
file.managed:
- name: /etc/init.d/nginx
- source: salt://nginx/files/nginx
- user: root
- group: root
- mode:
cmd.run:
- name: chkconfig --add nginx
- unless: chkconfig --list |grep nginx
- reuqire:
- cmd: nginx-source-install
- file: nginx-init

4.5 配置top

[root@node1 dev]# vim top.sls

[root@node1 dev]# cd nginx/

[root@node1 nginx]# mkdir files

[root@node1 nginx]# cd files/

4.6 下载包

[root@node1 files]# ll

-rw-r--r--.  root root    Apr   : nginx
-rw-r--r--. root root Oct nginx-1.12..tar.gz

[root@node1 files]# cd ../../pcre/

[root@node1 pcre]# mkdir files

[root@node1 pcre]# cd files

[root@node1 files]# ll

[root@node1 files]# vim nginx

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: -
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid # Source function library.
. /etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ "$NETWORKING" = "no" ] && exit nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" lockfile=/var/lock/subsys/nginx start() {
[ -x $nginx ] || exit
[ -f $NGINX_CONF_FILE ] || exit
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq ] && rm -f $lockfile
return $retval
} restart() {
configtest || return $?
stop
start
} reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
} configtest() {
$nginx -t -c $NGINX_CONF_FILE
} rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null >&
} case "$1" in
start)
rh_status_q && exit
$
;;
stop)
rh_status_q || exit
$
;;
restart|configtest)
$
;;
reload)
rh_status_q || exit
$
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit
esac

4.7 检测

[root@node1 dev]# tree

.
├── initpkg
│   └── install.sls
├── nginx
│   ├── files
│   │   ├── nginx
│   │   └── nginx-1.12..tar.gz
│   └── install.sls
├── pcre
│   ├── files
│   │   └── pcre-8.38.tar.gz
│   └── install.sls
└── top.sls directories, files

4.8 测试

[root@node1 files]# salt 'web1' state.highstate env=dev test

4.9 运行

[root@node1 files]# salt 'web1' state.highstate env=dev test=False

ID: nginx-init
Function: file.managed
Name: /etc/init.d/nginx
Result: True
Comment: File /etc/init.d/nginx updated
Started: ::24.379206
Duration: 68.116 ms
Changes:
----------
diff:
New file
mode: ----------
ID: nginx-init
Function: cmd.run
Name: chkconfig --add nginx
Result: True
Comment: Command "chkconfig --add nginx" run
Started: ::24.447622
Duration: 81.706 ms
Changes:
----------
pid: retcode: stderr:
stdout: Summary for web1
-------------
Succeeded: (changed=)
Failed:
-------------
Total states run:
Total run time: 449.603 s

检测

[root@node1 dev]# salt 'web1' cmd.run 'ls -l  /usr/local/nginx'
web1:
total
drwxr-xr-x. root root Apr : conf
drwxr-xr-x. root root Apr : html
drwxr-xr-x. root root Apr : logs
drwxr-xr-x. root root Apr : sbin

4.10 启动

[root@node1 dev]# salt 'web1' cmd.run 'systemctl restart nginx'
web1:
[root@node1 dev]# salt 'web1' cmd.run 'netstat -ntlp|grep nginx'
web1:
tcp 0.0.0.0: 0.0.0.0:* LISTEN /nginx: master

访问成功

saltstack的配置配置的更多相关文章

  1. saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy的Keepalived

    saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy的Keepalived 安装配置Keepalived 1.编写功能模块 #创建keepalived目录# mkdir -p ...

  2. saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy

    saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy 下载haproxy1.6.2.tar.gz下载地址:http://www.haproxy.org/download/1. ...

  3. nginx代理配置 配置中的静态资源配置,root 和 alias的区别。启动注意事项

    这篇主要内容是:nginx代理配置 配置中的静态资源配置,root 和 alias的区别.启动注意事项! 为什么会在window上配置了nginx呢?最近我们的项目是静态资源单独放在一个工程里面,后端 ...

  4. Testlink1.9.17使用方法( 第三章 初始配置[配置用户、产品] )

    第三章 初始配置(配置用户.产品) 一. 设置用户 QQ交流群:585499566 在TestLink系统中,每个用户都可以维护自己的私有信息.admin可以创建用户,但不能看到其它用户的密码.在用户 ...

  5. nginx代理配置 配置中的静态资源配置,root 和 alias的区别

    这篇主要内容是:nginx代理配置 配置中的静态资源配置,root 和 alias的区别.启动注意事项! 为什么会在window上配置了nginx呢?最近我们的项目是静态资源单独放在一个工程里面,后端 ...

  6. saltstack之(七)配置管理系统初始化init

    saltstack的配置管理分环境管理:①.base为基础环境,一般会存放一些所有服务器都使用的配置管理信息.②.dev为开发测试环境,一般会存放一些开发测试服务器使用的配置管理信息.③.pro为线上 ...

  7. saltstack安装与配置

    Saltstack是基于Python开发的一套C/S架构,具备Puppet.Ansible功能于一身的配置管理工具,功能十分强大,各模块融合度及复用性极高:使用号称世界上最快的消息队列ZeroMQ使得 ...

  8. SaltStack 安装及配置认证

    一.SaltStack 安装 SaltStack 是基于 Python 开发的,也是基于 C/S 架构,通过服务端 ( master ) 控制多台客户端 ( minion ) 实现批量操作这里我们使用 ...

  9. SaltStack安装及配置

    1.简介SaltStack是一个服务器基础架构集中化管理平台,具备配置管理.远程执行.监控等功能,一般可以理解为简化版的puppet和加强版的func.SaltStack基于Python语言实现,结合 ...

  10. SaltStack自动化安装配置haproxy的Keepalived

    keepalived配置安装 什么是vrrp,阿里云不支持组播,所以阿里云上不能配置keepalived,但是它有自己的slb.运维的大忌,在命令行复制粘贴,一般是先复制到文本中查看确认以后salt编 ...

随机推荐

  1. iOS-CoreLocation:无论你在哪里,我都要找到你!

    作者:@翁呀伟呀 授权本站转载 CoreLocation 1.定位 使用步骤: 创建CLLocationManager示例,并且需要强引用它 设置CLLocationManager的代理,监听并获取所 ...

  2. 22-2 模板语言的进阶和fontawesome字体的使用

    一  fontfawesome字体的使用 http://fontawesome.dashgame.com/ 官网 1 下载 2 放到你的项目下面 3 html导入这个目录 实例: class最前面的f ...

  3. Java之Socket与HTTP区别

    我们都知道TCP/IP协议共分四层: ① 链路层,有时也称作数据链路层或网络接口层,通常包括操作系统中的设备驱动程序和计算机中对应的网络接口卡.它们一起处理与电缆(或其他任何传输媒介)的物理接口细节. ...

  4. @loj - 6353@「CodePlus 2018 4 月赛」组合数问题 2

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 请你找到 k 个不同的组合数,使得对于其中任何一个组合数 \(C ...

  5. Open Source GIS and Freeware GIS Applications

    Open Source GIS and Freeware GIS Applications   An open source application by definition is software ...

  6. 设置 Tomcat 的JVM运行内存

    win7,64位: Tomcat7.0.5:jdk1.7: 情况一:Tomcat注册成系统服务,如何修改JVM运行内存? WINDOW 64位 , cmd打开注册表(regedit) HKEY_LOC ...

  7. 达观数据CTO纪达麒:小标注数据量下自然语言处理实战经验

    自然语言处理在文本信息抽取.自动审校.智能问答.情感分析等场景下都有非常多的实际应用需求,在人工智能领域里有极为广泛的应用场景.然而在实际工程应用中,最经常面临的挑战是我们往往很难有大量高质量的标注语 ...

  8. Array.from()类数组转化为数组的用法

    类数组对象转化为数组 let arrayLike = { '0': 'a', '1': 'b', '2': 'c', length: 3 }; let arr = Array.from(arrayLi ...

  9. java Math和Random和UUID

    Math类 public final class Math extends Object 以下X表示double,float,int, long abs(X x):求绝对值 max(X x1,X x2 ...

  10. 浅谈集合框架三、Map常用方法及常用工具类

    最近刚学完集合框架,想把自己的一些学习笔记与想法整理一下,所以本篇博客或许会有一些内容写的不严谨或者不正确,还请大神指出.初学者对于本篇博客只建议作为参考,欢迎留言共同学习. 之前有介绍集合框架的体系 ...