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

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. python 浮点型(float)

  2. oralce ROLLUP

    select id,area,stu_type,sum(score) score from students group by rollup(id,area,stu_type) order by id ...

  3. idea 启动一直一直build以及勉勉强强的解决方案

    周日做了一个密匙解析的功能,在idea的springboot项目的该类上写了个main方法测试,当时一直提示build,没在意,直接打开eclipse上写 今天早上发现 idea启动springboo ...

  4. SVN的使用与教程

    1.先下载SVN安装包 SVN安装教程

  5. iptables 网址转译 (Network Address Translation,NAT)

    当封包流经NAT電腦時,其位址/通訊端口會被修改,以達到改变包目的地(或旅程),或是让目的地误以为包是源自NAT电脑的效果.換言之,对封包执行NAT的电脑,可以成为新包的来源或目的地,或是成为真正来源 ...

  6. linux lvm删除导致无法启动

    要想编辑/etc/fstab文件,我们需要在系统中重新挂载根目录,使其具有可读写状态,使用如下命令: mount -o remount,rw / 该条命令的作用是,以可读写的形式重新挂载根分区. 然后 ...

  7. Project Euler Problem 9-Special Pythagorean triplet

    我是俩循环暴力 看了看给的文档,英语并不好,有点懵,所以找了个中文的博客看了看:勾股数组学习小记.里面有两个学习链接和例题. import math def calc(): for i in rang ...

  8. laravel安装intervention/image图像处理扩展 报错 intervention/image 2.3.7 requires ext-fileinfo

    在安装intervention/image图像处理扩展 报错fileinfo is missing 报错信息如下: \blog>composer require intervention/ima ...

  9. 【t013】无聊的军官

    Time Limit: 1 second Memory Limit: 32 MB [问题描述] 每个学年的开始,高一新生们都要进行传统的军训.今年有一个军训教官十分奇怪,他为了测试学员们的反应能力,每 ...

  10. 基于 Laravel-Admin 在十分钟内搭建起功能齐全的后台模板

    http://laravelacademy.org/post/6468.html 1.简介 为 Laravel 提供后台模板的项目越来越多,学院君已陆续为大家介绍过Laravel Angular Ad ...