Linux系統安裝:CentOS系html
POST --> BootSequence(BIOS) --> BootLoader(GRUB --> 1_5 stage -->2nd stage) --> Kernel (devtmpfs) --> [ ramdisk (dev,proc,sys) -->] rootfs(ro) --> /sbin/init (SysV Init, upstart Init, systemd) java
對於所安裝的CentOS操做系統來講,其一級子目錄中,有一些絕對不能單獨分區,有一些能夠單獨分區;python
絕對不能分區:bin, sbin, lib, lib64linux
建議單獨分區:boot, home, var, usrweb
安裝Linux系統:vim
/bootcentos
swap安全
/服務器
/home網絡
/var
/usr
磁盤分區規劃:
啓動分區
根分區
swap
規劃文件系統:
/sbin/init, /sbin/systemd
全部的應用程序存放的路徑
應用程序所依賴的庫文件存放的路徑
應用程序所使用的配置文件存放的路徑
CentOS系/RHEL系操做系統的安裝程序:anaconda
在安裝操做系統的過程當中,系統的啓動流程:
POST --> BootLoader --> kernel --> initrd --> rootfs --> anaconda
anaconda給咱們提供了兩種操做界面:
TUI:基於curses的文件配置窗口;
GUI:圖形界面
CLI:命令行界面
以光盤爲例,CentOS系統的安裝啓動流程:
1.POST
2.讀取MBR:boot.cat,就是光盤的bootloader;/isolinux/boot.cat
3.stage2:/isolinux/isolinux.bin
配置文件:/isolinux/isolinux.cfg
label linux:
標籤名稱,能夠用來引用下述全部命令的通用名稱;
menu label ^Install or upgrade an existing system
菜單項的具體內容以及對應的熱鍵;
menu default
將此菜單項作爲默認菜單項;
kernel vmlinuz
指定內核文件名稱
append initrd=initrd.img
向內核傳遞附加參數;經常使用的參數有:
initrd=initrd.img
text:從文本界面啓動
method:手動選擇安裝方式
ip=ADDRESS
netmask=MASK
gateway=GW
dns=DNS_SERVER
rescue:啓用緊急救援模式
dd:device drivers,裝載額外的設備的啓動程序;
ks:使用kickstart啓動無人值守安裝,指明kickstart配置文件的所在位置:
光盤上:ks=cdrom:/PATH/TO/KICKSTART_FILE
本地硬盤:ks=hd:/DEVICE/PATH/TO/KICKSTART_FILE
某個遠程web站點:ks=http://HOST[:PORT]/PATH/TO/KICKSTART_FILE
某個遠程FTP站點:ks=ftp://[username@]HOST[:PORT]/PATH/TO/KICKSTART_FILE
某個遠程安全WEB站點:ks=https://HOST[:PORT]/PATH/TO/KICKSTART_FILE
4.裝載rootfs,並啓動anaconda
注意:若是內存不夠512M,則anaconda是以文本界面啓動的;若是內存大於512M,anaconda默認以圖形界面啓動;
"ESC"鍵 --> boot: linux text
注意:上述的全部內容通常位於引導設備,然後續的anaconda及其餘安裝時所用的程序包或程序包組等可來源於yum倉庫,yum倉庫的位置:
本地光盤
本地硬盤
FTP服務器
HTTP服務器
NFS服務器
若是想手動指定程序包安裝源:
ESC鍵 --> boot: linux method
anaconda的工做過程:
安裝前的準備配置階段
1.安裝過程當中使用的語言:簡體中文
2.鍵盤佈局類型:美國英語式
3.系統安裝的目標存儲設備:
Basic Storage,本地磁盤
Special Storage,網絡存儲,iSCSI,NAS,SAN, ...
4.設置主機名稱
5.配置網絡接口
6.選擇時區
7.管理員密碼
8.設定分區方式及MBR安裝的位置
9.選擇要安裝的程序包或程序包組;
安裝階段:
1.有可能運行某些預安裝腳本,完成初始化工做;
2.根據準備階段規劃的分區格式進行分區建立並執行格式化安裝文件系統並掛載全部文件系統至指定掛載點;
3.將選定的程序包或程序包組安裝至目標位置;
4.安裝bootloader至MBR及boot分區中;
5.製做ramdisk文件;
6.若是有必要,可能會運行安裝後腳本;
首次啓動:
1.選擇許可證信息;
2.建立普通用戶;
3.配置內核核心轉儲(Kdump傾倒,Core dump),若是內存小於2GB,Kdump不開啓;
當某一時刻,內核核心崩潰時,kdump會將內核崩潰時內存中的全部數據建立成一個映像文件保存到磁盤上;經過分析此文件的內容,查找出內核崩潰的直接或間接緣由;
1.是否配置iptables防火牆;初學者建議關閉;
2.是否配置SELinux安全機制的啓動,初學者建議關閉;
kickstart文件的格式:
命令段:指明各類安裝前的配置;
必備命令:
authconfig:認證方式的配置
authconfig --useshadow --passalgo=sha512
bootloader:定義bootloader的安裝位置和相關配置選項
bootloader --location=mbr --driveorder=sda --append="*** crashkernel=auto rhgb quiet"
keyboard:設定鍵盤的類型
keyboard us
lang:安裝過程當中的語言類型
lang zh_CN.UTF-8
part:分區佈局及分區使用方式的定義;
part /boot --fstype=ext4 --size=200
part swap --size=2048
part PV_NAME --size=51200 --grow
clearpart:清除分區
clearpart --none --drives=sda
volgroup:建立卷組的命令
volgroup VG_NAME --pesize=8192 PV_NAME
logvol:建立邏輯卷的命令
logvol /home --fstype=ext4 --name=lv_home --vgname=VG_NAME --size=10240
logvol / --fstype=ext4 --name=lv_root --vgname=VG_NAME --size=30720
logvol /var --fstype=ext4 --name=lv_var --vgname=VG_NAME --size=10240
logvol /usr --fstype=ext4 --name=lv_usr --vgname=VG_NAME --size=10240
rootpw:指明超級用戶root的密碼
rootpw --iscrypted $6$SALT$ENCRYPTED_PASS
timezone:時區
timezone Asia/Shanghai
可選擇命令:
install:全新安裝操做系統
upgrade:升級安裝操做系統
text:使用文本界面安裝操做系統,默認是GUI;
network:配置網絡接口
network --onboot yes --device eth0 --bootproto static --ip 172.16.254.1 --netmask 255.255.0.0 --noipv6 --hostname a.link.com --gateway= --dns=
firewall:防火牆設置
firewall --disabled
firewall --service=ssh
selinux:SELinux的設置
selinux --disabled
selinux --enforcing
題外話:
若是計劃在已經開啓防火牆和SELinux的強制模式時,能夠經過這樣的幾種方式將其關閉:
防火牆:
CentOS 6:
# service iptables stop
# chkconfig iptables off
CentOS 7:
# systemctl stop firewalld.service
# systemctl disable firewalld.service
若是想要讓防火牆臨時不生效:
# iptables -F 適用於全部的CentOS系統;
SELinux:
1.編輯SELinux的配置文件/etc/sysconfig/selinux(/etc/selinux/config),在配置文件中,有一行語句爲:
SELINUX=disabled
2.編輯grub的啓動配置文件/boot/grub/grub.conf
kernel /vmlinuz-VERSION-release ARGS selinux=0
若是想要SELinux臨時不限用戶行爲:
# setenforce 0 == Enforcing --> Permissive
# setenforce 1 == Permissive --> Enforcing
# getenforce
repo:安裝系統是所使用的倉庫repository
repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100
repo --name="CentOS" --baseurl=http://host[:port]/PATH --cost=100
reboot:安裝完成以後從新啓動
halt/poweroff:安裝完成以後關閉系統
url:指明安裝時使用的倉庫repository,但必須使用url格式;
url --url=http://host[:port]/PATH
firstboot:控制首次啓動
firstboot --disable
腳本段:
%pre:安裝前腳本的開始部分
運行環境:運行於安裝介質上的微型Linux系統環境;
%end
%post:安裝後腳本的開始部分
運行環境:安裝之後的操做系統
%end
程序包/程序包組段:指明要安裝的程序包或程序包組以及不安裝程序包;
%packages
@PACK_GROUP_NAME:安裝一個程序包組
PACK_NAME:安裝單個指定的程序包
-PACK_NAME:明確指出不安裝的程序包;有時即使明確指出該項,被指定的程序包也可能會被安裝上;
%end
如何建立kickstart文件:
1.直接以anaconda-ks.cfg爲模版,複製以後修改便可;
2.可使用工具來建立:
若是命令不存在,則yum install system-config-kickstart安裝便可;
# system-config-kickstart &
能夠全新建立,也能夠依據其餘的ks文件(如anaconda-ks.cfg)來修改生成新的配置文件;
3.檢測ks文件的語法是否存在錯誤:
ksvalidator
若是該命令不存在,能夠安裝pykickstart-1.74.20-1.el6.noarch
http://172.16.72.1/ks.cfg
利用一臺CentOS7構建web server,方法以下:
臨時清理防火牆規則,並將selinux設置爲permissive模式:
~]# iptables -F
~]# setenforce 0
啓動WEB服務
~]# systemctl start httpd.service
查看web服務的運行狀態,只要有綠色文字顯示的active(running),即爲服務正常啓動;
~]# systemctl status httpd.service
爲CentOS 6提供repository
~]# mkdir /var/www/html/centos_6_repo
~]# mount /dev/sr0 /mnt/cdrom
注意:光驅中放的是CentOS6的安裝光盤的CD1;
~]# cp -a /mnt/cdrom/* /var/www/html/centos_6_repo
到此,web服務器的配置完成;
利用一臺已經安裝好的CentOS 6操做系統,建立啓動光盤:
將下述內容寫入kickstart文件;
~]# vim /root/centos6-ks.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Install OS instead of upgrade
install
# Use network installation
network --onboot yes --device eth0 --bootproto dhcp
url --url="http://172.16.72.1/myrepo"
# Root password
rootpw --iscrypted $1$iRHppr42$VMesh73wBqhUTjKp6OYOD.
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="rhgb crashkernel=auto quiet" --location=mbr --driveorder="sda"
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part pv.008 --size=61440
volgroup myvg --pesize=4096 pv.008
logvol / --fstype=ext4 --name=root --vgname=myvg --size=20480
logvol swap --name=swap --vgname=myvg --size=2048
logvol /usr --fstype=ext4 --name=usr --vgname=myvg --size=10240
logvol /var --fstype=ext4 --name=var --vgname=myvg --size=20480
#repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100
%post
echo -e 'Qhdlink Linux for Learning Services\nhttp://www.linklinux.com\n' >> /etc/issue
sed -i '1,$s@id:[0-9]:initdefault:@id:3:initdefault:@g' /etc/inittab
ifconfig eth0 172.16.69.2/16
%end
%packages
@base
@core
@debugging
@basic-desktop
@desktop-debugging
@desktop-platform
@desktop-platform-devel
@development
@directory-client
@fonts
@general-desktop
@graphical-admin-tools
@input-methods
@internet-applications
@internet-browser
@java-platform
@legacy-x
@network-file-system-client
@office-suite
@print-client
@remote-desktop-clients
@server-platform
@server-platform-devel
@server-policy
@workstation-policy
@x11
mtools
pax
python-dmidecode
oddjob
wodim
sgpio
genisop_w_picpath
device-mapper-persistent-data
systemtap-client
abrt-gui
desktop-file-utils
jpackage-utils
samba-winbind
certmonger
pam_krb5
krb5-workstation
openmotif
libXmu
libXp
%end
建立引導光盤:
~]# mkdir myiso
~]# cp -r /mnt/cdrom/isolinux /root/myiso/
注意:這樣的複製方法是將isolinux目錄直接複製到myiso目錄中,也就是說isolinux是myiso的子目錄;
~]# vim /root/myiso/isolinux/isolinux.cfg
label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append initrd=initrd.img ks=cdrom:/centos6-ks.cfg
~]# cp /root/centos6-ks.cfg /root/myiso/
~]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 6 x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso myiso/
建立U盤啓動盤
方法一:
~]# dd if=/dev/sr0 of=/dev/sdb
方法二:
~]# fdisk /dev/sdb (將整個U盤分爲一個分區,並將其分區類型修改成vfat,即在fdisk交互式模式中使用t --> b命令完成轉換)
~]# mkfs.vfat /dev/sdb1
~]# mount /dev/sdb1 /mnt/usb
~]# mkidr -p /mnt/usb/grub
~]# cp /mnt/cdrom/isolinux/{vmlinuz,initrd.img} /mnt/usb
~]# vim /mnt/usb/grub/grub.conf
default=0
timeout=5
title the linux boot from usb
root (hd0,0)
kernel /vmlinuz
initrd /initrd.img ks=http://172.16.72.1/ks.cfg (將centos6-ks.cfg文件放置於CentOS7的/var/www/html目錄中,更名爲ks.cfg便可)
~]# grub
grub> root (hd1,0)
grub> setup (hd1)