运维自动化系统部署

您所在的位置:网站首页 自动化部署与运维 运维自动化系统部署

运维自动化系统部署

2022-10-09 03:38| 来源: 网络整理| 查看: 265

文章目录 一、CentOS8实现PXE自动化安装1、安装前准备:2、安装相关软件包3、配置dhcp服务4、准备yum源和相关目录5、准备kickstart文件6、准备PXE启动相关文件7、准备启动菜单文件8、测试客户端基于PXE实现自动安装 二、利用cobbler实现自动化安装1、环境准备2、安装相关包并启动服务3、修改cobbler相关的配置4、实现dhcp服务5、下载启动的相关文件6、修改菜单的标题信息7、导入centos系统的安装文件,生成相应的yum源8、准备kickstart文件,并关联至指定的yum源9、支持UEFI安装10、实现cobbler web 管理11、创建cobbler自定义用户

一、CentOS8实现PXE自动化安装 1、安装前准备:

关闭防火墙和selinux 确保dhcp服务器地址是静态IP

2、安装相关软件包 [root@centos8 ~]#dnf -y install dhcp-server tftp-server httpd syslinuxnonlinux(或者syslinux-tftpboot) [root@centos8 ~]#systemctl enable --now httpd tftp dhcpd 3、配置dhcp服务 [root@centos8 ~]#cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf [root@centos8 ~]#vim /etc/dhcp/dhcpd.conf option domain-name "example.com"; option domain-name-servers 180.76.76.76,223.6.6.6; 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.1; next-server 10.0.0.100; filename "pxelinux.0"; } [root@centos8 ~]#systemctl start dhcpd 4、准备yum源和相关目录 [root@centos8 ~]#mkdir -pv /var/www/html/centos/{6,7,8}/os/x86_64/ [root@centos8 ~]#mount /dev/sr0 /var/www/html/centos/6/os/x86_64/ [root@centos8 ~]#mount /dev/sr1 /var/www/html/centos/7/os/x86_64/ [root@centos8 ~]#mount /dev/sr2 /var/www/html/centos/8/os/x86_64/ 5、准备kickstart文件 [root@centos8 ~]#mkdir /var/www/html/ks/ [root@centos8 ~]#vim /var/www/html/ks/centos6.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard 'us' # Root password rootpw --iscrypted $1$ALS9TIDA$V2TkFpdeH24/B/2Y/ILtJ0 # System language lang en_US # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text firstboot --disable # SELinux configuration selinux --disabled # Firewall configuration firewall --disabled # Network information network --bootproto=dhcp --device=eth0 # Reboot after installation reboot # System timezone timezone Africa/Abidjan # Use network installation url --url="http://10.0.0.7/centos/6/os/x86_64" # System bootloader configuration bootloader --append="net.ifnames=0" --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part / --fstype="ext4" --size=20480 part /boot --fstype="ext4" --size=1024 part swap --fstype="swap" --size=2048 %packages @core @server-policy @workstation-policy autofs vim-enhanced %end %post useradd wang echo magedu | passwd --stdin wang &> /dev/null mkdir /etc/yum.repos.d/bak mv /etc/yum.repos.d/* /etc/yum.repos.d/bak cat > /etc/yum.repos.d/base.repo /var/lib/tftpboot/menu.c32 trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi copying distros to tftpboot copying images generating PXE configuration files generating PXE menu structure rendering TFTPD files generating /etc/xinetd.d/tftp cleaning link caches running post-sync triggers running python triggers from /var/lib/cobbler/triggers/sync/post/* running python trigger cobbler.modules.sync_post_restart_services running shell triggers from /var/lib/cobbler/triggers/sync/post/* running python triggers from /var/lib/cobbler/triggers/change/* running python trigger cobbler.modules.manage_genders running python trigger cobbler.modules.scm_track running shell triggers from /var/lib/cobbler/triggers/change/* *** TASK COMPLETE *** [root@centos7 ~]#tree /var/lib/tftpboot/ /var/lib/tftpboot/ ├── boot │ └── grub │ └── menu.lst ├── etc ├── grub │ ├── efidefault │ ├── grub-x86_64.efi │ ├── grub-x86.efi │ └── images -> ../images ├── images ├── images2 ├── memdisk ├── menu.c32 ├── ppc ├── pxelinux.0 ├── pxelinux.cfg │ └── default ├── s390x │ └── profile_list └── yaboot 10 directories, 10 files 6、修改菜单的标题信息 [root@centos7 ~]#vim /etc/cobbler/pxe/pxedefault.template MENU TITLE Cobbler | http://www.magedu.com/ [root@centos7 ~]#cobbler sync [root@centos7 ~]#cat /var/lib/tftpboot/pxelinux.cfg/default DEFAULT menu PROMPT 0 MENU TITLE Cobbler | http://www.magedu.com/ #默认为:http://cobbler.github.io/ TIMEOUT 200 TOTALTIMEOUT 6000 ONTIMEOUT local LABEL local MENU LABEL (local) MENU DEFAULT LOCALBOOT -1 MENU end [root@centos7 ~]#cobbler sync 7、导入centos系统的安装文件,生成相应的yum源 #导入yum源时,会自动生成菜单项并自动关联最小化安装系统的文件kickstart文件,默认root密码为cobbler [root@centos7 ~]#cobbler import --name=centos-8.1-x86_64 --path=/misc/cd --arch=x86_64 [root@centos7 ~]#mount /dev/sr1 /mnt mount: /dev/sr1 is write-protected, mounting read-only #也可以在导入yum源的同时进行关联自定义的kickstart文件 [root@centos7 ~]#cobbler import --name=centos-7.7-x86_64 --path=/mnt --arch=x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg [root@centos7 ~]#du -sh /var/www/cobbler/ks_mirror/* 11G /var/www/cobbler/ks_mirror/centos-7.7-x86_64 7.2G /var/www/cobbler/ks_mirror/centos-8.1-x86_64 12K /var/www/cobbler/ks_mirror/config [root@centos7 ~]#cobbler distro list centos-7.7-x86_64 centos-8.1-x86_64 [root@centos7 ~]#cobbler profile listsh centos-7.7-x86_64 centos-8.1-x86_64

注意:CentOS8.3 的导入出错,需要修改文件

#默认直接导入CentOS8.3会出现下面错误 [root@centos7 ~]#cobbler import --name=centos-8.3-x86_64 --path=/mnt -- arch=x86_64 task started: 2021-01-18_162855_import task started (id=Media import, time=Mon Jan 18 16:28:55 2021) Found a candidate signature: breed=redhat, version=rhel8 No signature matched in /var/www/cobbler/ks_mirror/centos-8.3-x86_64 !!! TASK FAILED !!! #解决方法 [root@centos7 ~]#vim /var/lib/cobbler/distro_signatures.json #修改第70行添加centos-linux 68 "rhel8": { 69 "signatures":["BaseOS"], 70 "version_file":"(redhat|sl|slf|centos-linux|centos|oraclelinux|vzlinux)- release-(?!notes)([\\w]*-)*8(Server)*[\\.-]+(.*)\\.rpm", [root@centos7 ~]#systemctl restart cobblerd [root@centos7 ~]#cobbler sync 8、准备kickstart文件,并关联至指定的yum源 #将kickstart文件,关联指定的YUM源和生成菜单列表 [root@centos7 ~]#cobbler profile add --name=CentOS-8.1_test --distro=CentOS-8.1- x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos8.cfg [root@centos7 ~]#cobbler profile add --name=CentOS-7.7_test --distro=CentOS-7.7- x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg #删除默认生成的菜单 [root@centos7 ~]#cobbler profile remove --name=centos-8.1-x86_64 [root@centos7 ~]#cobbler profile remove --name=centos-7.7-x86_64 [root@centos7 ~]#cobbler profile list CentOS-7.7_test CentOS-8.1_test #删除默认的菜单列表 [root@centos7 ~]#cobbler profile remove --name=CentOS8.0-x86_64 #设置默认安装菜单, 这样未装系统的设备会自动从pxe引导启动你需要安装的系统, 不需要再手动接显示器 选了 [root@centos7 ~]#cobbler system add --name=default --profile=centos-8.1-x86_64 9、支持UEFI安装

注意:CentOS 6 的虚拟机不支持UEFI

修改文件设置时间,默认不显示菜单 #修改模版文件 [root@cobbler-centos7 ~]#vim /etc/cobbler/pxe/efidefault.template [root@cobbler-centos7 ~]#cat /var/lib/tftpboot/grub/efidefault default=0 timeout=60 $grub_menu_items #使模版生效 [root@cobbler-centos7 ~]#cobbler sync #验证生效 [root@cobbler-centos7 ~]#head -n 2 /var/lib/tftpboot/grub/efidefault default=0 timeout=60 10、实现cobbler web 管理 [root@centos7 ~]#yum -y install cobbler-web [root@centos7 ~]#systemctl restart httpd 通过浏览器访问下面地址: https://10.0.0.7/cobbler_web 用户名:cobbler 密码:cobbler 11、创建cobbler自定义用户 [root@centos7 ~]#cat /etc/cobbler/users.digest cobbler:Cobbler:a2d6bae81669d707b72c0bd9806e01f3 [root@centos7 ~]#htdigest -c /etc/cobbler/users.digest Cobbler admin Adding password for admin in realm Cobbler. New password: Re-type new password: [root@centos7 ~]#cat /etc/cobbler/users.digest admin:Cobbler:461941848a17e1b412f94c100a79bf75 3 [root@centos7 ~]#htdigest /etc/cobbler/users.digest Cobbler admin2 Adding user admin2 in realm Cobbler New password: Re-type new password: [root@centos7 ~]#cat /etc/cobbler/users.digest admin:Cobbler:461941848a17e1b412f94c100a79bf75 3 admin2:Cobbler:8e3ab6cc196fac11dcf0512c200a672f


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3