Linux系統半自動和自動安裝

一、使用 kickstart 半自動化安裝CentOS系統html

#設置yum源
[root@centos173 ~]#cd /var/www/html/centos/7/os/x86_64/
[root@centos173 x86_64]#ll
total 694
-rw-rw-r--. 2 root root     14 Apr 21 02:14 CentOS_BuildTag
drwxr-xr-x. 3 root root   2048 Apr 21 02:00 EFI
-rw-rw-r--. 3 root root    227 Aug 30  2017 EULA
-rw-rw-r--. 3 root root  18009 Dec 10  2015 GPL
drwxr-xr-x. 3 root root   2048 Apr 21 02:00 images
drwxr-xr-x. 2 root root   2048 Apr 21 02:00 isolinux
drwxr-xr-x. 2 root root   2048 Apr 21 02:00 LiveOS
drwxr-xr-x. 2 root root 671744 Apr 22 08:15 Packages
drwxrwxr-x. 2 root root   4096 Apr 22 08:19 repodata
-rw-rw-r--. 3 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 3 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root   2883 Apr 22 08:54 TRANS.TBL
#掛載到光盤
[root@centos173 x86_64]#yum -y install httpd;systemctl enable --now httpd
[root@centos173 ~]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          920812       0    920812   0% /dev
tmpfs             931520       0    931520   0% /dev/shm
tmpfs             931520    9768    921752   2% /run
tmpfs             931520       0    931520   0% /sys/fs/cgroup
/dev/sda2      104806400 1794036 103012364   2% /
/dev/sda5       52403200   33008  52370192   1% /data
/dev/sda1        1038336  144904    893432  14% /boot
tmpfs             186304       0    186304   0% /run/user/0
/dev/sr0         4669162 4669162         0 100% /var/www/html/centos/7/os/x86_64
#下載httpd
[root@centos173 ~]#yum -y install httpd;systemctl enable --now httpd
#設置kickstart文件
[root@centos173 ~]#cat /var/www/html/ksdir/ks7.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext 123456
# System language
lang en_US
# 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
# Do not configure the X Window System
skipx

# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
#network  --hostname=centos***
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://10.0.0.173/centos/7/os/x86_64/"
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=none
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --size=100000
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=2048
part /data --fstype="xfs" --size=50000

%pre
i am pre
%end

%post
mv /etc/yum.repos.d/* /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=CentOS
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch
    https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch
gpgcheck=0

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch
    https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch
gpgcheck=0
enabled=1

[epel]
name=EPEL
baseurl=https://mirrors.aliyun.com/epel/\$releasever/Everything/\$basearch
    https://mirrors.huaweicloud.com/epel/\$releasever/Everythhing/\$basearch
gpgcheck=0
enabled=1
EOF

mkdir /root/.ssh -m 700
cat > authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2CCYsscefCmiZwXop9dCTDZ+BF+ZlCgDjmRo/TRls1NhurcRayq7lcxk7LcbKcR1Bx3UtqnQAIa/5+6/BjzuZDVtf0L0rUwD4/2S/a0LkwnwrCxKYowiYpNoTEwJbBYzdwH/++ytpvt4OZQGD4s1P911dyywP/cFAWayDH0T8dKDsTu4AExcDksdLXs119OwhI2EmzDHEmiICRL4FG7LSyBy407Cb0PrtvSMCPVnhwW6X9pVJsIkxdEIuP/gJg1Jix4xmXqcGliZP0rUYwwrwmB/HivyxXei/Z2BqT00tK8cHdu8PTc0QQ749RBRgYjgpH61/DObGqa5GzPwlg86V root@centos171
EOF
chmod 600 /root/.ssh

#sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#systemctl disable firewalld
useradd xiaobai
echo 123456|passwd --stdin xiaobai
%end

%packages
@development
%end

二、實現pxe安裝雙系統centos六、centos7 linux

centos6,7安裝vim

#安裝相關包並啓動
[root@centos183 ~]#yum install dhcp-server httpd tftp-server syslinux-nonlinux

#配置DHCP服務
[root@centos183 ~]#cp /usr/share/doc/dhcp-server/dhcpd.conf.sample /etc/dhcp/dhcpd.conf 
[root@centos183 ~]#vim /etc/dhcp/dhcpd.conf 
option domain-name "example.com";
option domain-name-servers 180.76.76.76,8.8.8.8;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 10.0.0.0 netmask 255.255.255.0{
range 10.0.0.1 10.0.0.200;
    option routers 10.0.0.2;
    next-server 10.0.0.100;
    filename "pxelinux.0"
}

#準備pxe啓動文件
[root@centos183 ~]#ll /var/www/html/ksdir/
total 12
-rw-r--r-- 1 root root 1301 Sep 14 06:49 ks6.cfg
-rw-r--r-- 1 root root 1433 Sep 14 06:50 ks7.cfg
-rw-r--r-- 1 root root 2007 Sep 14 01:10 ks8.cfg
[root@centos163 ~]#scp /var/www/html/centos/6/os/x86_64/isolinux/{vmlinuz,initrd.img} 10.0.0.183:/var/lib/tftpboot/centos6
[root@centos173 ~]#scp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinuz,initrd.img} 10.0.0.183:/var/lib/tftpboot/centos7

#準備啓動菜單文件
[root@centos183 ~]#vim /var/lib/tftpboot/pxelinux.cfg/default

label centos6
    menu label Automatic Install centos^6
    kernel vmlinuz
    append initrd=initrd.img ks=http://10.0.0.183/ksdir/ks6.cfg
label centos7
    menu label Automatic Install centos^7
    kernel vmlinuz
    append initrd=initrd.img ks=http://10.0.0.183/ksdir/ks7.cfg
相關文章
相關標籤/搜索