puppet之java批量安裝案例
利用puppet對若干臺linux伺服器安裝java,設定java環境變數,本文以一臺agent為例安裝java
一 服務端模組
新建目錄
mkdir -p /etc/puppet/modules/java/manifests
在該目錄下有關於安裝java的若干個檔案
tree /etc/puppet/modules/java/manifests/
/etc/puppet/modules/java/manifests/
|-- init.pp
|-- install_java.pp
`-- set_profile.pp
init.pp是每個模組的必需初始化檔案,puppet會根據init.pp尋找其他檔案中定義的類
[root@master puppet]# cat /etc/puppet/modules/java/manifests/init.pp
class java {
include java::install_java
include java::set_profile
}
install_java.pp中定義了一個install_java類,包含有file,exec資源。file資源是定義從puppet服務端取檔案的,本文是從puppet的/etc/puppet/files取檔案jdk-6u24-linux-i586.bin,放到agent的/usr/local/src檔名不變。檔案屬性是:屬主root,屬組root,許可權是755.exec資源定義了執行jdk-6u24-linux-i586.bin這個動作。cwd說明進入某個目錄,creates定義如果該檔案存在則不執行該資源,command定義執行的命令。require定義了exec資源依賴於file:/usr/local/src/jdk-6u24-linux-i586.bin,必須有/usr/local/src/jdk-6u24-linux-i586.bin檔案存在才執行該資源。
[root@master puppet]# cat /etc/puppet/modules/java/manifests/install_java.pp
class java::install_java {
file {
"/usr/local/src/jdk-6u24-linux-i586.bin": #copy file to remote machine,File paths must be fully qualified
owner => "root",
group => "root",
mode => 755,
source => "puppet://$puppetserver/files/jdk-6u24-linux-i586.bin",
}
exec {
"sh /usr/local/src/jdk-6u24-linux-i586.bin":
cwd => "/usr/local/src/", # end with "/"
creates => "/usr/local/java", #if the file "/usr/local/java" is not found,do below command.
command => "sh /usr/local/src/jdk-6u24-linux-i586.bin && mv /usr/local/src/jdk1.6.0_24 /usr/local/java",
user => "root",
path => ["/usr/local/sbin","/usr/local/bin","/sbin","/bin","/usr/sbin","/usr/bin"],
require => File["/usr/local/src/jdk-6u24-linux-i586.bin"],
}
}
設定java環境變數
unless定義瞭如果grep -i java_home /etc/profile返回的值為1,即結果為false才執行該資源。
[root@master puppet]# cat /etc/puppet/modules/java/manifests/set_profile.pp
class java::set_profile {
file {
"/usr/local/src/java_profile": #copy file to remote machine,File paths must be fully qualified
owner => "root",
group => "root",
source => "puppet://$puppetserver/files/java_profile",
}
exec {
"set profile":
command => "cat /usr/local/src/java_profile >>/etc/profile && source /etc/profile",
user => "root",
path => ["/usr/local/sbin","/usr/local/bin","/sbin","/bin","/usr/sbin","/usr/bin"],
unless => "grep -i java_home /etc/profile", #if the return value is 1,do this command.
require => File["/usr/local/src/java_profile"],
}
}
在/etc/puppet/manifests/定義了一些模組和節點的資訊
[root@master manifests]# tree /etc/puppet/manifests/
/etc/puppet/manifests/
|-- modules.pp
|-- nodes.pp
`-- site.pp
0 directories, 3 files
site.pp是puppet主要入口,告訴puppet從哪裡尋找載入指定的客戶端配置
[root@master manifests]# cat site.pp
import "modules.pp"
import "nodes.pp"
模組匯入藉口
[root@master manifests]# cat modules.pp
import "cron"
import "java"
import "mysql"
節點檔案,在節點檔案裡include模組
[root@master manifests]# cat nodes.pp
node 'agent1.andy.com' {
include cron
include java
#include mysql
}
一 服務端模組
新建目錄
mkdir -p /etc/puppet/modules/java/manifests
在該目錄下有關於安裝java的若干個檔案
tree /etc/puppet/modules/java/manifests/
/etc/puppet/modules/java/manifests/
|-- init.pp
|-- install_java.pp
`-- set_profile.pp
init.pp是每個模組的必需初始化檔案,puppet會根據init.pp尋找其他檔案中定義的類
[root@master puppet]# cat /etc/puppet/modules/java/manifests/init.pp
class java {
include java::install_java
include java::set_profile
}
install_java.pp中定義了一個install_java類,包含有file,exec資源。file資源是定義從puppet服務端取檔案的,本文是從puppet的/etc/puppet/files取檔案jdk-6u24-linux-i586.bin,放到agent的/usr/local/src檔名不變。檔案屬性是:屬主root,屬組root,許可權是755.exec資源定義了執行jdk-6u24-linux-i586.bin這個動作。cwd說明進入某個目錄,creates定義如果該檔案存在則不執行該資源,command定義執行的命令。require定義了exec資源依賴於file:/usr/local/src/jdk-6u24-linux-i586.bin,必須有/usr/local/src/jdk-6u24-linux-i586.bin檔案存在才執行該資源。
[root@master puppet]# cat /etc/puppet/modules/java/manifests/install_java.pp
class java::install_java {
file {
"/usr/local/src/jdk-6u24-linux-i586.bin": #copy file to remote machine,File paths must be fully qualified
owner => "root",
group => "root",
mode => 755,
source => "puppet://$puppetserver/files/jdk-6u24-linux-i586.bin",
}
exec {
"sh /usr/local/src/jdk-6u24-linux-i586.bin":
cwd => "/usr/local/src/", # end with "/"
creates => "/usr/local/java", #if the file "/usr/local/java" is not found,do below command.
command => "sh /usr/local/src/jdk-6u24-linux-i586.bin && mv /usr/local/src/jdk1.6.0_24 /usr/local/java",
user => "root",
path => ["/usr/local/sbin","/usr/local/bin","/sbin","/bin","/usr/sbin","/usr/bin"],
require => File["/usr/local/src/jdk-6u24-linux-i586.bin"],
}
}
設定java環境變數
unless定義瞭如果grep -i java_home /etc/profile返回的值為1,即結果為false才執行該資源。
[root@master puppet]# cat /etc/puppet/modules/java/manifests/set_profile.pp
class java::set_profile {
file {
"/usr/local/src/java_profile": #copy file to remote machine,File paths must be fully qualified
owner => "root",
group => "root",
source => "puppet://$puppetserver/files/java_profile",
}
exec {
"set profile":
command => "cat /usr/local/src/java_profile >>/etc/profile && source /etc/profile",
user => "root",
path => ["/usr/local/sbin","/usr/local/bin","/sbin","/bin","/usr/sbin","/usr/bin"],
unless => "grep -i java_home /etc/profile", #if the return value is 1,do this command.
require => File["/usr/local/src/java_profile"],
}
}
在/etc/puppet/manifests/定義了一些模組和節點的資訊
[root@master manifests]# tree /etc/puppet/manifests/
/etc/puppet/manifests/
|-- modules.pp
|-- nodes.pp
`-- site.pp
0 directories, 3 files
site.pp是puppet主要入口,告訴puppet從哪裡尋找載入指定的客戶端配置
[root@master manifests]# cat site.pp
import "modules.pp"
import "nodes.pp"
模組匯入藉口
[root@master manifests]# cat modules.pp
import "cron"
import "java"
import "mysql"
節點檔案,在節點檔案裡include模組
[root@master manifests]# cat nodes.pp
node 'agent1.andy.com' {
include cron
include java
#include mysql
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-776321/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- puppet之mysql批量安裝案例MySql
- kickstart之批量安裝puppet客戶端客戶端
- puppet之安裝配置
- puppet 安裝
- puppet rpm方式的安裝
- RHEL6下puppet部署管理1之安裝測試
- puppet完全攻略(一)puppet應用原理及安裝部署
- 如何在 Ubuntu 15.04 中安裝 puppetUbuntu
- CentOS 6.3下Puppet安裝配置筆記CentOS筆記
- Puppet+foreman 本地yum安裝手冊REM
- cobbler 批量安裝linux薦Linux
- 在centos 5.6 64位用yum安裝puppet 2.6.9(一)薦CentOS
- puppet之crontab時間同步
- python庫批量安裝的方法Python
- Java爬坑日記之批量更新Java
- 批量載入效能案例
- 使用adb如何批量給裝置安裝apkAPK
- win10怎麼批處理批量安裝字型_win10批量安裝字型的步驟Win10
- 批量安裝python庫函式—pipPython函式
- PXE + Kickstart無人值守批量安裝OS
- codis安裝 (java 安裝 + zookeeper 安裝 + go 安裝 + codis 安裝JavaGo
- ffmpeg安裝之mac安裝Mac
- SPARK 安裝之scala 安裝Spark
- 多種方式批量安裝作業系統作業系統
- 自動化運維工具之Puppet模組運維
- MySQL批量更新死鎖案例分析MySql
- Pig安裝及入門案例
- PSU之解除安裝與安裝
- 無人值守批量安裝linux作業系統Linux作業系統
- Redis安裝與使用之簡單案例Redis
- docker筆記18-案例-安裝mysqlDocker筆記MySql
- PIG安裝配置及案例應用
- (CMake):CMake安裝及快速入門案例
- 另一種批量裝機神器-----使用PXE批量裝機
- ffmpeg安裝之linux編譯安裝Linux編譯
- Ubuntu 安裝 Java JdkUbuntuJavaJDK
- linux安裝javaLinuxJava
- Puppet實戰