anaconda負責安裝系統嚮導,默認爲GUI界面,若是咱們使用ks自動應答安裝的話建議使用TUI界面來安裝html
在安裝啓動界面咱們能夠按esc鍵來本身手動指定安裝啓動選項linux
anaconda選項:git
1)linux askmethod 在稍後的安裝中手動選擇安裝源github
本地光盤、硬盤、NFS、FTP、HTTPweb
2)linux dd 加載驅動盤redis
3)linux ks=xxx 指定安裝ks文件vim
4)linux nonet 不啓用網絡centos
5)linux noprobe 不裝載其餘的硬件設備瀏覽器
6)linux rescue 進入救援模式服務器
7)linux 正常安裝
8)local 從硬盤啓動
9)linux text 以字符界面安裝
10)linux ip={DHCP | 192.168.0.1} netmask=255.255.255.0 gateway=192.168.0.1 dns=114.114.114.114 ks=http://192.168.0.1/ks.cfg 設置IP並從網絡獲取ks文件
11)linux ip={DHCP | 192.168.0.1} netmask=255.255.255.0 gateway=192.168.0.1 dns=114.114.114.114 repo=http://192.168.0.1 設置IP地址並指定從repo源安裝
12)linux vnc vncpassword="PASSWORD" 使用vnc調用安裝界面
在光盤下的isolinux/文件夾爲anaconda的工做目錄文件存放位置
# ls -1 isolinux/ boot.cat 模擬mbr文件 boot.msg grub.conf grub的配置文件 initrd.img ramdisk文件 isolinux.bin grub的第二階段 isolinux.cfg 配置文件(啓動菜單定製文件) memtest 內存測試文件 splash.jpg 背景圖片 TRANS.TBL vesamenu.c32 光盤啓動的圖形界面菜單風格 vmlinuz 內核文件
啓動菜單的配置文件isolinux/isolinux.cfg
# cat isolinux/isolinux.cfg default vesamenu.c32 提供圖形菜單風格 #prompt 1 timeout 600 菜單選擇超時時間 display boot.msg menu background splash.jpg 背景圖片 menu title Welcome to CentOS 6.9! 菜單上方提示信息 menu color border 0 #ffffffff #00000000 menu color sel 7 #ffffffff #ff000000 menu color title 0 #ffffffff #00000000 menu color tabmsg 0 #ffffffff #00000000 menu color unsel 0 #ffffffff #00000000 menu color hotsel 0 #ff000000 #ffffffff menu color hotkey 7 #ffffffff #ff000000 menu color scrollbar 0 #ffffffff #00000000 label linux 一條菜單 menu label ^Install or upgrade an existing system menu default 默認選擇 kernel vmlinuz append initrd=initrd.img 向內核傳遞參數
Anaconda安裝系統分紅三個階段:
一、安裝前配置階段
二、安裝階段
三、圖形模式首次啓動
kickstart爲anaconda安裝系統過程當中自動應答已配置好的選項,實現無人值守安裝系統。
ks文件格式:三部分
命令段:
---必須指定---
---可選命令---
軟件包選擇段:%package
腳本段:
預安裝腳本%pre
後安裝腳本%post
咱們瞭解了ks文件的格式以後來建立一個ks文件吧,建立的方式有倆種,咱們能夠直接參考 /root/anaconda-ks.cfg 來編輯,而後使用ksvalidator命令來檢查是否有語法錯誤,可是這樣不是很方便;第二種方法就是使用system-config-kickstart 圖形界面工具生成ks文件。
一、配置yum源、安裝軟件並啓動,須要安裝圖形界面
root@centos7 ~]# cat /etc/yum.repos.d/cdrom.repo [development] #爲了讓system-config-kickstart讀取軟件包 name=cdrom_base baseurl=file:///media/cdrom/ gpgcheck=0 enabled=1 [root@centos7 ~]# yum install system-config-kickstart [root@centos7 ~]# system-config-kickstart &
二、按需配置
ks.cfg配置文件,以上步驟生成
[root@centos7 data]# cat ks.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard 'us' # Root password rootpw --iscrypted $1$.4cA9H18$yFklftvKKTJ78OmWBqAPz1 # System language lang en_US # System authorization information auth --useshadow --passalgo=sha512 # Use CDROM installation media cdrom # Use text mode install text #文本文件安裝 # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # Firewall configuration firewall --disabled # Network information network --bootproto=static --device=eth0 --gateway=192.168.0.1 --ip=192.168.0.222 --nameserver=114.114.114.114 --netmask=255.255.255.0 # Reboot after installation reboot # System timezone timezone Asia/Shanghai #時區 # 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 /boot --fstype="xfs" --size=200 part swap --fstype="swap" --size=2048 part / --fstype="xfs" --grow --size=1 #表示根分區使用剩餘所有空間 %packages
@^minimal
@core @base %end
ks文件中LVM邏輯卷分區格式
part /boot --fstype xfs --size=200 --ondisk=sda part pv.2 --size=0 --grow --ondisk=sda volgroup myvg --pesize=4096 pv.2 logvol / --fstype xfs --name=lv_root --vgname=myvg --size=10240 --grow logvol swap --fstype swap --name=lv_swap --vgname=myvg --size=1024 --grow --maxsize=2048
ks文件中使用系統自動分區格式
# Partition clearing information clearpart --all --initlabel autopartc
咱們如今已經有一個ks文件了,接下來須要把ks文件加入到光盤文件中來實現自動安裝
一、準備安裝文件
[root@centos7 ~]# mkdir -p /data/myiso [root@centos7 ~]# cp -r /media/cdrom/ /data/myiso/
[root@centos7 ~]# cp /data/ks_7_mini.cfg /data/myiso/cdrom/ksdir/
二、編輯配置文件
[root@centos7 ~]# vim /data/myiso/cdrom/isolinux/isolinux.cfg #增長一個label label linux menu label ^Ks_Install CentOS 7_mini kernel vmlinuz append initrd=initrd.img text ks=cdrom:/ksdir/ks_7_mini.cfg
三、製做ISO文件
[root@centos7 ~]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS_7.5_x86_64"
-b isolinux/isolinux.bin -c isolinux/boot.cat -o /data/CentOS-7.5-x86_64.iso /data/myiso/cdrom
mkisofs命令
Preboot Excution Environment 預啓動執行環境,Intel公司研發,基於Client/Server的網絡模式,支持遠程主機經過網絡從遠端服務器下載映像,並由此支持經過網絡啓動操做系統,PXE能夠引導和安裝Windows,linux等多種操做系統。
準備環境:CentOS6.9,靜態IP(必須):192.168.0.6,CentOS6.9和CentOS7.5的ISO鏡像
關閉防火牆和selinux
[root@centos6 ~]# yum install -y dhcp tftp-server httpd syslinux
[root@centos6 ~]# mkdir /media/centos{6,7} [root@centos6 ~]# mount -r /dev/sr0 /media/centos6/ [root@centos6 ~]# mount -r /dev/sr1 /media/centos7/
[root@centos6 ~]# vim /etc/dhcp/dhcpd.conf log-facility local7; #記錄日誌級別 subnet 192.168.0.0 netmask 255.255.255.0 { #分配子網,和本身主機一個網段 range 192.168.0.100 192.168.0.254; #地址池 option domain-name-servers 114.114.114.114; #DNS option domain-name "pxe.test.org"; #搜索域 option routers 192.168.0.1; #路由網關 default-lease-time 600; #默認租約時間 max-lease-time 7200; #最大租約時間 next-server 192.168.0.6; #*指向tftp服務器地址,此處指向本機 filename "pxelinux.0"; #pxe文件名,系統默認爲pxelinux.0 }
[root@centos6 ~]# service dhcpd start #啓動dhcp服務 [root@centos6 ~]# chkconfig dhcpd on #加入開機啓動
[root@centos6 ~]# chkconfig tftp on [root@centos6 ~]# service xinetd start
[root@centos6 ~]# cd /var/lib/tftpboot/ [root@centos6 tftpboot]# mkdir centos{6,7} [root@centos6 tftpboot]# mkdir pxelinux.cfg/ [root@centos6 tftpboot]# cp /media/centos6/isolinux/{initrd.img,vmlinuz} centos6/ [root@centos6 tftpboot]# cp /media/centos7/isolinux/{initrd.img,vmlinuz} centos7/ [root@centos6 tftpboot]# cp /media/centos6/isolinux/{boot.msg,splash.jpg,vesamenu.c32} . [root@centos6 tftpboot]# cp /usr/share/syslinux/pxelinux.0 . [root@centos6 tftpboot]# install -m 644 /media/centos6/isolinux/isolinux.cfg pxelinux.cfg/default [root@centos6 tftpboot]# vim pxelinux.cfg/default default vesamenu.c32 timeout 60 display boot.msg menu background splash.jpg menu title Welcome to CentOS ! label linux menu label ^Install centos6.9_mini kernel centos6/vmlinuz append initrd=centos6/initrd.img ks=http://192.168.0.6/ksdir/ks6_mini.cfg label linux menu label ^Install centos7.5_mini kernel centos7/vmlinuz append initrd=centos7/initrd.img ks=http://192.168.0.6/ksdir/ks7_mini.cfg label local menu default menu label Boot from ^local drive localboot 0xffff
[root@centos6 tftpboot]# tree . ├── boot.msg ├── centos6 │ ├── initrd.img │ └── vmlinuz ├── centos7 │ ├── initrd.img │ └── vmlinuz ├── pxelinux.0 ├── pxelinux.cfg │ └── default ├── splash.jpg └── vesamenu.c32
[root@centos6 ~]# mkdir -p /var/www/html/centos/{6,7} [root@centos6 ~]# mount -r /dev/sr0 /var/www/html/centos/6/ [root@centos6 ~]# mount -r /dev/sr1 /var/www/html/centos/7/ [root@centos6 ~]# mkdir -p /var/www/html/ksdir/ [root@centos6 ~]# cp ks6_mini.cfg ks7-mini.cfg /var/www/html/ksdir/
[root@centos6 ~]# service httpd start [root@centos6 ~]# chkconfig httpd on
[root@centos6 ~]# netstat -tnul #查看如下端口是否都監聽 tcp 0 0 :::80 :::* LISTEN udp 0 0 0.0.0.0:67 0.0.0.0:* udp 0 0 0.0.0.0:69 0.0.0.0:*
#platform=x86, AMD64, or Intel EM64T #version=DEVEL # Firewall configuration firewall --disabled # Install OS instead of upgrade install # Use network installation url --url="http://192.168.0.10/centos/6/" # Root password rootpw --iscrypted $1$sQ90pp9b$TI8EEelvqSLdsrjDoPwrN/ # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text # System keyboard keyboard us # System language lang en_US # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # Installation logging level logging --level=info # Reboot after installation reboot # System timezone timezone Asia/Shanghai # Network information network --bootproto=dhcp --device=eth0 --onboot=on # System bootloader configuration bootloader --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information autopart %packages @core %end
pxe的二次封裝,由Python開發,提供CLI和Web管理,cobbler在epel源中,安裝時須要配置epel源。
工做原理:
配置文件:
/etc/cobbler/settings : cobbler 主配置文件
/etc/cobbler/iso/: iso模板配置文件
/etc/cobbler/pxe: pxe模板文件
/etc/cobbler/power: 電源配置文件
/etc/cobbler/user.conf: web服務受權配置文件
/etc/cobbler/users.digest: web訪問的用戶名密碼配置文件
/etc/cobbler/dhcp.template : dhcp服務器的的配置末班
/etc/cobbler/dnsmasq.template : dns服務器的配置模板
/etc/cobbler/tftpd.template : tftp服務的配置模板
/etc/cobbler/modules.conf : 模塊的配置文件
數據目錄:
/var/lib/cobbler/config/: 用於存放distros,system,profiles 等信息配置文件
/var/lib/cobbler/triggers/: 用於存放用戶定義的cobbler命令
/var/lib/cobbler/kickstart/: 默認存放kickstart文件
/var/lib/cobbler/loaders/: 存放各類引導程序
鏡像目錄:
/var/www/cobbler/ks_mirror/: 導入的發行版系統的全部數據
/var/www/cobbler/images/ : 導入發行版的kernel和initrd鏡像用於遠程網絡啓動
/var/www/cobbler/repo_mirror/: yum 倉庫存儲目錄
日誌目錄:
/var/log/cobbler/installing: 客戶端安裝日誌
/var/log/cobbler/cobbler.log : cobbler日誌
cobbler經常使用命令:
cobbler check 覈對當前設置是否有問題
cobbler list 列出全部的cobbler元素
cobbler report 列出元素的詳細信息
cobbler sync 同步配置到數據目錄,更改配置最好都要執行下
cobbler reposync 同步yum倉庫
cobbler distro 查看導入的發行版系統信息
cobbler system 查看添加的系統信息
cobbler profile 查看配置信息
cobbler profile report --name=xxxx 查看ks文件的詳細信息
環境:CentOS7.5,epel源,IP:192.168.0.7
一、安裝並啓動須要服務
[root@centos7 ~]# yum install cobbler dhcp [root@centos7 ~]# systemctl enable cobblerd dhcpd httpd tftp [root@centos7 ~]# systemctl start cobblerd httpd tftp
二、 檢查環境,按照提示修改對應項
[root@centos7 ~]# 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. #修改配置文件中server參數爲本身的主機IP 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. #修改配置文件中next_server指向tftp服務器,這裏我也指向本身的IP 3 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment: https://github.com/cobbler/cobbler/wiki/Selinux #將selinux關閉 4 : change 'disable' to 'no' in /etc/xinetd.d/tftp #將tftp服務啓動 5 : 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. #執行cobbler get-loaders下載啓動引導的文件 6 : enable and start rsyncd.service with systemctl #啓動rsync服務 7 : debmirror package is not installed, it will be required to manage debian deployments and repositories #安裝支持deb包的組件,如今安裝CentOS不須要此組件 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 #修改配置文件中password的參數爲本身指定的安裝完系統後的root密碼 9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them #fencing設備的配置 Restart cobblerd and then run 'cobbler sync' to apply changes.
1)
[root@centos7 ~]# vim /etc/cobbler/settings server: 192.168.0.7
2)
[root@centos7 ~]# vim /etc/cobbler/settings next_server: 192.168.130.8
3)
[root@centos7 ~]# setenforce 0 [root@centos7 ~]# getenforce Permissive
4)
前邊已經啓動過了,這裏就不須要再次啓動了,此報錯是CentOS6中的修改方式
5)
[root@centos7 ~]# cobbler get-loaders
6)
[root@centos7 ~]# systemctl start rsyncd.service [root@centos7 ~]# systemctl enable rsyncd.service
7)
若是須要安裝Debian系列的系統能夠執行 yum install debmirror 命令
8)
[root@centos7 ~]# openssl passwd -1 Password: ****** Verifying - Password: ****** $1$wyB5xyxu$N7aNVlpb7uivVwTbIBC6F/ #複製此密碼到配置文件中,修改default_password_crypted參數 [root@centos7 ~]# vim /etc/cobbler/settings default_password_crypted: "$1$wyB5xyxu$N7aNVlpb7uivVwTbIBC6F/" #安裝系統的root密碼
9)
關於物理電源管理的配置,此時先不作配置了
三、配置dhcp
[root@centos7 ~]# vim /etc/cobbler/settings manage_dhcp: 1 [root@centos7 ~]# vim /etc/cobbler/dhcp.template #cobbler的配置dhcp模板,修改此文件後同步便可生效 subnet 192.168.0.0 netmask 255.255.255.0 { #修改成本身的網段 option routers 192.168.0.1; #路由地址 option domain-name-servers 114.114.114.114; #DNS option subnet-mask 255.255.255.0; #子網掩碼 range dynamic-bootp 192.168.0.100 192.168.0.254; #地址池 default-lease-time 21600; max-lease-time 43200; next-server $next_server; class "pxeclients" { match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; if option pxe-system-type = 00:02 { filename "ia64/elilo.efi"; } else if option pxe-system-type = 00:06 { filename "grub/grub-x86.efi"; } else if option pxe-system-type = 00:07 { filename "grub/grub-x86_64.efi"; } else if option pxe-system-type = 00:09 { filename "grub/grub-x86_64.efi"; } else { filename "pxelinux.0"; } } }
四、同步配置並重啓服務
[root@centos7 ~]# cobbler sync [root@centos7 ~]# systemctl restart cobblerd
到這裏cobbler已經配置完畢了,接下來咱們只須要將發行版的源和ks文件導入
導入發行版,可能會比較慢,並且要確認硬盤有足夠的空間
[root@centos7 ~]# cobbler import --path=/media/cdrom/ --name=CentOS-7.5-x86_64 --arch=x86_64
查看一下是否導入成功
[root@centos7 ~]# cobbler distro list CentOS-7.5-x86_64
cobbler會自動生成一個自動應答的配置文件,咱們須要將它刪除
[root@centos7 ~]# cobbler profile list CentOS-7.5-x86_64
[root@centos7 ~]# cobbler profile remove --name=CentOS-7.5-x86_64
接下來導入咱們準備好的ks文件
注意:須要將ks文件中的url改成 url --url=$tree
[root@centos7 ~]# cp ks7_mini.cfg /var/lib/cobbler/kickstarts/ [root@centos7 ~]# cobbler distro list CentOS-7.5-x86_64 [root@centos7 ~]# cobbler profile add --name=CentOS-7.5-x86_64_Mini --distro=CentOS-7.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_mini.cfg
導入成功
[root@centos7 ~]# cobbler profile list CentOS-7.5-x86_64_Mini
到此爲止,咱們已經配置好了一臺cobbler服務器了,接下來作安裝測試
[root@centos7 ~]# yum install cobbler-web [root@centos7 ~]# htdigest -c /etc/cobbler/users.digest Cobbler test1 建立管理用戶 [root@centos7 ~]# systemctl restart httpd 在瀏覽器中訪問https://192.168.0.7/cobbler_web
cobbler_web用戶管理認證方式:
文件方式:
# htdigest -c /etc/cobbler/users.digest Cobbler test1
pam模塊認證方式: