免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 55465 | 回复: 101
打印 上一主题 下一主题

有奖专家座谈——自动化运维案例分享讨论之二(特邀某大型网游运维总监“king_819”) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-13 10:17 |只看该作者 |倒序浏览

获奖名单已公布,详情请看:http://bbs.chinaunix.net/thread-3657350-1-1.html

随着互联网的不断发展,互联网企业的IT架构不断扩展,服务器数量也是越来越多,这样对运维人员的要求也是越来越高了,不可能再通过手动一台一台的安装配置服务器了,我们要从“零售商”变成“批发商”了,特别是网络游戏行业,从事网络游戏运维的兄弟们应该深有感触,往往在开新服的时候需要大批量的布署新的服务器,时间紧迫而且量大,装系统、初始化、游戏服务端配置,枯燥而又乏味,有时还容易出错,为了解放我们的双手,让我们的工作轻松又不容易出错,所以要实现自动化,今天我们就一起来讨论下自动化运维的相关话题,第一期为初始化相关的讨论,第二期为自动化及后期脚本分享。

第一期讨论话题:批量安装 批量优化 批量布署
链接地址:http://bbs.chinaunix.net/thread-3619218-1-1.html

本期讨论话题:

1、更新自动化
2、备份自动化
3、监控自动化
4、自动化脚本分享

活动要求:

针对以上话题讨论并分享经验和实际运行中的案例及解决方案。

活动时间:
2011年12月13日——2011年12月30日

活动有奖:微软(Microsoft)键鼠套装 无线光学套装800 黑色 3个


论坛徽章:
0
2 [报告]
发表于 2011-12-13 10:20 |只看该作者
欢迎大家一起讨论分享!!

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
3 [报告]
发表于 2011-12-13 10:33 |只看该作者
支持下

论坛徽章:
0
4 [报告]
发表于 2011-12-13 10:36 |只看该作者
chenyx的速度很快咧,分享下你的经验撒

论坛徽章:
1
天秤座
日期:2014-11-05 16:54:55
5 [报告]
发表于 2011-12-13 10:40 |只看该作者
来学习下,,,

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
6 [报告]
发表于 2011-12-13 10:40 |只看该作者
转帖一个,A few things you might not know about RHEL-6.1+ yum,源地址:http://illiterat.livejournal.com/8221.html

Time to look at a few features of yum in RHEL-6.1 now that it's released
Search is more userfriendly
As we maintain yum we are always looking for the "minor" changes that can make a big difference to the user, and this is probably one of the biggest minor changes. As of late RHEL-5 and RHEL-6.0 "yum search" was great for finding obscure things that you knew something about but with 6.1 we've hopefully made it useful for finding the "everyday" packages you can't remember the exact name of. We did this by excluding a lot of the "extra" hits, when you get a large search result. For instance "yum search kvm manager" is pretty useless in RHEL-6.0, but in RHEL-6.1 you should find what you want very quickly.

Example commands:
yum search kvm manager
yum search python url
The updateinfo command
The "yum-security" or "yum-plugin-security" package has been around since early RHEL-5, but the RHEL-6.1 update has introduced the "updateinfo" command to make things a little easier to use, and you can now easily view installed security errata (to more easily make sure you are secure). We've also added a few new pieces of data to the RHEL updateinfo data. Probably the most significant is that as well as errata being marked "security" or not they are now tagged with their "severity". So you can automatically apply only "critical" security updates, for example.

Example commands:
yum updateinfo list security all
yum update-minimal --sec-severity=critical
The versionlock command
As with the previous point we've had "yum-plugin-version" for a long time, but now we've made it easier to use and put all it's functions under a single "versionlock" sub-command. You can now also "exclude" specific versions you don't want, instead of locking to known good specific ones you had tested.

Example commands:
# Lock to the version of yum currently installed.
yum versionlock add yum
# Opposite, disallow versions of yum currently available:
yum versionlock exclude yum

yum versionlock list
yum versionlock delete yum\*
yum versionlock clear

# This will show how many "excluded" packages are in each repo.
yum repolist -x .
Manage your own .repo variables
This is actually available in RHEL-6.0, but given that almost nobody knows about it I thought I'd share it here. You can put files in "/etc/yum/vars" and then use the names of those files are variables in any yum configuration, just like $basearch or $releasever. There is also a special $uuid variable, so you can track individual machines if you want to.

yum has it's own DB
Again, this something that was there in RHEL-6.0 but has improved (and is likely to improve more over time). The most noticeable addition is that we now store the "installed_by" and "changed_by" attributes, this could be worked out from "yum history" before, but now it's easily available directly from the installed package.

Example commands:
yumdb
yumdb info yum
yumdb set installonly keep kernel-2.6.32-71.7.1.el6
yumdb sync
Additional data in "yum history"
Again, this something that was there in RHEL-6.0 but has improved (and is likely to improve more over time). The most noticeable additions are that we now store the command line and we store a "transaction file" that you can use on other machines.

Example commands:
yum history
yum history pkgs yum
yum history summary

yum history undo last

yum history addon-info 1    config-main
yum history addon-info last saved_tx
"yum install" is now fully kickstart compatible
As of RHEL-6.0 there was one thing you could do in a kickstart package list that you couldn't do in "yum install" and that was to "remove" packages with "-package". As of the RHEL-6.1 yum you can do that, and we also added that functionality to upgrade/downgrade/remove. Apart from anything else, this should make it very easy to turn the kickstart package list into "yum shell" files (which can even be run in kickstart's %post).

Example commands:
yum install 'config(postfix) >= 2.7.0'
yum install MTA
yum install '/usr/kerberos/sbin/*'
yum -- install @books -javanotes
Easier to change yum configuration
We tended to get a lot of feature requests for a plugin to add a command line option so the user could change a single yum.conf variable, and we had to evaluate those requests for general distribution based on how much we thought all users would want/need them. With the RHEL-6.1 yum we created the --setopt so that any option can be changed easily, without having to create a specific bit of code. There were also some updates to the yum-config-manager command.

Example commands:
yum --setopt=alwaysprompt=false upgrade yum

yum-config-manager
yum-config-manager --enable myrepo
yum-config-manager --add-repo https://example.com/myrepo.repo
Working towards managing 10 machines easily
yum is the best way to manage a single machine, but it isn't quite as good at managing 10 identical machines. While the RHEL-6.1 yum still isn't great at this, we've made a few improvements that should help significantly. The biggest is probably the "load-ts" command, and the infrastructure around it, which allows you to easily create a transaction on one machine, test it, and then "deploy" it to a number of other machines. This is done with checking on the yum side that the machines started from the same place (via. rpmdb versions), so that you know you are doing the same operation.

Also worth noting is that we have added a plugin hook to the "package verify" operation, allowing things like "puppet" to hook into the verification process. A prototype of what that should allow those kinds of tools to do was written by Seth Vidal here.

Example commands:
# Find the current rpmdb version for this machine (available in RHEL-6.0)
yum version nogroups

# Completely re-image a machine, or dump it's "package image"
yum-debug-dump
yum-debug-restore
    --install-latest
    --ignore-arch
    --filter-types=install,remove,update,downgrade

# This is the easiest way to get a transaction file without modifying the rpmdb
echo | yum update blah
ls ${TMPDIR:-/tmp}/yum_save_tx-* | sort | tail -1

# You can now load a transaction and/or see the previous transaction from the history
yum load-ts /tmp/yum_save_tx-2011-01-17-01-00ToIFXK.yumtx
yum -q history addon-info last saved_tx > my-yum-saved-tx.yumtx

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
7 [报告]
发表于 2011-12-13 10:42 |只看该作者
本帖最后由 chenyx 于 2011-12-13 10:43 编辑

自动化部署,主要是ks.cfg的部分.下面贴一个cactiez的ks.cfg的内容,转帖自cactiez中文版
#CactiEZ v10.1
install
text
cdrom
mediacheck
lang en_US.UTF-8
keyboard us
rootpw  CactiEZ
firewall --service=ssh --service=snmp --service=http
authconfig --enableshadow --passalgo=sha512 --enablefingerprint
selinux --disabled
timezone Asia/Shanghai
network --bootproto=static --ip=192.168.0.64 --netmask=255.255.255.0 --gateway=192.168.0.1 --nameserver 8.8.8.8 --hostname=CactiEZ.local --noipv6 --onboot=yes
bootloader --location=mbr

zerombr yes
clearpart --all --initlabel

part /boot --fstype=ext4 --size=200
part pv.cZWdAb-3EW9-0foh-Bl0a-To6S-TJez-7moyho --grow --size=200

volgroup vg_cactiezv10 --pesize=4096 pv.cZWdAb-3EW9-0foh-Bl0a-To6S-TJez-7moyho
logvol / --fstype=ext4 --name=LogVol00 --vgname=vg_cactiezv10 --grow --size=8192
logvol swap --name=LogVol01 --vgname=vg_cactiezv10 --size=1024

repo --name="CactiEZ"  --baseurl=file:///mnt/source --cost=100

%packages --nobase --excludedocs
@core
@server-policy
man
file
vim-enhanced
openssh-clients
lftp
ftp
wget
curl
elinks
net-snmp-utils
net-snmp
httpd
php
mysql-server
php-mysql
php-gd
expect
ntp
rsyslog-mysql
pango
system-config-network-tui

%post --nochroot
mkdir -p /mnt/sysimage/tmp/cactiez >> /tmp/ins.log 2>&1
cp /mnt/source/Packages/cactiez-x86_64.tgz /mnt/sysimage/tmp/cactiez >> /tmp/ins.log 2>&1

%post
cd /tmp/cactiez >> /tmp/ins.log 2>&1
tar zxvf cactiez-x86_64.tgz >> /tmp/ins.log 2>&1

cp -rf /tmp/cactiez/var/www/html/* /var/www/html >> /tmp/ins.log 2>&1
cp -rf /tmp/cactiez/usr/* /usr >> /tmp/ins.log 2>&1
cp -rf /tmp/cactiez/etc/* /etc >> /tmp/ins.log 2>&1

service mysqld start >> /tmp/ins.log 2>&1
/usr/bin/mysqladmin --user=root create cacti >> /tmp/ins.log 2>&1
mysql -e "GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser'" >> /tmp/ins.log 2>&1

mysql cacti < /var/www/html/cactiez.sql
service mysqld stop >> /tmp/ins.log 2>&1

chmod -R 777 /var/www/html/log/
chmod -R 7755 /var/www/html/rra/
chmod -R 755 /var/www/html/scripts/
chmod -R 755 /usr/local/spine/bin/
chmod -R 755 /usr/local/rrdtool/bin/
chown -R apache:apache /var/www/html/

echo '*/10 * * * * /usr/sbin/ntpdate 0.rhel.pool.ntp.org && /sbin/clock -w' > /tmp/crontab2.tmp
echo '*/5 * * * * php /var/www/html/poller.php > /dev/null 2>&1' >> /tmp/crontab2.tmp
crontab /tmp/crontab2.tmp
rm /tmp/crontab2.tmp

for service in httpd mysqld snmpd
do
  chkconfig --level 235 $service on
done

#rm -rf /tmp/*

%end

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
8 [报告]
发表于 2011-12-13 10:45 |只看该作者
上面的ks配置中,大家注意:
  • %post --nochroot
  • %post

这两个,相当于rescue模式,前面的相当于没进入chroot,后面的那个相当于进入chroot环境

论坛徽章:
0
9 [报告]
发表于 2011-12-13 10:47 |只看该作者
上面的ks配置中,大家注意:
  • %post --nochroot
  • %post

    这两个,相当于rescue模式,前面的相当于没进 ...
    chenyx 发表于 2011-12-13 10:45



  •     批量部署上期已经讨论过了,这期主要讨论批量更新、备份、监控方面的

    论坛徽章:
    381
    CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
    10 [报告]
    发表于 2011-12-13 10:47 |只看该作者
    转帖一个centos wiki上的文档:
    Anaconda 及 Kickstart 的提示与技巧 ,网址:http://wiki.centos.org/zh/TipsAndTricks/KickStart
    欲取得全部文档,请参阅 http://www.centos.org/docs/5/htm ... kstart2-howuse.html

    对准 %packages 部份

    当使用 %packages 来定义哪些组件需要安装时,有一些比较少记载的选项可供使用:

    --resolvedeps
    自动排除组件之间的依赖。这个选项在 Centos 5 已经被降级。组件之间的依赖现在每次都会自动被排除。
    --excludedocs
    安装时省略那些被标签为文档的文件(就是那些在执行 rpm -qld <packagename> 时列出来的文件)

    --nobase
    安装时省略 @Base。除非你知道自己在做什么,否则这样做行不通,因为可能会遗漏某些组件是安装后执行脚本时所需的
    --ignoremissing
    忽视不存在的组件及群组,而不要询问处理方法。这个选项在 Centos 5 已经被降级。组件之间的依赖现在每次都会自动被排除。
    为 CentOS 4 选择最少组件的样例:


    %packages --resolvedeps --excludedocs --nobase
    kudzu
    请留意这样做会遗漏一些基本的组件。rpm、yum、vim、dhcp-client 及键盘布局都不会存在。Kudzu 是必须的,因为没有它,安装程序将不能执行。

    为 CentOS 5 选择最少组件的样例:


    %packages --excludedocs --nobase
    @Core
    同样,这样做只会产生一个非常基本的系统,而大部份你遇期有的功能都不会存在。

    CentOS 4 上所指定的 --resolvedeps 已不必在 CentOS 5 中采用,因为较新的安装程序经常会解决依赖关系。

    分割磁盘

    若果你以一个未分割的磁盘、或虚拟机器上未分割的映像作为初始化点,请使用 --initlabel 或 clearpart 参数来确定磁盘标签会被初始化,否则 Anaconda 会交互地要求你确定创建磁盘标签。假设你需要清除 xvda 上的所有分区,并为未存在的磁盘标签进行初始化,请执行:


    clearpart --all --initlabel --drives=xvda
    在直正的文字模式执行 anaconda

    你很可能已经知道在你的 kickstart 档内加入 "text" 这一行会令 anaconda 采用 ncurses 界面,而不是 X11 界面。但其实还有另一个可能选择:就是在真正的文字模式中进行安装。只要将 kickstart 档内 "text" 这行以 "cmdline" 取代,anaconda 便会将整个安装过程在文字模式中进行。尤其是当采用 %packages --nobase 或执行复杂的 %post 脚本时,这样做会省下很多小时的侦错时间,因为你可以亲眼看见所有在安装时执行的脚本的输出。

    启用/停用 firstboot

    你们都认识 firstboot,那个在安装后帮助你设置系统的向导。你可以在 kickstart 档内的指命部份加入 "firstboot --enable" 或 "firstboot --disable" 来启用或停用它。

    各个终端機所显示的内容

    Alt-F1
    使用 text 或 cmdline 模式安装时的对话框
    Alt-F2
    指命壳的提示符号
    Alt-F3
    安装程序所输出的安装日志
    Alt-F4
    内核及其它程序所输出的系统日志
    Alt-F5
    其它信息
    Alt-F7
    使用图像界面安装时的对话框
    记录 %pre 及 %post

    当使用 %pre 或 %post 脚本时,你可以轻易地用 --log=/path/to/file 将输出记录在一个文件内


    %post --log=/root/my-post-log
    echo 'Hello, World!'
    下面是另一个同时记录输出并将它显示在划面上的方法:


    %post
    exec < /dev/tty3 > /dev/tty3
    chvt 3
    echo
    echo "################################"
    echo "# Running Post Configuration   #"
    echo "################################"
    (
    echo 'Hello, World!'
    ) 2>&1 | /usr/bin/tee /var/log/post_install.log
    chvt 1
    为防火墙设置多个信任的界面

    你可以在防火墙的选项中多次加入 --trust 选项来信任多个界面:


    # 启用 firewall,打开 ssh 端口,并信任 eth1 及 eth2
    firewall --enable --ssh --trust=eth1 --trust=eth2
    令 kickstart 使用指定的网络界面

    当你的系统拥有多过一个的网络界面时,anaconda 会询问你要 kickstart 使用哪一个。这个决定可以在开机通过加入 ksdevice 参数来设置。要以 eth0 来进行 kickstart,你只须在内核指命行内加入 ksdevice=eth0。

    第二个方法是指定 ksdevice=link。这样,anaconda 就会采用第一个获得有效连接的界面。

    第三个方法在 PXE 模式的安装下生效。你须要在 PXE 配置文件内加入 IPAPPEND 2 及指定 ksdevice=bootif。这样,anaconda 就会采用 PXE 引导时使用的界面(这未必等同第一个获得有效连接的界面)。

    在 kickstart 配置文件内,你亦需要用 network 语句来定义网络界面。假若你采用第二个或第三个方法,你便不能预知哪个界面会被使用。若果你在 network 语句中没有指定一个界面,anaconda 将会按照 network 语句内的定义来设置 kickstart 所使用的仪器。

    强迫 kickstart 询问网络设置

    由 CentOS 5 起,有一个未被记载的选项可以在安装过程启用网络设置的提示。在 network 语句内,为 --bootproto=  这个选项放入 query 关键字,如下:


    network --device=eth0 --bootproto=query
    这样一个对话框便会出现,询问有关 IP 地址及主机名称的设置。

    有用的现成 kickstart 档

    https://nazar.karan.org/cgit/bluecain/tree/ 你可以找到一堆现成的 kickstart 档。它们主要是用来测试 CentOS 的部署程序,但当然也适用于其它地方。

    Translation of revision 26
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP