您的位置:首页 > 运维架构 > Linux

CentOS-6半自动化安装

2017-09-24 21:49 393 查看
kickstart 文件 介绍

介绍
kickstart文件的格式
命令段

程序包段

脚本段

必备命令

可选命令

kickstart文件的创建

创建 kickstart 文件并通过网络ftp半自动化安装系统

创建kickstart 文件的方式

下面通过网络安装系统
走网络安装
这是手动安装

本文介绍通过 kickstart 文件、yum源、走网络 来 实现半自动化安装系统

kickstart 文件 介绍

(自动化安装的前提)

文件路径

/root/anaconda-ks.cfg

可以通过

指明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


来调用

介绍

[root@CentOS-6-T ~]# cat anaconda-ks.cfg


# Kickstart file automatically generated by anaconda.
#version=DEVEL
install                             #安装
cdrom                               #使用光盘cdrom
lang en_US.UTF-8                    #设置语言
keyboard us                         #键盘设置
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw  --iscrypted $6$MVXDAdOomQoUJiTG    #root口令 $26CnFurWPhM6YBPza7YAkYDwYR9tlay98SNxH9tj9GTCZETH4MkbfG92KZwTfMtSDXAYHbTusW4EJ1hYo55J..
firewall --service=ssh              #防火墙
authconfig --enableshadow --passalgo=sha512
selinux --enforcing                 #默认selinux
timezone Asia/Shanghai              #设置时区
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" --password=$6$.4qH2dRhiQS2f32x$5YUFb9Ttb.BhF.4npUC1QebRrzmaulo4mnpEdsJF2WHs5NqouIdQzeH5sxD6UBIuHTmbmM4q12tJosE/vxad..
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --all --drives=sda    # 默认清除分区
#clearpart --none --drives=sda   # 默认清除分区

#part /boot --fstype=ext4 --size=500
#part pv.008002 --grow --size=1

#volgroup vg_centos6t --pesize=4096 pv.008002       #配置逻辑卷
#logvol /home --fstype=ext4 --name=lv_home --vgname=vg_centos6t --grow --size=100
#logvol / --fstype=ext4 --name=lv_root --vgname=vg_centos6t --grow --size=1024 --maxsize=51200
#logvol swap --name=lv_swap --vgname=vg_centos6t --grow --size=1984 --maxsize=1984

repo --name="CentOS"  --baseurl=cdrom:sr0 --cost=100

#程序包段
#带@的是包组,不带的是普通包,可实现定制化
#packagesname  #不装包组中的某些选项

%packages

@core
@server-policy
@workstation-policy
vim
autofs
%end


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: 时区

可选命令

nstall OR upgrade

text: 文本安装界面

network

firewall

selinux

halt

poweroff

reboot

repo

user :安装完成后为系统创建新用户

url: 指明安装源

key –skip 跳过安装号码, 适用于rhel

kickstart文件的创建

创建kickstart 文件的方式

直接手动编辑

依据某模板修改

可使用创建工具:system-config-kickstart

依据某模板修改并生成新配置

/root/anaconda-ks.cfg

检查ks 文件的语法错误:ksvalidator

ksvalidator /PATH/TO/KICKSTART_FILE

创建 kickstart 文件,并通过网络(ftp)半自动化安装系统

创建 kickstart 是基于图形界面,下面我们将介绍如何生成 kickstart 文件

创建kickstart 文件的方式

直接手动编辑

依据某模板修改

可使用创建工具:system-config-kickstart

依据某模板修改并生成新配置

/root/anaconda-ks.cfg

检查ks 文件的语法错误:ksvalidator

ksvalidator /PATH/TO/KICKSTART_FILE

步骤:

yum install -y system-config-kickstart

#安装软件

system-config-kickstart

#运行程序,打开图形界面



基于网络就填自己网络的资源路径



没有的话就是使用默认配置



配置你想要的IP





保存脚本,等会修改

而这个保存下来的文件就是自动化安装的基础。

[root@CentOS-6-T ~]# ls
anaconda-ks.cfg  Desktop  Documents  Downloads  install.log  install.log.syslog  ks.cfg  Music  Pictures  Public  Templates  Videos  VMwareall
[root@CentOS-6-T ~]# cat ks.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://172.18.0.1/centos/6/"
# Root password
rootpw --iscrypted $1$SGKXv08B$0jacHHjl7WQFR4NMIMPXX1
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
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/Hong_Kong
# Network information
network  --bootproto=static --device=eth0 --ip=172.18.13.66 --netmask=255.255.0.0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part swap --fstype="swap" --size=2048
part / --fstype="ext4" --size=20000

%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
useradd wang
echo 888888|passwd --srdin wang
%end

%packages
@base

%end


改为: 有的就不改,没有的就添加

# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part swap --fstype="swap" --size=2048
part / --fstype="ext4" --size=20000

%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
useradd wang
echo 888888|passwd --srdin wang
%end

%packages
@base
@workstation-policy
@server-policy
autofs
vim
%end


]#alias yy='yum -y install'
]#yum -y vsftp
]#service vsftpd status
]#service vsftpd start
]#cd /var/ftp/pub
#放在这里是可以给ftp访问的
pub]# cp /root/ks.cfg .
iptables -L
#查看防火墙,如果不行就停掉防火墙。
#chkconfig iptables off
#service iptables stop
#如果关掉可以从网页查看能不能访问了,网页中输入ftp://172.18.13.65
#可以查看/pub/ks.cfg 下面的文件,即能通过网络安装。


[title2]下面通过网络安装系统[/title2]

新建一个虚拟机,过程不多说,网上自行搜索。

注:启动是用光盘启动,但是安装是通过网络ks.cfg文件安装,即引导计算机。



方法一:光盘引导界面 → Esc键 → boot: linux ks=ftp://172.18.13.65/pub/ks.cfg
方法二:光盘引导界面 → tab键 → ks=ftp://172.18.13.65/pub/ks.cfg

#注:ks.cfg的权限要是能给所有人读取的。
#[root@CentOS-6-T pub]# ll ks.cfg
#-rw-r--r--. 1 root root 1298 Sep 18 21:38 ks.cfg

#注:
#因为我们是走网络安装的,所有需要网卡有IP地址,如果没弹出对话框就说明拿到地址了
#如果没有拿到就需要手动配置,只需要配置和ftp服务在同一网段的地址就行了。
#或者直接把网卡改成桥接模式。
#下面就可以通过我们的网络的来安装,直至安装完成




我们可以通过 ks.cfg 文件 中的一些信息判断是否安装完成。
Last login: Mon Sep 18 22:17:53 2017
[root@localhost ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
.
.略
.
wang:x:500:500::/home/wang:/bin/bash

#wang用户是我们创建的,所以说明安装完成。

**半自动化完成!**


走网络安装

这是手动安装

光盘引导,在光盘安装引导界面按Esc

看到

boot: linux askMethod

安装向导界面多一个界面,询问安装源(yum源)



走网络需要配置ip,DHCP临时配置ip → ctrl+alt+f2 → 信息能看到ip

可以用其他机器ping一下



后面正常安装,略。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: