运维自动化发展历程及技术应用

安装程序

CentOS系统安装
系统启动流程:
  bootloader-->kernel(initramfs)-->rootfs-->/sbin/init anaconda: 系统安装程序
   gui:图形窗口
   tui: 基于图形库curses的文本窗口

安装程序启动过程

MBR:isolinux/boot.cat
stage2: isolinux/isolinux.bin
配置文件:isolinux/isolinux.cfg
  每个对应的菜单选项:
    加载内核:isolinuz/vmlinuz
    向内核传递参数:append initrd=initrd.img ...
装载根文件系统,并启动anaconda
  默认启动GUI接口
  若是显式指定使用TUI接口:向内核传递text参数即可
    (1)按tab键,在后面增加text
    (2)按ESC键:boot: linux text

anaconda工作过程

Anaconda安装系统分成三个阶段:
1、安装前配置阶段
  安装过程使用的语言
   键盘类型
  安装目标存储设备
    Basic Storage:本地磁盘
    特殊设备:iSCSI
  设定主机名   配置网络接口   时区   管理员密码   设定分区方式及MBR的安装位置   创建一个普通用户   选定要安装的程序包
2、安装阶段:
  在目标磁盘创建分区,执行格式化操作等   将选定的程序包安装至目标位置   安装bootloader和initramfs
3、图形模式首次启动
  iptables   selinux   core dump

指定安装源

centos6:     DVD drive repo=cdrom :device     Hard Drive repo=hd:device/path     HTTP Server repo=http://host/path     HTTPS Server repo=https://host/path     FTP Server repo=ftp://username:password@ host/path     NFS Server repo=nfs:server:/path     ISO images on an NFS Server repo=nfsiso:server:/path
centos7:     Any CD/DVD drive inst.repo=cdrom     Hard Drive inst.repo=hd:device:/path     HTTP Server inst.repo=http://host/path     HTTPS Server inst.repo=https://host/path     FTP Server inst.repo=ftp://username:password@ host/path     NFS Server inst.repo=nfs:[options:]server:/path

系统安装

启动安装过程一般应位于引导设备;后续的anaconda及其安装用到的程序包等可来自下面几种方式:
  本地光盘
  本地硬盘
  NFS
  URL:
    ftp server: yum repository
    http server: yum repostory
如果想手动指定安装源:   boot: linux askmethod
  boot: linux ks=http://172.20.7.52/ks6.cfg
anaconda的配置方式:   (1) 交互式配置方式   (2) 通过读取事先给定的配置文件自动完成配置
      按特定语法给出的配置选项
        kickstart文件
安装boot引导选项:boot
text: 文本安装方式
askmethod: 手动指定使用的安装方法
与网络相关的引导选项:
  ip=IPADDR   netmask=MASK   gateway=GW   dns=DNS_SERVER_IP   ifname=NAME:MAC_ADDR
与远程访问功能相关的引导选项:
  vnc   vncpassword='PASSWORD'
指明kickstart文件的位置: ks=
    DVD drive: ks=cdrom:/PATH/TO/KICKSTART_FILE     Hard drive: ks=hd:device:/directory/KICKSTART_FILE     HTTP server: ks=http://host:port/path/to/KICKSTART_FILE     FTP server: ks=ftp://host:port/path/to/KICKSTART_FILE     HTTPS server: ks=https://host:port/path/to/KICKSTART_FILE     NFS server:ks=nfs:host:/path/to/KICKSTART_FILE
启动紧急救援模式:
  rescue

kickstart文件的格式

命令段:指明各种安装前配置,如键盘类型等
程序包段:指明要安装的程序包组或程序包,不安装的程序包等
    %packages     @group_name     package     -package     %end
脚本段:
    %pre: 安装前脚本         运行环境:运行于安装介质上的微型Linux环境     %post: 安装后脚本         运行环境:安装完成的系统
命令段中的命令:
  必备命令
      authconfig: 认证方式配置           authconfig --useshadow --passalgo=sha512       bootloader:bootloader的安装位置及相关配置           bootloader --location=mbr --driveorder=sda –               append="crashkernel=auto rhgb quiet"
      keyboard: 设定键盘类型       lang: 语言类型       part: 创建分区       rootpw: 指明root的密码       timezone: 时区
可选命令:
    install OR upgrade     text: 文本安装界面     network     firewall     selinux     halt     poweroff     reboot     repo     user:安装完成后为系统创建新用户     url: 指明安装源     key –skip 跳过安装号码,适用于rhel版本

kickstart文件创建

创建kickstart文件的方式
  直接手动编辑
     依据某模板修改
   可使用创建工具:system-config-kickstart
     默认好像是没有需要安装:yum -y install system-config-kickstart
     依据某模板修改并生成新配置
        /root/anaconda-ks.cfg
检查ks文件的语法错误:ksvalidator
   ksvalidator /PATH/TO/KICKSTART_FILE
   [root@ansible ~]#ksvalidator anaconda-ks.cfg

ks模版文件:
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url=$tree
# Root password
rootpw --iscrypted $1$2gpkF.e/$CezTOjwptBtOlJo5cOSKR1
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel 
# Disk partitioning information
part /boot --fstype="ext4" --size=500
part / --fstype="ext4" --size=50000
part swap --fstype="swap" --size=4096
part /data --fstype="ext4" --size=50000

%packages
@base
autofs
@compat-libraries
@development
%end

%post
rm -rf   /etc/yum.repos.d/*
cat > /etc/yum.repos.d/base.repo << EOF
[base]
name=base
baseurl=file:///misc/cd
gpgcheck=0
EOF

echo 'PS1="\[\e[1;42m\][\[\e[31;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m]\\$"' > /etc/profile.d/env.sh
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config
ed -i "/# Source/i\alias cdnet='cd /etc/sysconfig/network-scripts'" /root/.bashrc
sed -i "/# Source/i\ alias viet='vim /etc/sysconfig/network-scripts/ifcfg-eth0'" /root/.bashrc
{ . /etc/profile.d/env.sh;service sshd restart; . /root/.bashrc;  }
%end