PXE部署安装Linux系统

pxe需要的软件

DHCP、TFTP、VSFTP/httpd、syslinux

DHCP : 分配网络参数 如 IP、子网掩码
TFTP :简单的文件传输协议,提供tftp服务器 
syslinux : 提供pxe 启动镜像
vsftp/httpd : 提供,网络安装的资源

目录结构

lpxelinux.0     可使用http和ftp协议,传输内核文件vmlinuz和最小化系统文件initrd
pxelinux.0       则必须使用tftp协议,传输内核文件vmlinuz和最小化系统文件initrd
vmlinuz文件:       是一个可引导的、压缩的内核映像文件vmlinuz,"vm"代表"Virtual Memory",Linux支持虚拟内存,能够使用硬盘空间作为虚拟内存,因此得名“vm”。
initrd.img文件:    是一个最小化的Linux系统initrd.img,在内核vmlinuz启动之后,加载initrd.img,从而安装其中的驱动

/web/repo               web根目录
/web/tftp/syslinux      tftp根目录
ks.cfg                  应答文件
default                 菜单文件

/web
└── repo
│    ├── centos
│    │    └──6.8
│    │    │   └───x86_64
│    │    │         ├──*
│    │    │         └──ks.cfg
│    │    └──7.2
│    │    │   └──x86_64
│    ├── othon
└── tftp
     └── syslinux
          ├──*
          └──pxelinux.cfg
              └── default

配置YUN

准备工作

如何查看服务器的系统版本

/usr/bin/python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)'

创建目录结构

mkdir -p /web/repo/{centos/{6.8/x86_64,7.2/x86_64},other}
yum install tree -y && tree /web/repo

将光盘的数据导入到对应的目录中

df
cp -Rfv /dvd/* /web/repo/centos/6.8/x86_64/

Centos 6.8 两张光盘数据处理:

先将 CentOS 6.8 x86_64 DVD1光盘文件,拷贝到/web/repo/centos/6.8/x86_64/目录中
cp -Rfv /dvd/* /web/repo/centos/6.8/x86_64/
再将 CentOS 6.8 x86_64DVD2光盘文件中的Packages目录中的rpm包,拷贝到/web/repo/centos/6.8/x86_64/Packages/目录中
cp -Rfv /dvd/* /web/repo/centos/6.8/x86_64/Packages

安装 createrepo 工具 <生成光盘数据的repo元数据>

yum install -y createrepo

centos 6.8 生成包组数据

查看包组信息

[root@li-pc x86_64]pwd
/web/repo/centos/6.8/x86_64
[root@li-pc x86_64]# grep -P "comps.xml$" repodata/TRANS.TBL
F D0DF041D.XML;1                                               d0df041d26b67f7e9b5c5828e5126ddbfeb3a998ec8e8426de2d260d8e1215f6-c6-x86_64-comps.xml
[root@li-pc x86_64]# 

生成软件包组数据

createrepo -g repodata/6221039e7e3dabf7d538c76571d82aaf42b6292b8f6fe6cf56b8fcf1cff3d3ab-comps-rhel6-Server.xml

createrepo -g repodata/为grep 查到的 一长串的字符文件

[root@li-pc x86_64]# createrepo -g repodata/d0df041d26b67f7e9b5c5828e5126ddbfeb3a998ec8e8426de2d260d8e1215f6-c6-x86_64-comps.xml .
Spawning worker 0 with 6696 pkgs
Workers Finished
Gathering worker results
输入的结果为:
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

使用createrepo 创建第三方的rpm 的repo 元数据

[root@localhost other]# cd /web/repo/other
[root@localhost other]# createrepo .

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost other]# 

配置TFTP

准备工作

创建: syslinux 文件的tftp根目录,用于tftp传送启动文件

mkdir -p /web/tftp/syslinux/

修改安全上下文

chcon -R -t tftpdir_rw_t /web/tftp/syslinux

安装TFTP软件

yum install -y tftp*

修改tftp配置文件

vim /etc/xinetd.d/tftp

service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /web/tftp/syslinux/    #tftp 共享路径
        disable                 = no  #开启
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

配置开机启动

chkconfig xinetd on

启动服务

service xinetd restart

防火墙允许通过

vi /etc/sysconfig/iptables
-A INPUT -m udp -p udp --dport 69 -j ACCEPT

重新加载防火墙配置文件

service iptables reload

安装syslinux

yum install gcc gcc-c++ nasm libuuid-devel mtools libc.so.6 libc.so.6* syslinux perl -y

cd ~
yum install wget -y     #安装wget 软件

获取syslinux源码包

wget https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.gz    

解压和编译安装syslinux

tar -axf syslinux-6.03.tar.gz
cd syslinux-6.03
make && make install        #编译并安装

备注:syslinux-6.03默认编译安装在</usr/share/syslinux>目录中

将syslinux数据复制到TFTP根目录

\cp -Rf /usr/share/syslinux/* /web/tftp/syslinux/

配置DHCP

安装DHCP

yum install dhcp -y

添加配置

vim /etc/dhcp/dhcpd.conf
option domain-name "test.com";
option domain-name-servers 192.168.100.8,114.114.114.114;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
## 定义:本地作用域
subnet 192.168.100.0 netmask 255.255.255.0 {
    range dynamic-bootp 192.168.100.100 192.168.100.200;
    option routers 192.168.100.1;
    option broadcast-address 192.168.100.255;
    next-server 192.168.100.8;
    filename "/lpxelinux.0";
}

#开机启动dhcpd
chkconfig dhcpd on
#启动dhcpd 服务
service dhcpd restart
#允许dhcp通过防火墙
vi /etc/sysconfig/iptables      
配置:    -A INPUT -m udp -p udp --dport 67 -j ACCEPT
service iptables  reload      #重新加载防火墙配置文件

配置DNS

安装软件

yum install bind* -y

备份dns配置文件

test -e /etc/named.conf.bak && echo "已经存在!" || \cp -rf /etc/named.conf /etc/named.conf.bak

修改 监听端口为any

sed -r -i '/[ \t]*listen-on[ \t]+[ \t]*port[ \t]+/c \\tlisten-on port 53 { any; };' /etc/named.conf
sed -r -i '/[ \t]*allow-query[ \t]+/c \\tallow-query { any; };' /etc/named.conf

添加区域文件

vim /etc/named.rfc1912.zones
zone "test.com" IN {
    type master;
    file "zone.test.com";
    allow-update { none; };
};

配置区域主机记录文件

cat > /var/named/zone.test.com <<EOF
\$TTL    3H
@ IN SOA dns.test.com. 156405304.qq.com. (
                                0
                                1D
                                1H
                                1W
                                3H )
@               IN      NS      dns.test.com.
dns             IN      A       192.168.100.8
pxe             IN      CNAME   dns.test.com.
repo             IN      CNAME   dns.test.com.
EOF

设置防火墙允许通过

vi /etc/sysconfig/iptables
-A INPUT -p tcp --dport 53 -j ACCEPT
-A INPUT -p udp --dport 53 -j ACCEPT
service iptables reload

修改本机的DNS为本服务器

vi /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=127.0.0.1
DNS2=114.114.114.114

重启网络服务

service network restart

开启启动DNS服务

chkconfig named on

开启启动DNS服务

service named restart

配置httpd服务

安装httpd

yum install httpd -y

备份httpd配置文件

test -f /etc/httpd/conf/httpd.conf.bak || \cp -f /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak

sed -r -i -e '/(^[ \t]*#|^[ \t]*$)/d' /etc/httpd/conf/httpd.conf

vi /etc/httpd/conf/httpd.conf

添加如下内容:

ServerName *:80
DocumentRoot "/web/repo"
<Directory /web/repo>
    Options Indexes FollowSymLinks
    IndexOptions Charset=UTF-8
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

修改安全上下文件

chcon -R -t httpd_sys_content_t /web/repo/

注释掉 vim /etc/httpd/conf.d/welcome.conf 欢迎文件中所有的内容,否则,就自动显示欢迎页面了。

开机启动

chkconfig httpd on

服务启动

service httpd restart

允许防火墙通过

vi /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 80 --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j ACCEPT

重新加载防火墙

service iptables reload

准备ks.cfg自动应答文件

为密码生产Hash值

[root@localhost other]# openssl passwd -crypt root
cuXs2IVTMhUAw

手动创建ks.cfg自动应答文件

创建应答文件

cd /web/repo/centos/6.8/x86_64/
vi ks.cfg

#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
firewall --enabled --ssh
install
url --url="http://192.168.100.8/centos/6.8/x86_64/"  #为安装包网络位置
rootpw --iscrypted TSampmgIqzVWA
auth  --useshadow  --passalgo=sha512
graphical
firstboot --disable
keyboard us
lang zh_CN
selinux --enforcing
logging --level=info
reboot
timezone --isUtc Asia/Shanghai
network  --bootproto=dhcp --device=eth0 --onboot=on
bootloader --location=mbr
zerombr
clearpart --all --initlabel 
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4000
part / --fstype="ext4" --grow --size=1

%packages
@core
@chinese-support
@server-policy
@workstation-policy
%end

准备default网络引导菜单

mkdir -p /web/tftp/syslinux/pxelinux.cfg/

创建引导文件

vim /web/repo/tftp/syslinux/pxelinux.cfg/default

default vesamenu.c32    
timeout 60
display http://pxe.test.com/centos/6.8/x86_64/isolinux/boot.msg
menu background http://pxe.test.com/centos/6.8/x86_64/isolinux/splash.jpg 
menu title Welcome to CentOS 6.8!!!
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 CentOS6.8-Auto
    menu label ^1 Auto-Install CentOS 6.8
    kernel  http://192.168.100.8/centos/6.8/x86_64/isolinux/vmlinuz  repo=http://192.168.100.8/centos/6.8/x86_64/ ip=dhcp  
    append  initrd=http://192.168.100.8/centos/6.8/x86_64/isolinux/initrd.img  ks=http://192.168.100.8/centos/6.8/x86_64/ks.cfg

客户机配置本机yum 源

vi /web/repo/create_lan_yum_repo.sh

#!/bin/bash
rpm -qa | grep redhat-lsb-core || yum install redhat-lsb-core -y
R=`lsb_release -a | awk -F "[: .\t]*" '/Release/{print $2 }'`
case $R in
"6")
echo "本系统是CentOS_$R系列!!!"
cat >/etc/yum.repos.d/lan_centos_dvd.repo<<EOF
    [00-lan-centos6.8_dvd]
    name= LAN-CentOS6.8-DVD
    baseurl=http://repo.test.com/centos/\$releasever.8/\$basearch/
    enabled=1
    gpgcheck=1
    gpgkey="http://repo.test.com/centos/\$releasever.8/\$basearch/RPM-GPG-KEY-CentOS-6"
    [00-lan-other]
    name= LAN-Other-RPM
    baseurl=http://repo.test.com/other
    enabled=1
    gpgcheck=0
    EOF
;;
"7")
echo "本系统是CentOS_$R系列!!!"
cat >/etc/yum.repos.d/lan_centos_dvd.repo<<EOF
    [00-lan-centos7.2_dvd]
    name= LAN-CentOS7.2-DVD
    baseurl=http://repo.test.com/centos/\$releasever.2/\$basearch/
    enabled=1
    gpgcheck=1
    gpgkey="http://repo.test.com/centos/\$releasever.2/\$basearch/RPM-GPG-KEY-CentOS-7"
    [00-lan-other]
    name= LAN-Other-RPM
    baseurl=http://repo.test.com/other
    enabled=1
    gpgcheck=0
    EOF
;;
esac
ll /etc/yum.repos.d
cat /etc/yum.repos.d/00_lan_centos_dvd.repo
yum clean all
yum makecache
yum repolist enable
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,290评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,399评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,021评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,034评论 0 207
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,412评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,651评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,902评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,605评论 0 199
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,339评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,586评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,076评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,400评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,060评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,083评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,851评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,685评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,595评论 2 270

推荐阅读更多精彩内容