温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

运维自动化之系统安装

发布时间:2020-06-16 23:26:24 来源:网络 阅读:804 作者:何小帅 栏目:系统运维

实现方式

1 使用kickstart半自动化安装CentOS系统(CentOS6)

1.1 什么是kickstart安装?

安装系统时的应答文件,其中包括在典型安装过程中可能会问的所有问题的答案。

1.2 KICKSTART Configurator(配置器)

Kickstart Configurator 允许使用图形用户界面创建和修改 kickstart 文件,这样就需要记住文件的正确语法。

默认情况下,不会在 Red Hat Enterprise Linux 6 中安装 Kickstart Configurator。运行yum install system-config-kickstart,或使用图形化软件包管理器安装这个软件。

要启动 Kickstart Configurator,请将系统引导至图形环境,然后运行 system-config-kickstart,或在 GNOME 桌面上点击 应用程序 → 系统工具 → Kickstart,或者在 KDE 桌面上点击 开始应用程序启动器+应用程序 → 系统 → Kickstart。

创建 kickstart 文件时,可以在任何时候选择 File → Preview 查看当前的选择。

要修改现有的 kickstart 文件,选择 File → Open File,并选择文件。

1.2.1 基本配置

运维自动化之系统安装

1.2.2 安装方法

运维自动化之系统安装

1.2.3 引导装载程序选项

运维自动化之系统安装

1.2.4 分区信息

运维自动化之系统安装

1.2.5 网络配置

运维自动化之系统安装

1.2.6 认证

运维自动化之系统安装

1.2.7 防火墙和selinux配置

运维自动化之系统安装

1.2.8 显示配置

运维自动化之系统安装

1.2.9 软件包选择

运维自动化之系统安装

1.2.10 安装前脚本

运维自动化之系统安装

1.2.11 安装后脚本

运维自动化之系统安装

1.2.12 保存文件

运维自动化之系统安装
运维自动化之系统安装

1.2.13 在浏览器中打开kickstart文件

运维自动化之系统安装

1.3 新建一个虚拟机,使用刚才创建好的kickstart文件来完成安装
1.3.1 基本信息填写

运维自动化之系统安装

1.3.2 开机进入光盘引导界面后,按ESC键,然后填写kickstart文件的位置信息

运维自动化之系统安装
运维自动化之系统安装

1.3.3 开始使用kickstart应答文件进行自动安装

运维自动化之系统安装

2 基于CentOS8的PXE自动化安装CentOS系统

2.1 前提准备
selinux:关闭
firewalld:关闭
os:centos7
ip:192.168.7.81
2.2 安装必要软件包,并启动
[root@CentOS8 yum.repos.d]# dnf install dhcp-server tftp-server httpd syslinux-nonlinux -y

注:syslinux-nonlinux这个包,在6,7系统上叫syslinux
[root@CentOS8 ~]# systemctl enable --now httpd tftp dhcpd
2.3 准备yum源
[root@CentOS8 ~]# mkdir /var/www/html/centos/{6,7,8}/isos/x86_64/ -p
[root@CentOS8 ~]# mount /dev/sr0 /var/www/html/centos/8/isos/x86_64/
2.4 准备ks文件
[root@CentOS8 ~]# mkdir /var/www/html/ksdir
[root@CentOS8 ~]# cat /var/www/html/ksdir/ks8.cfg 
ignoredisk --only-use=sda
zerombr
text
reboot
clearpart --all --initlabel
selinux --disabled
firewall --disabled
url --url=http://192.168.7.81/centos/8/isos/x86_64/
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network  --bootproto=dhcp --device=ens160 --ipv6=auto --activate
network  --hostname=centos8-pxe
rootpw --iscrypted $6$nOPs5JTMlP4mhQeW$R/o62B6SXAh4RR.zrZ3U0X4xYX9/u5nSLrR/vqCB6kdO2XFfMk2a4yAgrHJQpXK/e4jzRb0jiLBv2nFMXaBjB/
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
user --name=hechunping --password=$6$oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv9pTogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="hechunping"
part / --fstype="xfs" --ondisk=sda --size=102400
part /data --fstype="xfs" --ondisk=sda --size=51200
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="ext4" --ondisk=sda --size=1024
%packages
@^minimal-environment
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
2.5 dhcp配置
[root@CentOS8 ~]# cp -p /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[root@CentOS8 ~]# grep -Ev "^#|^$" /etc/dhcp/dhcpd.conf 
option domain-name "example.org";
option domain-name-servers 180.76.76.76,223.5.5.5;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.7.0 netmask 255.255.255.0 {
    range 192.168.7.100 192.168.7.200;
    option routers 192.168.7.2;
    next-server 192.168.7.81;
    filename "pxelinux.0";
}
[root@CentOS8 ~]# systemctl restart dhcpd
2.6 准备tftp相关文件
[root@CentOS8 ~]# cp -p /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
[root@CentOS8 ~]# cp -p /var/www/html/centos/8/isos/x86_64/isolinux/{ldlinux.c32,libcom32.c32,libutil.c32} /var/lib/tftpboot/
[root@CentOS8 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg/
[root@CentOS8 ~]# cp -p /var/www/html/centos/8/isos/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@CentOS8 ~]# cp -p /var/www/html/centos/6/isos/x86_64/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/6/ 
[root@CentOS8 ~]# cp -p /var/www/html/centos/7/isos/x86_64/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/7/ 
[root@CentOS8 ~]# cp -p /var/www/html/centos/8/isos/x86_64/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/8/

[root@CentOS8 ~]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── 6
│   ├── initrd.img
│   └── vmlinuz
├── 7
│   ├── initrd.img
│   └── vmlinuz
├── 8
│   ├── initrd.img
│   └── vmlinuz
├── ldlinux.c32
├── libcom32.c32
├── libutil.c32
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
    └── default
2.7 创建安装菜单
[root@CentOS8 ~]# cat /var/lib/tftpboot/pxelinux.cfg/default 
default menu.c32
timeout 600

menu title CentOS Linux 

label linux8
  menu label Auto Install CentOS Linux ^8.0 Mini
  kernel 8/vmlinuz
  append initrd=8/initrd.img ks=http://192.168.7.81/ksdir/ks8.cfg

label linux7
  menu label Auto Install CentOS Linux ^7 Mini
  kernel 7/vmlinuz
  append initrd=7/initrd.img ks=http://192.168.7.81/ksdir/ks7.cfg

label linux6
  menu label Auto Install CentOS Linux ^6 Mini
  kernel 6/vmlinuz
  append initrd=6/initrd.img ks=http://192.168.7.81/ksdir/ks6.cfg

label manual
  menu label  ^Manual  Install CentOS Linux 8.0 
  kernel vmlinuz
  append initrd=initrd.img inst.repo=http://192.168.7.81/centos/8/isos/x86_64/

label local
  menu default
  menu label Boot from ^local drive
  localboot 0xffff

[root@CentOS8 ~]# systemctl restart tftp
2.8 开始自动安装centos8
2.8.1 系统硬件基本配置

运维自动化之系统安装

2.8.2 开机启动在菜单选择安装CentOS8,后面让它自己安装就行了

运维自动化之系统安装

6,7的安装基本类似,这里不再展开

3 CentOS7基于Cobbler自动化安装系统

3.1 基本包的安装和启动
[root@CentOS7-01 ~]#yum install cobbler dhcp tftp httpd -y
[root@CentOS7-01 ~]#systemctl enable --now cobblerd httpd tftp dhcpd
这里报dhcpd服务错误,是因为还没有配置相关文件,先不用管,继续往下做
3.2 cobbler环境检查
[root@CentOS7-01 ~]#cobbler check
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : ksvalidator was not found, install pykickstart
8 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.
3.2.1 cobbler报错解决
3.2.1.1 修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名
server: 192.168.7.71
3.2.1.2 修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址
next_server: 192.168.7.71
3.2.1.3 在/etc/xinetd.d/tftp中将'disable'更改为'no'
disable         = no
3.2.1.4 修改/etc/cobbler/settings文件,启用Cobbler的DHCP管理功能。并修改下面文件/etc/cobbler/dhcp.template
manage_dhcp: 1
3.3 下载启动菜单
[root@CentOS7-01 ~]#cobbler get-loaders
3.4 配置dhcp服务
subnet 192.168.7.0 netmask 255.255.255.0 {
     option routers             192.168.7.2;
     option domain-name-servers 8.8.8.8;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.7.100 192.168.7.254;
3.5 同步cobbler配置,并且重启dhcp服务
[root@CentOS7-01 ~]#cobbler sync
...中间省略信息...
*** TASK COMPLETE ***

[root@CentOS7-01 ~]#systemctl restart dhcpd

3.6 管理distro
[root@CentOS7-01 ~]#mount /dev/sr0 /mnt
[root@CentOS7-01 ~]#cobbler import --name=centos8-x86_64 --path=/mnt --arch=x86_64
3.7 准备kickstart文件
[root@CentOS7-01 ~]#cat /var/lib/cobbler/kickstarts/ks8.cfg
#version=RHEL8 
ignoredisk --only-use=sda
zerombr
text
reboot
# Partition clearing information
clearpart --all --initlabel
selinux --disabled
firewall --disabled

# Use graphical install
url --url=$tree 
# Use CDROM installation media
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=ens160 --ipv6=auto --activate
network  --hostname=centos8
# Root password
rootpw --iscrypted $6$nOPs5JTMlP4mhQeW$R/o62B6SXAh4RR.zrZ3U0X4xYX9/u5nSLrR/vqCB6kdO2XFfMk2a4yAgrHJQpXK/e4jzRb0jiLBv2nFMXaBjB/
# Run the Setup Agent on first boot
firstboot --enable
# Do not configure the X Window System
skipx
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
user --name=hechunping --password=$6$oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv9pTogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="hechunping"
# Disk partitioning information
part / --fstype="xfs" --ondisk=sda --size=102400
part /data --fstype="xfs" --ondisk=sda --size=51200
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="ext4" --ondisk=sda --size=1024

%packages
@^minimal-environment
kexec-tools
%end

%addon com_redhat_kdump --enable --reserve-mb='auto'
%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
3.8 管理profile
[root@CentOS7-01 ~]#cobbler profile add --name=centos8 --distro=centos8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks8.cfg
3.9 查看profiles
[root@CentOS7-01 ~]#cobbler profile list
3.10 查看引导文件
[root@CentOS7-01 ~]#cat /var/lib/tftpboot/pxelinux.cfg/default
3.11 开始自动安装centos8
3.11.1 系统硬件基本配置

运维自动化之系统安装

3.11.2 开机启动,在菜单中选择安装cenots8,后面让它自己安装就行了。

运维自动化之系统安装

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI