温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

自动安装puppet脚本

发布时间:2020-06-17 16:43:37 来源:网络 阅读:932 作者:hx10 栏目:编程语言

vm1为master  hostname为vm1.example.com

vm2 vm3 vm4为client,hostname为vm2|vm3|vm4.example.com

脚本如下:

 

  1. #!/bin/bash 
  2. PROG_NAME=$0 
  3. vm=$1 
  4.  
  5. usage() { 
  6.     echo "Usage: $PROG_NAME {vm1|vm2|vm3|vm4|reca}" 
  7.     exit 1; 
  8.  
  9. if [ $# -ne 1 ]; then 
  10.     usage 
  11. fi 
  12.  
  13. prepare() 
  14. echo "alias vivim=vi">> ~/.bash_profile 
  15. service iptables stop 
  16. cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 
  17. /usr/sbin/ntpdate time.nist.gov 
  18. echo "*/5 * * * * /usr/sbin/ntpdate time.nist.gov" > /var/spool/cron/root 
  19. chmod 600 /var/spool/cron/root 
  20.  
  21. install_master() 
  22.  
  23. sed -i "s/HOSTNAME=.*/HOSTNAME=${vm}.example.com/" /etc/sysconfig/network 
  24. hostname $vm.example.com 
  25. echo "10.13.114.3           vm1.example.com" >> /etc/hosts 
  26. echo "10.13.114.25          vm2.example.com" >> /etc/hosts 
  27. echo "10.13.114.27          vm3.example.com" >> /etc/hosts 
  28. echo "10.13.114.30          vm4.example.com" >> /etc/hosts 
  29.  
  30. #####step 1.install ruby environment##### 
  31. wget http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo -O /etc/yum.repos.d/CentOS-Base.repo 
  32. yum -y install ruby ruby-rdoc 
  33.  
  34.  
  35. #####step 2.install puppet server####### 
  36. rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-4.noarch.rpm 
  37. yum -y install puppet-server  
  38. chkconfig --level 2345 puppetmaster on 
  39.  
  40. cat >> /etc/puppet/manifests/site.pp << EOF 
  41. node default { 
  42.           file { "/tmp/temp1.txt": content => "hello,first puppet manifest"; } 
  43.          } 
  44. EOF 
  45.  
  46.  
  47. cat >>/etc/puppet/autosign.conf <<EOF 
  48. *.example.com 
  49. EOF 
  50.  
  51.  
  52.  
  53. install_client() 
  54. sed -i "s/HOSTNAME=.*/HOSTNAME=${vm}.example.com/" /etc/sysconfig/network 
  55. hostname $vm.example.com 
  56. echo "10.13.114.3           vm1.example.com" >> /etc/hosts 
  57. echo "10.13.114.25          vm2.example.com" >> /etc/hosts 
  58. echo "10.13.114.27          vm3.example.com" >> /etc/hosts 
  59. echo "10.13.114.30          vm4.example.com" >> /etc/hosts 
  60.  
  61. #####step 1.install ruby environment##### 
  62. wget http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo -O /etc/yum.repos.d/CentOS-Base.repo 
  63. yum -y install ruby ruby-rdoc 
  64.  
  65.  
  66. ####step 2.install puppet server#### 
  67. rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-4.noarch.rpm 
  68. yum -y install puppet 
  69. chkconfig --level 2345 puppet on 
  70.  
  71. echo "  server=vm1.example.com">>/etc/puppet/puppet.conf 
  72. echo "  listen=true">>/etc/puppet/puppet.conf 
  73. cat >>/etc/puppet/namespaceauth.conf << EOF 
  74. [fileserver] 
  75. allow * 
  76. [puppetmaster] 
  77. allow * 
  78. [puppetrunner] 
  79. allow * 
  80. [puppetbucket] 
  81. allow * 
  82. [puppetreports] 
  83. allow * 
  84. [resource] 
  85. allow * 
  86. EOF 
  87.  
  88.  
  89.  
  90. re_create_ca() 
  91. rm -f /var/lib/puppet/ssl/certs/* 
  92. rm -f /var/lib/puppet/ssl/certificate_requests/* 
  93. rm -f /var/lib/puppet/ssl/crl.pem 
  94.  
  95. case "$vm" in 
  96.     vm1) 
  97.     prepare 
  98.     install_master 
  99.     ;; 
  100.     vm2) 
  101.     prepare 
  102.     install_client 
  103.     ;; 
  104.     vm3) 
  105.     prepare 
  106.     install_client 
  107.     ;; 
  108.     vm4) 
  109.     prepare 
  110.     install_client 
  111.     ;; 
  112.     reca) 
  113.     re_create_ca 
  114.     ;; 
  115.     *) 
  116.     usage 
  117.     ;; 
  118. esac 

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI