RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
自动安装puppet脚本

vm1为master  hostname为vm1.example.com

创新互联公司专业为企业提供全州网站建设、全州做网站、全州网站设计、全州网站制作等企业网站建设、网页设计与制作、全州企业网站模板建站服务,10年全州做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

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

 


当前标题:自动安装puppet脚本
URL链接:http://dtcuyxr.com/article/jdopph.html