linuxhot自动化运维UNIXHOT打造中_第1页
linuxhot自动化运维UNIXHOT打造中_第2页
linuxhot自动化运维UNIXHOT打造中_第3页
linuxhot自动化运维UNIXHOT打造中_第4页
linuxhot自动化运维UNIXHOT打造中_第5页
已阅读5页,还剩30页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、自动化运维自动化运维UNIXHOT 运维社区:UNIXHOT 打造最专业的运维门户1自动化运维Copyright (c) 2010 Zhao Shundong. Permission is granted to copy, distribute and/or modify thisdocument under the terms of the GNUDocumentation License, Version 1.2 or any later versionpublished by theSoftware Foundation; with no Invariant Sections, no F

2、ront-Cover Texts, and noBack-Cover Texts. A copy of the license is included in the section entitled "GNUDocumentationLicense".使用说明:1.为保证本文的完整性和可用性,本文遵循 GFDL 协议。2.可以在找到本文的最新版本。3.本文参考使用,不承担任何因文档错误而造成的任何损失。4.有任何问题可以在 UnixHot 运维社区讨论交流。5.由于时间仓促,有些章节讲解的不够深入,敬请谅解,下个版本加强。6.有相关问题或业务合作。请邮件至 admin。相关

3、文档:1.Linux系统运维之系统架构2.Linux系统运维之系统管理3.Linux系统运维之运维4.Linux系统运维之性能优化5.Linux系统运维之运维规范6.Linux系统运维之 MySQL DBA7.Linux系统运维之 Oracle DBA8.自动化运维修订历史UNIXHOT 打造最专业的运维门户2自动化运维UNIXHOT 打造最专业的运维门户3日期版本说明2010.04.010.1创建本文档2010.04.200.2正式互联网发布自动化运维前言从开始实施自动化运维已经很久了,一直没的整理过文档,本次版本可能比较粗糙,没有经过仔细的校对,有问题可以直接在群里讨论,或者登录获得相关的

4、内容。自动化运维是目前每个运维团队都在积极部署和讨论的话题,本文通过目前互联网常用的工具进行简单的阐述,自动化安装、自动化管理、自动化配置。本文入门级别的自动化运维的阐述,高手看到这里可以关闭了。第 1 章 自动化安装1.1 Kickstart 还是 cobbler在自动化运维的大浪潮中,每个人都可以有喜欢的工具,在我们团队的系统中,自动化安装一直是 Kickstart 占据着重要的位置,我不否认 cobbler 的成绩和很多人的赞美,至少我用 cobbler无法网络安装 ESXi,但是通过原的 Kisckstart 却可以。1.2 Kickstart 自定义Kickstart 的安装略,后期

5、加上。1.2.1 自定义开机的界面rootmail tftpboot# cat boot.msg*Kickstart by Jason Zhao*-To install or upgrade in graphical mode, press the 01<ENTER>07 key.-To install or upgrade in text mode, type: 01linux text <ENTER>07.-Use the function keys listed below for more information.0fF1-Main F2-Options F3-

6、General F4-Kernel F5-Rescue07-Please select and input the operating system for installedUNIXHOT 打造最专业的运维门户4自动化运维-Option:rhel5564 rhel5532 centos5564 centos5532 ESXi5.0 ESXi 设置安装选项rootmail pxelinux.cfg# cat defaultdefault rhel5564prompt 1timeout 60000display boot.msgF1 boot.msgF2 options.msgF

7、3 general.msgF4 param.msgF5 rescue.msglabel rhel5564kernel vmlinuzappend ks initrd=initrd.img ks=ftp:/*.*.*.*/pub/shell/rhel5564.cfg ksdevice=eth0(部分内容略去)rootmail pxelinux.cfg# pwd/tftpboot/pxelinux.cfg1.3 Cobbler 安装部署步骤略,比较简单,网上有众多的文档,时间问题再次省略。第 2 章 自动化运维工具 Func2.1 Func 简介Func 全称为 Fedora Unified Ne

8、twork Controller(Fedora 统一网络器),是由 Fedara 社区维护管理的工具。在生产应用中可以代替 Expect,运行在 C/S 模式下,可的一款用于服务器自动化UNIXHOT 打造最专业的运维门户5自动化运维以再主控端进行批量的管理操作。2.2 Func 特性· 1.Func 可以在主控机上一次管理任意多台服务器,或任意多个服务器组;· 2.Func 基于 Certmaster()建立了 Master Slaves 主从SSL管控体系,可以将自动分发到所有受控服务器;· 3.Func 命令行可以直接发送命令或者获取数据;· 4.

9、Func常用任务模块:dModule 、 FileTrackerModule 、 JBossModule 、 IPtablesModule 、HardwareModule 、MountModule、NagiosCheck、NetappModule、 NetworkTest、ProcessModule、ServiceModule、SysctlModule、RebootModule、RpmModule、VirtModule、YumModule 等等,这些模块的作用都可以顾名思义,或者参考:;· 5.任何人都可以通过 FuncAPI 轻松编写提供的的模块,以实现具体功能扩展。而且 任何 F

10、unc命令行能完成的工作,都能通过 API 编程实现;· 6.Func 通讯基于 XMLRPC 和 SSL 标准协议。2.3 Func 安装Func 的安装非常的简单,由于之前没有安装过程,使用的是一个脚本安装的,func 是初始化安装调用脚本中的一个功能函数,在此贴出。你可以将他嵌入到您自动化安装后执行的脚本中,注意两个个变量即可 FILE_SERVER 是文件服务器,SOFTWARE_PATH 是您将后的安装包存放的位置。func_install()cd $SOFTWARE_PATHwget "$FILE_SERVER"/-2.6.tgzwget "

11、$FILE_SERVER"/certmaster-0.25.tar.gzwget "$FILE_SERVER"/func-0.25.tar.gzwget "$FILE_SERVER"/pyOpenSSL-0.9.tar.gzchmod +x-2.6.tgzchmod +x certmaster-0.25.tar.gzUNIXHOT 打造最专业的运维门户6自动化运维chmod +x func-0.25.tar.gzchmod +X pyOpenSSL-0.9.tar.gztar zxvf-2.6.tgzcd-2.6./configure -pre

12、fix=/usr/local/make && make installcd $SOFTWARE_PATHtar zxvf pyOpenSSL-0.9.tar.gzcd pyOpenSSL-0.9/usr/local/bin/setup.py installcd $SOFTWARE_PATHtar zxvf certmaster-0.25.tar.gzcd certmaster-0.25/usr/local/bin/setup.py installcd $SOFTWARE_PATHtar zxvf func-0.25.tar.gzcd func-0.25/usr/local/bi

13、n/setup.py installln -s /usr/local/bin/certmaster /usr/bin/certmasterln -s /usr/local/bin/certmaster-request /usr/bin/certmaster-requestln -s /usr/local/bin/certmaster-ca /usr/bin/certmaster-caln -s /usr/local/bin/certmaster-sync /usr/bin/certmaster-syncln -s /usr/local/bin/funcd /usr/bin/funcdln -s

14、 /usr/local/bin/func /usr/bin/funcln -s /usr/local/bin/func-create-module /usr/bin/func-create-moduleln -s /usr/local/bin/func-inventory /usr/bin/func-inventoryln -s /usr/local/bin/func-transmit /usr/bin/func-transmitln -s /usr/local/bin/func-build-map /usr/bin/func-build-map注:不要让看似简单的频繁操作占用你的时间,尽量脚

15、本化,自动化。UNIXHOT 打造最专业的运维门户7自动化运维2.4 Func 配置安装完毕后,需要简单的配置才可以使用。2.4.1 /etc/hosts这个是第一个需要配置的,根据运维规范,建议将主机名设置为 web- 这样的模式,同时需要在/etc/hosts 绑定主机名和 ip 地址的对应。客户端需要至少两个绑定如:1 web-0 puppet-服务器端,需要多个绑定如:0 puppet-1 web-2 web-.(略)2.4.2 客户端配置rootapp-node1 12:01

16、:02 # cat /etc/certmaster/minion.conf# configuration for minionsmaincertmaster = puppet-certmaster_port = 51235log_level = DEBUGcert_dir = /etc/pki/certmaster2.4.3 服务器端配置rootpuppet-master func# cat /etc/certmaster/certmaster.conf# configuration for certmasterd and certmaster-caUNIXHOT 打造最专业的运维门户8自动化

17、运维mainautosign = yes#开启自动listen_addr =listen_port = 51235cadir = /etc/pki/certmaster/cacert_dir = /etc/pki/certmastercertroot = /var/lib/certmaster/certmaster/certscsrroot = /var/lib/certmaster/certmaster/csrscert_extension = certsync_certs = False2.4.4 启动服务客户端:(客户端只启动 funcd)rootbus-node1 12:02:13 #

18、 /etc/init.d/funcd start服务器端:(服务器端只启动 certmaster)rootpuppet-master # /etc/init.d/certmaster start2.5 服务器端操作2.5.1 查验证的服务器certmaster-ca -list2.5.2 验证服务器certmaster-ca -sign "linux-"2.5.3 显示已经验证的服务器certmaster-ca -list-signUNIXHOT 打造最专业的运维门户9自动化运维2.5.4 其它删除客户端:certmaster-ca -c hostname客户端重装:rm

19、/var/lib/certmaster/certmaster/certs/hostname.cert2.6 func 使用案例2.6.1 查看系统负载rootpuppet-master # func "bj*" calld run "cat /proc/loadavg"('app-', 0, '2.95 2.82 3.85 1/470 30863n', '')('app-', 0, '1.53 2.25 2.69 5/408 12488n', '')('

20、;app-', 0, '2.56 3.13 3.64 1/417 11484n', '')('app-', 0, '0.08 0.04 0.00 1/212 26374n', '')('app-', 0, '0.02 0.02 0.00 1/412 6820n', '')('app-', 0, '0.09 0.04 0.05 1/413 15550n', '')这个是d 模块,也就是说在 run 后面,你几乎可以

21、执行所有的系统命令,shell 脚本,返回值会返回。请官方文档获取所有内容:2.6.2dModule 模块格式:func hostname calld rund2.6.3 ServiceModule 模块格式:Func hostname call service start/stop/restart servername例:重新启动服务器的 vsftp 服务UNIXHOT 打造最专业的运维门户10自动化运维rootpuppet-master # func "" call service restart vsftpd'': 0 返回 0 为正常。2.6.4 J

22、BossModule 模块格式:func hostname call jbossd例:func "jboss-" call jboss statusfunc "jboss-" call jboss checkfunc "jboss-" call jboss search_by_instance "web"func "jboss-" call jboss search_by_port 80802.6 .5 ProcessModule 模块格式:Func hostname call processd

23、例:func ssh-1 call process info “aux”func ssh-1 call process memfunc ssh-1 call process kill httpd SIGHUP2.6.6 SysctlModule 模块格式:Func hostname call sysctld例:func ssh-1 call sysctl listfunc “*” call sysctl get <parameter> func“*” call sysctl set <parameter> <value>func ssh-1 call sys

24、ctl set net.ipv4.tcp_syncookies 1UNIXHOT 打造最专业的运维门户11自动化运维2.6.7 RpmModule 模块 ( =rpm qa )func"app-" call rpms inventory2.6.8 YumModule 模块func "app-" call yumcmd updatefunc "app-" calld run yum update第 3 章 运维自动化 Puppet3.1 PuppetPuppet 是开源的基于 Ruby 的系统配置管理工具,依赖于 C/S 的部署架构。主

25、要开发者是 LukeKanies,遵循 GPLv2协议。使用 Puppet 可以集中管理您服务器中的文件、进程等。工作原理:在端上安装 puppet-server包(被称作 Puppet master)。在被控端主机上安装puppet 客户端(被称作 Puppet)。当 Puppet连接上 Puppet master 后,定义在 Puppetmaster 上的配置文件会被编译,然后在客户端上运行。每个客户端默认每半个小时和服务器进行一次通信,确认配置的更新情况(可以通过修改配置文件修改,系统中每 5 分钟运行一次)。如果有新的配置或者配置已经改变,配置将会被重新编译并发布到各客户端执行。主动触

26、发:在需要马上更新所有客户端时,可以在服务器上主动触发一个配置的更新,强制各客户端进行配置。如果客户端的配置被改变了,它可以从服务器获得原始配置进行校正(通过 md5 比较来区分是否改变)。3.2 安装 PuppetUNIXHOT 打造最专业的运维门户12自动化运维3.2.1 修改主机名为 FQDN 名称rootpuppet-master # cat /etc/sysconfig/networkNETWORKING=yesNETWORKING_IPV6=noHOSTNAME=puppet-3.2.2 添加/etc/hosts 绑定rootpuppet-master # cat /etc/hos

27、ts# Do not remove the following line, or various programs# that require network functionality will fail.localhost.localdomain localhost:1localhost6.localdomain6 localhost611 puppet-3.2.3包rootpuppet-master # cd /usr/local/srcrootpuppet-master src# wgetrootpuppet-master src# wget3.2.4

28、 安装 Rubyrootpuppet-master # yum install ruby3.2.5 安装 Facter包rootpuppet-master src# tar zxvf facter-1.6.4.tar.gzrootpuppet-master src# cd facter-1.6.4rootpuppet-master facter-1.6.4# ruby install.rbUNIXHOT 打造最专业的运维门户13自动化运维3.2.6 安装 Puppet包rootpuppet-master src# tar zxvf puppet-2.7.6.tar.gzrootpuppet-m

29、aster src# cd puppet-2.7.6rootpuppet-master puppet-2.7.6# ruby install.rbrootpuppet-master # useradd -s /sbin/nologin -M puppet3.2.7 Puppet 安装后基本配置:rootpuppet-master # cd /usr/local/src/puppet-2.7.6rootpuppet-master puppet-2.7.6# cd conf/rootpuppet-master# cp puppet.conf /etc/puppet/rootpuppet-maste

30、r# cp fileserver.conf /etc/puppet/rootpuppet-master# cp logrotate /etc/puppet/rootpuppet-master# cp server.sysconfig /etc/sysconfig/puppetmasterrootpuppet-master# cp server.init /etc/init.d/puppetmasterrootpuppet-master# chmod 755 /etc/init.d/puppetmaster3.2.8 客户端配置在客户端制定 puppet Master。rootapp-node1

31、 13:22:26 # cat /etc/puppet/puppet.confmain# The Puppet log directory.# The default value is '$vardir/log'.logdir = /var/log/puppet# Where Puppet PID files are kept.# The default value is '$vardir/run'.rundir = /var/run/puppet# Where SSLs are kept.UNIXHOT 打造最专业的运维门户14自动化运维# The defau

32、lt value is '$confdir/ssl'.agent# The file in which puppetd stores a list of the classes# associated with the retrieved configuratiion.Can be loaded in# the separate puppet executable using the -loadclasses# option.# The default value is '$confdir/classes.txt'.classfile = $vardir/cla

33、sses.txtserver = puppet-#(指定 Puppet Master)report = true#(开启状态报告)runinterval = 180#(每隔 3 分钟向 Puppet Master 更新一次)# Where puppetd caches the local configuration. An# extension indicating the cache format is added automatically.# The default value is '$confdir/localconfig'.localconfig = $vardir

34、/localconfig3.3 启动测试3.3.1 Puppet 启动先以非调试模式启动,并输出详细,便于下面的客户端验证,观察输出:rootpuppet-master # puppet master -no-daemonize -debug -verbose3.3.2 客户端手动验证客户端:rootapp-node2 # puppetd -test -server puppet-管理端:rootpuppet-master # puppet cert-listapp- (7C:FA:82:AF:0C:0B:48:56:70:73:8F:9C:AA:04:C7:75)rootpuppet-mas

35、ter # puppet cert -s haproxy-UNIXHOT 打造最专业的运维门户15自动化运维客户端测试:验证通过后,客户端获取 puppet-master 配置并执行:rootapp-node3 # puppetd -test -server puppet-3.3.3 客户端自动验证在管理端创建自动验证的域名即可,如果运行没有问题,就可以让 puppet-master 运行在模式了。rootpuppet-master # puppet master -daemonize管理端:rootpuppet-master # cd /etc/puppet/rootpuppet-maste

36、r puppet# echo "*" >> autosign.conf客户端:rootapp-node1 # puppetd -test -server puppet-如果验证没有问题,可以将客户端运行在:rootapp-node1 13:22:35 # puppet agent3.4 Puppet Dashboard 安装由于本文使用系统自带的 ruby,1.8.5 在安装 Puppet Dashboard 时会有版本的问题,所以使用 rubyEnterprise 源码安装。3.4.1 相关包安装rootpuppet-master src# tar zxvf

37、ruby-enterprise-1.8.7-2011.12.tar.gzrootpuppet-master src# cd ruby-enterprise-1.8.7-2011.12rootpuppet-master ruby-enterprise-1.8.7-2011.12# ./installer默认会安装在/opt/ruby-enterprise-1.8.7-2011.12 目录下,请加入系统 PATH 变量中。PATH=$PATH:$HOME/bin:/opt/ruby-enterprise-1.8.7-2011.12/binrootpuppet-master # source .ba

38、sh_profileUNIXHOT 打造最专业的运维门户16自动化运维为 gem 添加源删除官方源,因为官方源被的所拦截了。添加淘宝的镜像站点。rootpuppet-master # gem source -rremoved from sourcesrootpuppet-master # gem source -aadded to sources安装依赖的包:rootpuppet-master # gem install ruby-mysqlrootpuppet-master # gem install rakerootpuppet-master # gem install railsroot

39、puppet-master # yum install -y mysql mysql-devel mysql-server(注意必须安装 mysql-devel)rootpuppet-master # /etc/init.d/mysqld startrootpuppet-master # chkconfig mysqld onrootpuppet-master # mysqladmin -u root password unixhotrootpuppet-master # cd /usr/local/srcrootpuppet-master src# wgetrootpuppet-master

40、 src# tar zxvf puppet-dashboard-1.2.7.tar.gzrootpuppet-master src# mv puppet-dashboard-1.2.7 /opt/puppet-dashboard3.4.2 配置 Dashboard 数据库修改Dashboard 数据库配置,并创建数据库。rootpuppet-master puppet-dashboard# cp config/database.yml.example config/database.ymlproduction:database: dashboardusername: puppetUNIXHOT

41、 打造最专业的运维门户17自动化运维password: puppetencoding: utf8adapter: mysql创建数据库mysql> create database puppet default charset utf8;mysql> grant all on puppet.* to puppetlocalhost identified by 'puppet'rootpuppet 05:38:01 tmp# ln -s /var/lysql/mysql.sock /tmp/mysql.sockrootpuppet-master # cd /opt/pu

42、ppet-dashboard/注意 rake 命令需要在/opt/puppet-dashboard/下运行rootpuppet-master puppet-dashboard# rake RAILS_ENV=production db:createrootpuppet-master puppet-dashboard# rake RAILS_ENV=production db:migrate启动Dashboard:rootpuppet-master # /opt/puppet-dashboard/script/server -e production -dUNIXHOT 打造最专业的运维门户18

43、自动化运维导入已的 reportrootpuppet-master puppet-dashboard#/opt/ruby-enterprise-1.8.7-2011.12/bin/rake RAILS_ENV=production reports:import3.5 puppet 使用请参考rootpuppet-master # cd /etc/puppet/rootpuppet-master puppet# tree|- auth.conf|- autosign.conf|- fileserver.conf|- logrotate|- manifests|- site.pp|- module

44、s|- init|- files|- config.sh|- resolv.conf|- snmpd.conf|- unixhot.repo|- manifests|- init.pp#,初始化|- templates|- puppet.conf- tagmail.conf6 directories, 12 filesrootpuppet-master puppet# cat modules/init/manifests/init.pp#initUNIXHOT 打造最专业的运维门户19自动化运维class init file "/etc/yum.repos.d/womai.repo&

45、quot;:source => "puppet:/$fileserver/init/unixhot.repo"file "/etc/resolv.conf":source => "puppet:/$fileserver/init/resolv.conf"file "/opt/shell/config.sh":source => "puppet:/$fileserver/init/config.sh"file "/etc/snmp/snmpd.conf":so

46、urce => "puppet:/$fileserver/init/snmpd.conf"附录一 RHELinux 5.5 x86_64自动安装脚本#Kickstart Configurator by Jason Zhao#platform=x86, AMD64, or Intel EM64Tkey -skip#Systemlanguagelang en_US#Language modules to installlangsupport zh_HK zh_CN zh_TW -default=en_US#System keyboardkeyboard us#System

47、 mousemouse#Sytem timezoneUNIXHOT 打造最专业的运维门户20自动化运维timezone Asia/Shanghai#Root passwordrootpw -iscrypted $1$YKqZy097$/kruS789206N1fbyEwKuu1#Reboot after installation#reboot#Use text mode installtext#Install OS instead of upgradeinstall#Use NFS installation Mediaurl -url=ftp:/*。*。*。*/pub/rhel5u5_x86_

48、64#System bootloader configurationbootloader -location=mbr#Clear the Master Boot Recordzerombr yes#Partition clearing informationclearpart -all -initlabel#Disk partitioning informationpart /boot -fstype ext3 -size 100 -ondisk sdapart swap -size 8192 -ondisk sdapart /var -fstype ext3 -size 2048 -ondi

49、sk sdapart / -fstype ext3 -size 1 -grow -ondisk sda#System authorization infomationauth-useshadow-enablemd5#Network informationnetwork-bootproto=dhcp-device=eth0-nameserver10,0-hostname=#Firewall configurationfirewall -disabled#SELinux configurationUNIXHOT 打造最专业的运维门户21自动化运维se

50、linux -disabled#Do not configure XWindowsskipx#Package install information%packages -resolvedeps admin-tools base-support core development-libs development-tools dialup legacy-software-development system-tools editors text-internetlrzszncurses-developenssl-develzlib-develmxmysqllockdevsysstatiptrafn

51、tpe2fsprogs-develkeyutils-libs-develkrb5-devellibselinux-develUNIXHOT 打造最专业的运维门户22自动化运维libsepol-devel%post#/bin/sed -i 's/#Protocol 2,1/Protocol 2/' /etc/ssh/sshd_config/bin/sed-i 's/ca:ctrlael:/#ca:ctrlael:/' /etc/inittab/sbin/chkconfig -level 3 diskdump off/sbin/chkconfig -level 3

52、dc_server off/sbin/chkconfig -level 3 nscd off/sbin/chkconfig -level 3 netfs off/sbin/chkconfig -level 3 psacct off/sbin/chkconfig -level 3 mdmpd off/sbin/chkconfig -level 3 netdump off/sbin/chkconfig -level 3ahead off/sbin/chkconfig -level 3 wpa_supplicant off/sbin/chkconfig -level 3 mdmonitor off/sbin/chkconfig -level 3 microcode_ctl off/sbin/chkconfig -level 3 xfs off/sbin/chkconfig -level 3 lvm2-monitor off/sbin/chkconfig -level 3 iptables off/sbin/chkconfig -level 3 nfs off/sbin/

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论