運維自動化發展歷程及技術應用
安裝程序
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文件的格式
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