1.配置master配置文件

[root@master jdk]# cat /etc/salt/master | grep -v "#" | grep -10 "file_roots"
file_roots:
base:
- /soft/salt
dev:
- /soft/salt/dev/services
- /soft/salt/dev/states
prod:
- /soft/salt/prod/services
- /soft/salt/prod/states

2.编写jdk的sls文件,上传jdk介质​

[root@master state]# pwd
/soft/salt/state
[root@master state]# tree
.
├── jdk
│ ├── files
│ │ └── jdk-8u202-linux-x64.tar.gz
│ └── init.sls

3.查看init.sls文件

[root@master state]# cat jdk/init.sls 
jdk-install:
file.managed:
- name: /usr/local/src/jdk-8u202-linux-x64.tar.gz
- source: salt://state/jdk/files/jdk-8u202-linux-x64.tar.gz
- user: root
- group: root
- mode: 755
cmd.run:
- name: cd /usr/local/src && tar xf jdk-8u202-linux-x64.tar.gz && mv jdk1.8.0_202 /usr/local/jdk && chown -R root:root /usr/local/jdk
- unless: test -d /usr/local/jdk
- require:
- file: jdk-install

jdk-config:
file.append:
- name: /etc/profile
- text:
- export JAVA_HOME=/usr/local/jdk
- export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
- export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

4.在minion01执行命令安装jdk。使用state.sls方式​

[root@master state]# salt minion01 state.sls state.jdk
minion01:
----------
ID: jdk-install
Function: file.managed
Name: /usr/local/src/jdk-8u202-linux-x64.tar.gz
Result: True
Comment: File /usr/local/src/jdk-8u202-linux-x64.tar.gz updated
Started: 17:23:13.127525
Duration: 12368.83 ms
Changes:
----------
diff:
New file
mode:
0755
----------
ID: jdk-install
Function: cmd.run
Name: cd /usr/local/src && tar xf jdk-8u202-linux-x64.tar.gz && mv jdk1.8.0_202 /usr/local/jdk && chown -R root:root /usr/local/jdk
Result: True
Comment: Command "cd /usr/local/src && tar xf jdk-8u202-linux-x64.tar.gz && mv jdk1.8.0_202 /usr/local/jdk && chown -R root:root /usr/local/jdk" run
Started: 17:23:25.498202
Duration: 11240.566 ms
Changes:
----------
pid:
30568
retcode:
0
stderr:
stdout:
----------
ID: jdk-config
Function: file.append
Name: /etc/profile
Result: True
Comment: File /etc/profile is in correct state
Started: 17:23:36.739389
Duration: 13.821 ms
Changes:

Summary for minion01
------------
Succeeded: 3 (changed=2)
Failed: 0
------------
Total states run: 3
Total run time: 23.623 s

5.在minion01节点查看​

[root@minion01 ~]# java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

版权声明:本文为博主原创文章,未经博主允许不得转载。

LINUX