自動化運維---puppet入門


1.puppet簡介

Puppet: 集中式的配置管理工具,通過自有配置語言對節點進行目標狀態定義,並能夠基於網絡實現目標狀態的維護。Puppet可管理配置文件、用戶、cron任務、軟件包、服務系統等。Puppet把這些系統實體稱之爲資源,puppet的設計目標是簡化對這些資源的管理以及妥善處理資源間的依賴關係。

aHR0cHM6Ly9tbWJpei5xbG9nby5jbi9tbWJpel9w

2.配置puppet的yum源及安裝前操作

地址:http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm

[root@localhost~]#yum install -y http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm

單機演示:

hosts文件,或dns提供解析

192.168.122.18 master.arethon.com master

[root@localhost ~]# vim /etc/hosts

增加:192.168.122.18 master.arethon.com master

[root@localhost ~]# hostnamectl set-hostname master.arethon.com

[root@localhost ~]# su –l

3.puppet安裝

[root@master ~]# yum install ruby ruby-augeas ruby-shadow –y

[root@master ~]# yum install -y puppet

查看puppet幫助:

[root@master ~]# puppet help

查看puppet子命令的幫助:

[root@master ~]# puppet help apply

4.puppet核心資源用法

1.notify:調試輸出

[root@master ~]# mkdir /test

[root@master ~]# cd /test

[root@master test]# vim test1.pp

blob.png

運行:

blob.png

#若要看詳細信息,使用-v,查看過程使用-d(debug)

[root@master test]# puppet apply test1.pp -v –d

2.package:軟件包管理

查看幫助:

[root@master test]# puppet describe package

1.安裝mariadb:

[root@master test]# vim test2.pp

blob.png

運行:

blob.png

查看是否安裝成功:

[root@master test]# rpm -q mariadb

卸載mariadb:

[root@master test]# vim test3.pp

blob.png

運行:

blob.png

查看是否卸載成功:

[root@master test]# rpm -q mariadb

2.利用RPM命令互聯網安裝lftp

[root@master test]# vim install_lftp.pp

blob.png

運行:

blob.png

查看是否安裝成功:

[root@master test]# rpm -q lftp

3.service:服務管理資源

查看幫助:

[root@master test]# puppet describe service

安裝vsftp,並設置當前啓動。

[root@master test]# vim install_vsftp.pp

blob.png

運行:

blob.png

驗證:

[root@master test]# rpm -q vsftpd

[root@master test]# systemctl status vsftpd

4.file:管理文件、目錄、符號鏈接

1.自動生成文件

[root@master test]# vim test4.pp

blob.png

運行:

blob.png

2.創建鏈接文件

[root@master test]# vim test4.pp

blob.png

運行:

blob.png

查看:

[root@master test]# ls -l /var/soft_hello

lrwxrwxrwx. 1 root root 15 10月 23 13:08 /var/soft_hello -> /test/hello.txt

5.exec:執行命令

[root@master test]# vim test5.pp

blob.png

運行:

blob.png

6.user:管理用戶

查看幫助:

[root@master test]# puppet describe user

1.創建組和用戶

[root@master test]# vim test6.pp

blob.png

運行並查看結果:

blob.png

7.cron:計劃任務

寫一個定時關機的計劃任務

[root@master test]# vim test7.pp

blob.png

運行:

blob.png

在計劃任務中查看:

blob.png


學習更多Linux運維知識,請關注微信公衆號--格物致其知


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章