实验自动化安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验自动化安装相关的知识,希望对你有一定的参考价值。
让电脑自动完成安装,我们要把分区、root口令等告诉电脑,我们用一个(应答文件的文本文件)将设置写入其中,让安装向导找到该应答文件即可自动安装。
准备素材:centos7、centos7mini(最小化安装版本)
##### A、[[email protected] ~]# ls
anaconda-ks.cfg
此文件anaconda-ks.cfg为记录了我们是如何安装系统的。
##### B、将网卡配置文件的 onboot 改为 yes
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=bd070b36-c892-43b7-a8c8-d179b44c1d3c
DEVICE=ens33
ONBOOT=yes
~
[[email protected] ~]# systemctl restart network
##### C、主机 centos7 ssh上远程的 centos7mini
[[email protected] ~]# ssh 192.168.58.133
[email protected]‘s password:
Last login: Wed Jan 30 12:49:40 2019 from 192.168.58.1
[[email protected] ~]# scp anaconda-ks.cfg 192.168.58.254:/data
[email protected]‘s password:
anaconda-ks.cfg 100% 1421 120.3KB/s 00:00
[[email protected] ~]# exit
logout
Connection to 192.168.58.133 closed.
此处是将 anaconda-ks.cfg 文件拷贝到主机上
##### D、我们可以把 anaconda-ks.cf 文件当做最小化安装的模板。如下:
[[email protected] ~]# cd /data
[[email protected] data]# ls
anaconda-ks.cfg hallo.sh magedu.pubkey
[[email protected] data]# vim anaconda-ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts=‘us‘
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=ens33 --onboot=off --ipv6=auto --no-activate
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$V2eP8pESlfKIToP8$NVcSm0geeSV4X1cd1lccrs9FAdK1rbj6EczSviVmoz75Znj5GaI.qY7jA0H1dmbh.hsI2ZIHtaR3Ko0/Xku9B1
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
"anaconda-ks.cfg" 48L, 1421C 1,1 Top
##### E、此时我们要先安装图像界面的文件,如下:
[[email protected] data]# yum install system-config-kickstart
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00
epel | 4.7 kB 00:00
(1/2): epel/updateinfo | 954 kB 00:00
(2/2): epel/primary_db | 6.6 MB 00:01
Dependency Installed:
gnome-python2.x86_64 0:2.28.1-14.el7
gnome-python2-canvas.x86_64 0:2.28.1-14.el7
libart_lgpl.x86_64 0:2.3.21-10.el7
libgnomecanvas.x86_64 0:2.30.3-8.el7
rarian.x86_64 0:0.8.1-11.el7
rarian-compat.x86_64 0:0.8.1-11.el7
system-config-date.noarch 0:1.10.6-3.el7.centos
system-config-date-docs.noarch 0:1.0.11-4.el7
system-config-keyboard.noarch 0:1.4.0-5.el7
system-config-keyboard-base.noarch 0:1.4.0-5.el7
system-config-language.noarch 0:1.4.0-9.el7
usermode-gtk.x86_64 0:1.111-5.el7
Complete!
##### F、我们可以利用网络,搭建一个网络服务器,按照httpd的做法,
[[email protected] ~]# rpm -ql httpd
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/var/www
/var/www/cgi-bin
/var/www/html
将httpd服务启动起来:
[[email protected] ~]# systemctl start httpd
[[email protected] ~]# cd /var/www/html
[[email protected] html]# mkdir centos/{6,7}/os/x86_64/ -pv
[[email protected] html]# tree
.
├── app
│?? ├── 6
│?? │?? └── x86_64
│?? └── 7
│?? └── x86_64
└── centos
├── 6
│?? └── os
│?? └── x86_64
└── 7
└── os
└── x86_64
12 directories, 0 files
[[email protected] html]# mount /dev/sr0 centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
##### G、此时,我们可以去互联网访问主机了,如下:
http://192.168.58.254/centos/7/
Index of /centos/7
[ICO] Name Last modified Size Description
[PARENTDIR] Parent Directory -
[DIR] os/ 2019-01-05 14:39 -
我们输入如下命令:
[[email protected] ~]# system-config-kickstart
这是图形界面,我们可以在弹出的页面中设置文件
##### H、我们把centos7mini里的文件拷贝到centos7 上
[[email protected] ~]# cd /data
[[email protected] data]# ls
anaconda-ks.cfg hallo.sh magedu.pubkey
[[email protected] data]# mkdir /var/www/html/ks/; cp anaconda-ks.cfg /var/www/html/ks/centos7-mini.cfg
##### L、我们进入ks文件中查看
[[email protected] data]# cd /var/www/html/ks
[[email protected] ks]# ls
centos7-mini.cfg
[[email protected] ks]# ll
total 4
-rw------- 1 root root 1421 Jan 30 22:10 centos7-mini.cfg
[[email protected] ks]# chmod a+r centos7-mini.cfg
[[email protected] ks]# ll
total 4
-rw-r--r-- 1 root root 1421 Jan 30 22:10 centos7-mini.cfg
效果如下:
http://192.168.58.254/ks/centos7-mini.cfg
#version=DEVEL
System authorization information
auth --enableshadow --passalgo=sha512
Use CDROM installation media
cdrom
Use graphical install
graphical
Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
Keyboard layouts
keyboard --vckeymap=us --xlayouts=‘us‘
System language
lang en_US.UTF-8
Network information
network --bootproto=dhcp --device=ens33 --onboot=off --ipv6=auto --no-activate
network --hostname=localhost.localdomain
Root password
rootpw --iscrypted $6$V2eP8pESlfKIToP8$NVcSm0geeSV4X1cd1lccrs9FAdK1rbj6EczSviVmoz75Znj5GaI.qY7jA0H1dmbh.hsI2ZIHtaR3Ko0/Xku9B1
System services
services --disabled="chronyd"
System timezone
timezone Asia/Shanghai --isUtc --nontp
user --name=wang --password=$6$5MKCrWhZLuuC30QZ$X7fRD6I.5TrvmUNm4tDS6TmTZua/uer6Sn2EzXBv/Bk307pkanOOn9pyilJxT/cs9jxpXMBnAzHChvgPbb8Qe. --iscrypted --gecos="wang"
System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
Partition clearing information
clearpart --none --initlabel
%packagesbr/>@^minimal
@core
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
##### H、接下来,我们在字符界面中配置文件
[[email protected] ~]# system-config-kickstart
Xlib: extension "RANDR" missing on display "localhost:11.0".
/usr/share/system-config-kickstart/kickstartGui.py:104: GtkWarning: GtkSpinButton: setting an adjustment with non-zero page size is deprecated
xml = gtk.glade.XML ("/usr/share/system-config-kickstart/system-config-kickstart.glade", domain="system-config-kickstart")
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
此时会出现字符界面,我们进行配置,会保存一个备份文件,设为 mini2.cfg 然后在命令行中配置mini2.cfg ,如下:
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
Install OS instead of upgrade
install
Keyboard layouts
old format: keyboard us
new format:
keyboard --vckeymap=us --xlayouts=‘us‘
Root password
rootpw --iscrypted $1$bd9ZrVuB$ce4e5JUDPx9sIL4chvqY4/
Use network installation
url --url="http://192.168.58.254/centos/7/os/x86_64/"
System language
lang en_US
user --name=wang --password=$6$5MKCrWhZLuuC30QZ$X7fRD6I.5TrvmUNm4tDS6TmTZua/uer6Sn2EzXBv/Bk307pkanOOn9pyilJxT/cs9jxpXMBnAzHChvgPbb8Qe. --iscrypted --gecos="wang"
System authorization information
auth --useshadow --passalgo=sha512
Use text mode install
text
Run the Setup Agent on first boot
firstboot --enable
SELinux configuration
selinux --disabled
System services
services --disabled="chronyd"
ignoredisk --only-use=sda
Firewall configuration
firewall --disabled
Network information
network --bootproto=dhcp --device=ens33
Halt after installation
halt
System timezone
timezone Asia/Shanghai --nontp
System bootloader configuration
bootloader --append="crashkernel=auto" --location=mbr --boot-drive=sda
Partition clearing information
zerombr
clearpart --all --initlabel
part / --fstype="xfs" --ondisk=sda --size=102400
part swap --fstype="swap" --ondisk=sda --size=2305
part /data --fstype="xfs" --ondisk=sda --size=50000
part /boot --fstype="xfs" --ondisk=sda --size=1024br/>%packages
@^minimal
@core
autofs
%end
%postbr/>@core
autofs
%end
%post
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=aliun-base
baseurl=http://192.168.58.254/centos/$releasever/os/$basearch
gpgcheack=0
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
enable=1
EOF
mkdir -m 700 /root/.ssh
cat > /root/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC877AA5GcfUvWTDyH/fVPhL42biDSFNvLpQgSWr2YOS5nDdCRHyiarhC9+1WBBQ0yWvpYa7HePADYzuBSwR5tk1ZljcMx+i1d6vW3nYCG2EoQea4Z9Ryo6PvLzOtRzUTvbkhc3DukxpU5CdrfEoRN6EAjfgpnr39VLDPxlCNPmyHOSohDcRufBTU522623B3c3FJ4XmbWb5f478ERbNNJfc0UWlJI2Kq82myAtY+RFQSxGElDu7a4F/W6O78qP6QGlbcK/2aBZcgmtHmjTPsCCKucnm4jEij0xOXYHxcFUS7bw23i4VRFYsxU9oVdsZ2e7lATHPMgh19R0Kl/ZQQul [email protected]
EOF
chmod 600 /root/.ssh/authorized_keys
echo ‘GSSAPIAuthentication no‘ >> /etc/ssh/sshd_config
echo ‘UseDNS no‘ >> /etc/ssh/sshd_config
%end
我们手动配置了zerombr 用来清空分区,part分区,yum源,ssh/authorized_keys,/etc/ssh/sshd_config等内容。
##### L、我们将新安装好的centos7mini开机,在install 7 选项处按 esc 键,会弹出:boot:输入:Linux ks=http://192.168.58.254/ks/mini2.cfg ip=192.168.58.123 netmask=255.255.255.0
此时我们去ping192.168.58.123,若能ping通,就说明可以了,按回车键,即可进行自动安装,到此,此实验完满结束!!!
以上是关于实验自动化安装的主要内容,如果未能解决你的问题,请参考以下文章