最も完全な自動システムインストールcentos。、kickstar + PXE。centosシステムの自動インストール(中央)

起動可能なCDとUディスクを作成する

カスタマイズされたインストールCDをキックスタートと組み合わせて、CDブートに基づく半自動インストールを実現できます

実装プロセス

[root@centos8 ~]#mkdir –pv /data/myiso
[root@centos8 ~]#cp -r /mnt/isolinux/ /data/myiso/ #复制目录到光盘文件 -r 递归复制
[root@centos8 ~]#tree /data/myiso/
/data/myiso/
└── isolinux
 ├── boot.cat
 ├── boot.msg
 ├── grub.conf
 ├── initrd.img
 ├── isolinux.bin
 ├── isolinux.cfg
 ├── ldlinux.c32
 ├── libcom32.c32
 ├── libutil.c32
 ├── memtest
 ├── splash.png
 ├── TRANS.TBL
 ├── vesamenu.c32
 └── vmlinuz
1 directory, 14 files
[root@centos8 ~]#vim /data/myiso/isolinux/isolinux.cfg
#方法1:应答方件放在ISO文件里
label linux
menu label ^Auto Install CentOS Linux 8
kernel vmlinuz
 initrd=initrd.img text ks=cdrom:/myks.cfg
 
#方法2:应答方件放在http服务器上
label linux
menu label ^Auto Install CentOS Linux 8
kernel vmlinuz
append initrd=initrd.img quiet ks=http://10.0.0.80/ksdir/centos8.cfg

label rescue #  救援模式
menu label ^Rescue a CentOS Linux system
kernel vmlinuz
append initrd=initrd.img inst.repo=http://10.0.0.80/centos/8/os/x86_64/ rescue
quiet

label local     #本地硬盘启动
menu default
menu label Boot from ^local drive
localboot 0xffff

[root@centos8 ~]#cp /root/myks.cfg /data/myiso/
[root@centos8 ~]#dnf -y install mkisofs
[root@centos8 ~]#mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 8.0 x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso /data/myiso/
注意:以上相对路径都是相对于光盘的根,和工作目录无关

mkisofsオプションの説明
最も完全な自動システムインストールcentos。、kickstar + PXE。centosシステムの自動インストール(中央)

DHCPサービスを実装する

ホストは、次の2つの方法でネットワーク構成を取得できます。

  • 静的割り当て

  • 動的取得:

    bootp:ブートプロトコルのMACとIPは静的に1対1で対応

    dhcp:拡張bootp、静的および動的をサポート

4.1 DHCPの動作原理

DHCP:動的ホスト構成プロトコル、動的ホスト構成プロトコル
UDPプロトコル、C / Sモード、dhcpサーバー:67 / udp、dhcpv4cサーバー

クライアント:68 / udp、dhcpv6クライアント:546 / udpクライアント

主目的:

  • 内部ネットワークおよびネットワークサービスプロバイダーがユーザーにIPアドレスを自動的に割り当てるために使用されます
  • すべてのコンピュータを集中管理する手段として内部ネットワーク管理者に使用されます
  • 自動設置システム
  • IPV4リソース不足の問題を解決する

DHCPメッセージには8つのタイプがあります。

  • DHCP DISCOVER:クライアントからサーバーへ
  • DHCPオファー:サーバーからクライアント
  • DHCP要求:クライアントからサーバーへ
  • DHCP ACK:サーバーからクライアントへ
  • DHCP NAK:サーバーからクライアントへ、適切なIPアドレスを割り当てることができないことをユーザーに通知します
  • DHCP DECLINE:クライアントからサーバーへ、アドレスが使用されたことを示します
  • DHCP RELEASE:クライアントからサーバーへ、ネットワークアドレスを放棄し、残りのリース時間をキャンセル
  • DHCP INFORM:クライアントからサーバー、クライアントがDHCPサーバーからより詳細な構成情報を取得する必要がある場合、サーバーに通知メッセージを送信して要求します。これはほとんど使用されません。

DHCPサービスリースの更新

  • 50%:リース時間が50%に達し、新しいDHCPREQUEST要求がDHCPサーバーに送信されたときにリースが更新されます。dhcpサービスに拒否の理由がない場合は、DHCPACKメッセージで応答します。DHCPクライアントは応答メッセージを受信すると、新しいリース期間を再開します
  • 87.5%:DHCPサーバーが以前にリース更新要求に応答しなかった場合、ホストはリース期間の7/8後に別のブロードキャスト要求を送信します

同じネットワークセグメント上の複数のDHCPサービス

  • DHCPサービスはローカルに基づいている必要があります
  • 先着順の原則

クロスネットワークセグメント

  • RFC 1542準拠ルーター
  • dhcpリレーエージェント:リレーエージェント

関連契約

  • arp
  • rarp

リース期間:

  • 長いリース期間:IPは比較的安定しており、ネットワークリソースの消費量は少ないですが、IPリソースが浪費されています

  • 短期リース:IPは比較的不安定で、ネットワークリソースの消費量が多くなりますが、IPリソースを利用でき、IPホスト
    サービスを少しだけ増やすことができます

DHCPの実装

注:DHCPサービスを実装する前に、まずネットワーク上の既存のDHCPサービスをオフにします。たとえば、マルウェアでDHCPを無効にして競合を防止します。

DHCPサービス実装ソフトウェア:

  • dhcp(CentOS 7より前)またはdhcp-server(CentOS 8のパッケージ名)
  • dnsmasq:dhcpおよびdns機能を提供できる小さなサービスソフトウェア

DHCP関連ドキュメントの構成

dhcpまたはdhcp-serverパッケージのファイル構成

  • / usr / sbin / dhcpd dhcpサービスのメインプログラム
  • /etc/dhcp/dhcpd.conf dhcpサービス構成ファイル
  • /usr/share/doc/dhcp-server/dhcpd.conf.example #dhcpサービス構成のサンプルファイル
  • /usr/lib/systemd/system/dhcpd.service #dhcpサービスサービスファイル
  • /var/lib/dh​​cpd/dhcpd.leasesアドレス割り当てレコード

dhcp-clientクライアントパッケージ

  • / usr / sbin / dhclient#クライアントプログラム
  • / var / lib / dhclient#自動的にIP情報ウィンドウツールを取得
    する

  • ipconfig / release #DHCPで取得したIPを解放し、再度IPを申請する
  • ipconfig / renew#リースの更新、更新

DHCPサーバー構成ファイル

ヘルプリファレンス:man 5 dhcpd.conf
/etc/dhcp/dhcpd.conf format
global configuration
subnet {
...
}
host {
}
Check syntax command:service dhcpd configtest(supported by CentOS 6 and previous versions)
例:dhcpd.conf

#安装服务
[root@Centos8 ~]#dnf install dhcp-server    #centos7 yum -y install dhcp 
[root@centos8 ~]#grep -v "#" /etc/dhcp/dhcpd.conf
option domain-name "magedu.org";
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.10  10.0.0.100;
range 10.0.0.110 10.0.0.200;
option routers 10.0.0.2;
next-server 10.0.0.8; 
filename "pxelinux.0";
}
host testclient {
hardware ethernet 00:0c:29:33:b4:1a;  #固定主机ip和DHCp 分配的地址
fixed-address 10.0.0.106;
default-lease-time 86400;  
max-lease-time 864000;
option routers 10.0.0.254;
option domain-name-servers 114.114.114.114,8.8.8.8 ;
option domain-name "magedu.net";
}

vimでは不要なフィールドに注意してください。カーソルから開始することに注意してください

.,$s/^\([^#]\)/#\1/

DHCP構成ファイルの他の構成オプション:

  • next-server:ブートファイルを提供するサーバーのIPアドレス

  • filename:ブートファイルの名前を示します

subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.10  192.168.100.100;
range 192.168.100.150  192.168.100.200;
option routers 192.168.100.1;
next-server 192.168.1.100; #TFTP服务器地址
filename "pxelinux.0";   #bootloader启动文件的名称
}

例:DHCPクライアントアプリケーションアドレスのプロセス

[root@centos7 ~]#dhclient -d
Internet Systems Consortium DHCP Client 4.2.5
Copyright 2004-2013 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/00:0c:29:01:f9:48
Sending on  LPF/eth0/00:0c:29:01:f9:48
Sending on  Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 8 (xid=0x4147178b)
DHCPREQUEST on eth0 to 255.255.255.255 port 67 (xid=0x4147178b)
DHCPOFFER from 10.0.0.8
DHCPACK from 10.0.0.8 (xid=0x4147178b)
bound to 10.0.0.100 -- renewal in 32740 seconds.

#DHCP客户端的日志
[root@centos7 ~]#ls /var/lib/dhclient/
dhclient.leases
[root@centos7 ~]#cat /var/lib/dhclient/dhclient.leases
lease {
interface "eth0";
fixed-address 10.0.0.100;
option subnet-mask 255.255.255.0;
option routers 10.0.0.2;
option dhcp-lease-time 86400;
option dhcp-message-type 5;
option domain-name-servers 180.76.76.76,223.5.5.5,223.6.6.6;
option dhcp-server-identifier 10.0.0.8;
option domain-name "magedu.com";
renew 3 2020/05/27 16:18:15;
rebind 4 2020/05/28 04:12:33;
expire 4 2020/05/28 07:12:33;
}
#DHCP服务器的日志
[root@centos8 ~]#tail -f /var/lib/dhcpd/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.3.6
# authoring-byte-order entry is generated, DO NOT DELETE
authoring-byte-order little-endian;
server-duid "\000\001\000\001&`\315\277\000\014)?s\225";
lease 10.0.0.100 {
starts 3 2020/05/27 07:12:33;
ends 4 2020/05/28 07:12:33;
cltt 3 2020/05/27 07:12:33;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 00:0c:29:01:f9:48;
}

例:DHCPサーバーが指定されたホストに固定IPを割り当てる

[root@centos8 ~]#vim /etc/dhcp/dhcpd.conf
subnet 10.0.0.0 netmask 255.255.255.0 {
 range 10.0.0.50 10.0.0.100;
 range 10.0.0.150 10.0.0.200;
 option routers 10.0.0.2;
 next-server 10.0.0.8;
 filename "pxelinux.0";
}
host test {
hardware ethernet 00:0c:29:cd:90:10;
fixed-address 10.0.0.123;
}

TFTPサービスを実装する

TFTPの紹介

TFTP:Trivial File Transfer Protocolは、ファイルを転送するための単純な高レベルプロトコルで、ファイル転送プロトコル(FTP)の
簡易バージョンです使いやすいが、ファイル転送プロトコル(FTP)よりも機能が低いファイルを転送するために使用されます
。TFTPとFTPの違い

1.セキュリティの違い
FTPは、適切な認証および暗号化プロトコルを使用してログインセキュリティをサポートします。接続の確立中にFTP認証と通信する必要
があります。TFTPはオープンプロトコルであり、セキュリティがなく、暗号化メカニズムがなく、TFTPと通信する必要はありません認証

2.トランスポート層プロトコルの違い
FTPはTCPをトランスポート層プロトコルとして使用し、TFTPはUDPをトランスポート層プロトコルとして使用します。

3.
FTPの使用の違いFTPは2つのポートを使用します:リスニングポートであるTCPポート21、ソース接続にはTCPポート20以上、TCPポート1024以上
。TFTPは、停止および待機モードのポートを1つだけ使用します:ポート:69 / udp

4. RFC
FTPとRFC FTPドキュメントの違いは、セキュリティ対策を網羅する他のRFCとのRFC 959ドキュメントに基づいており、TFTPはRFC 1350ドキュメントに基づいています。

5.実行コマンドの違い
FTPには多くの実行可能なコマンド(get、put、ls、dir、lcd)があり、ディレクトリなどを一覧表示
できます。TFTPには、実行できるコマンドが5つだけあります(rrq、wrq、data、ack、error)。

TFTPをインストールして使用する

インストールパッケージ:

  • tftp-server #serverパッケージ
  • tftp #clientパッケージ

例:tftpを使用してファイルをインストールおよびダウンロードする

#安装tftp服务器包
[root@centos8 ~]#dnf install tftp-server -y
[root@centos8 ~]#rpm -ql tftp-server
/usr/lib/.build-id
/usr/lib/.build-id/8c
/usr/lib/.build-id/8c/6921a9fb21d66da4fb299d516bce9ee6afea34
/usr/lib/systemd/system/tftp.service #tftp service文件
/usr/lib/systemd/system/tftp.socket #tftp socket文件
/usr/sbin/in.tftpd  #tftp主程序
/usr/share/doc/tftp-server
/usr/share/doc/tftp-server/CHANGES
/usr/share/doc/tftp-server/README
/usr/share/doc/tftp-server/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot  #TFTP服务数据目录
#启动服务
[root@centos8 ~]#systemctl enable --now tftp.service
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket →
/usr/lib/systemd/system/tftp.socket.
[root@centos8 ~]#ss -nulp|grep tftp
UNCONN  0     0             *:69           *:*   
users:(("in.tftpd",pid=10100,fd=0),("systemd",pid=1,fd=32))
#准备测试文件
[root@centos8 ~]#cp /etc/fstab /var/lib/tftpboot/f1.txt
[root@centos8 ~]#mkdir /var/lib/tftpboot/dir
[root@centos8 ~]#cp /etc/password /var/lib/tftpboot/dir/f2.txt
#安装tftp客户端包
[root@centos7 ~]#yum -y install tftp
#客户端通过tftp测试下载文件
[root@centos7 ~]#tftp 10.0.0.8
tftp> help
tftp-hpa 5.2
Commands may be abbreviated. Commands are:
connect connect to remote tftp
mode  set file transfer mode
put   send file
get   receive file
quit  exit tftp
verbose toggle verbose mode
trace  toggle packet tracing
literal toggle literal mode, ignore ':' in file name
status show current status
binary set mode to octet
ascii  set mode to netascii
rexmt  set per-packet transmission timeout
timeout set total retransmission timeout
?    print help information
help  print help information
tftp> get f1.txt
tftp> get dir/f2.txt
tftp> quit
[root@centos7 ~]#ls
anaconda-ks.cfg f1.txt f2.txt
#以下在tftp服务器执行,当用户下载文件后,可以观察到服务器端自动打开in.tftpd主程序
[root@centos8 tftpboot]#ps aux|grep in.tftp
root    1276  0.0  0.2  14912  1720 ?    Ss  12:03  0:00
/usr/sbin/in.tftpd -s /var/lib/tftpboot
root    1282  0.0  0.1  12108  960 pts/0  R+  12:04  0:00 grep --
color=auto in.tftp

おすすめ

転載: blog.51cto.com/13887323/2536268