基于Rocky Linux 9搭建 dhcp+tftp+nginx+php-fpm 的ipxe自动引导服务器

第一步:安装相应软件

# 安装并设置自动启动
    dnf install dhcp-server ;systemctl enable dhcpd   ;systemctl start dhcpd
    dnf install tftp-server ;systemctl enable tftp    ;systemctl start tftp
    dnf install nginx       ;systemctl enable nginx   ;systemctl start nginx
    dnf install php-fpm     ;systemctl enable php-fpm ;systemctl start php-fpm

第二步:将引导服务器所需要的ipxe程序放置到tftp路径下,并重启tftp服务,(使用udp 69端口)

# 适用于bios方式的
    ls -l /var/lib/tftpboot/undionly.kpxe
    chown apache. /var/lib/tftpboot/undionly.kpxe
    chmod 644 /var/lib/tftpboot/undionly.kpxe

# 适用于uefi方式的
    ls -l /var/lib/tftpboot/ipxe.efi
    chown apache. /var/lib/tftpboot/ipxe.efi
    chmod 644 /var/lib/tftpboot/ipxe.efi

# 重启tftp服务
    systemctl restart tftp

第三步:修改dhcp配置文件,并重启dhcpd服务,(使用udp 67/68端口)

cat > /etc/dhcp/dhcpd.conf << EOF
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp-server/dhcpd.conf.example
#   see dhcpd.conf(5) man page

ddns-update-style interim;
allow booting;
allow bootp;
ignore client-updates;
set vendorclass = option vendor-class-identifier;
option space ipxe;
option ipxe-encap-opts code 175 = encapsulate ipxe;
option ipxe.priority code 1 = signed integer 8;
option pxe-system-type code 93 = unsigned integer 16;

subnet 0.0.0.0 netmask 0.0.0.0 {
     default-lease-time         21600;
     max-lease-time             43200;
    }
host generic1 {
    hardware ethernet 00:0C:29:3E:A7:3F;
    fixed-address 192.168.100.2;
    option host-name "pxe-ipxe-client-bios-01";
    option subnet-mask 255.255.255.0;
    option routers 192.168.100.1;
    if exists user-class and option user-class = "gPXE" {
        #option ipxe.priority 1;
        filename "http://192.168.100.1/auto-install/config/bootmenu.php";
    } else if exists user-class and option user-class = "iPXE" {
        #option ipxe.priority 1;
        filename "http://192.168.100.1/auto-install/config/bootmenu.php";
    } else {
        if option pxe-system-type = 00:07 or option pxe-system-type = 00:09 {
            filename "ipxe.efi";
        } else {
            filename "undionly.kpxe";
        }
    }
    next-server 192.168.100.1;
    option domain-name-servers 192.168.100.1;
}

host generic2 {
    hardware ethernet 00:0C:29:91:69:20;
    fixed-address 192.168.100.3;
    option host-name "pxe-ipxe-client-uefi-02";
    option subnet-mask 255.255.255.0;
    option routers 192.168.100.1;
    if exists user-class and option user-class = "gPXE" {
        #option ipxe.priority 1;
        filename "http://192.168.100.1/auto-install/config/bootmenu.php";
    } else if exists user-class and option user-class = "iPXE" {
        #option ipxe.priority 1;
        filename "http://192.168.100.1/auto-install/config/bootmenu.php";
    } else {
        if option pxe-system-type = 00:07 or option pxe-system-type = 00:09 {
            filename "ipxe.efi";
        } else {
            filename "undionly.kpxe";
        }
    }
    next-server 192.168.100.1;
    option domain-name-servers 192.168.100.1;
}
EOF

# 重启dhcpd服务
    systemctl restart dhcpd

配置nginx,(使用http 80端口)

cat > /etc/nginx/nginx.conf << EOF
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;

    keepalive_timeout   300s 300s;
    keepalive_requests 10000;

    types_hash_max_size 4096;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        root         /home;
        #root         /usr/share/nginx/html;
        location /auto-install {
            # 下面这个是真实的文件存放路径
            alias   /home/auto-install/;
            autoindex on;   #这行就是最关键的
            autoindex_exact_size off;  # 不显示目录数量限制
            autoindex_localtime on;  # 显示文件修改时间
            charset utf-8;
        }

        location ~ \.php$ {
            include fastcgi.conf;
            fastcgi_pass unix:/run/php-fpm/www.sock;
            #fastcgi_param SCRIPT_FILENAME /home/auto-install/config/$fastcgi_script_name;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
}
EOF
声明:本文为原创,作者为 辣条①号,转载时请保留本声明及附带文章链接:https://boke.wsfnk.com/archives/1275.html
谢谢你请我吃辣条谢谢你请我吃辣条

如果文章对你有帮助,欢迎点击上方按钮打赏作者

最后编辑于:2024/3/25作者: 辣条①号

目标:网络规划设计师、系统工程师、ceph存储工程师、云计算工程师。 不负遇见,不谈亏欠!

暂无评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

arrow grin ! ? cool roll eek evil razz mrgreen smile oops lol mad twisted wink idea cry shock neutral sad ???

文章目录