之前使用Cobbler搭建自动安装系统,最近Cobbler网站无法访问,执行命令cobbler get-loaders下载获取PXE启动需要的文件时报404,即使下载成功,所有文件都为0字节,导致服务器安装系统自动获取到IP地址后卡住。不得已自己想办法解决,重新用Nginx DHCP TFTP Kickstart搭建了一套自动安装系统。Nginx安装和配置都挺简单,代替了Cobbler中使用的Apache。
虚拟环境
网段:192.168.200.0
掩码:255.255.255.0
网关:192.168.200.2
自动安装系统地址:192.168.200.10
DHCP分配地址范围:192.168.200.11 - 192.168.200.254
一、安装配置Nginx
下载编译安装Nginx
cd /App/src
wget
tar zxf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure \
--prefix=/App/nginx \
--without-http_access_module \
--without-http_auth_basic_module \
--without-http_browser_module \
--without-http_empty_gif_module \
--without-http_fastcgi_module \
--without-http_geo_module \
--without-http_limit_conn_module \
--without-http_limit_req_module \
--without-http_map_module \
--without-http_memcached_module \
--without-http_proxy_module \
--without-http_referer_module \
--without-http_rewrite_module \
--without-http_scgi_module \
--without-http_split_clients_module \
--without-http_ssi_module \
--without-http_upstream_hash_module \
--without-http_upstream_ip_hash_module \
--without-http_upstream_keepalive_module \
--without-http_upstream_least_conn_module \
--without-http_userid_module \
--without-http_uwsgi_module \
--without-mail_imap_module \
--without-mail_pop3_module \
--without-mail_smtp_module \
--without-pcre \
--without-poll_module \
--without-select_module
make && make install
修改Nginx配置文件/App/nginx/conf/nginx.conf
user nginx nginx;
worker_processes auto;
error_log logs/error.log error;
pid logs/nginx.pid;
worker_rlimit_nofile 65536;
events
{
use epoll;
accept_mutex off;
worker_connections 65536;
}
http
{
include mime.types;
default_type text/html;
charset UTF-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
open_file_cache max=65536 inactive=60s;
open_file_cache_valid 80s;
open_file_cache_min_uses 1;
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 logs/access.log main;
sendfile on;
server_tokens off;
keepalive_timeout 60;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 64k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain text/css application/json application/javascript application/xml;
server
{
listen 80;
server_name localhost;
index index.html;
root /App/web;
autoindex on;
}
}
新建Nginx运行账号和Web目录
useradd -s /bin/false -M nginx
mkdir -p /App/web
下载CentOS镜像iso文件并导入Web目录
cd /App/src
wget
mount -o loop CentOS-6.6-x86_64-bin-DVD1.iso /mnt
rsync -avP /mnt/ /App/web/CentOS-6.6-x86_64
启动Nginx
/App/nginx/sbin/nginx
二、安装配置DHCP
Yum安装dhcp服务端
yum -y install dhcp
修改配置dhcp文件/etc/dhcp/dhcpd.conf
allow booting;
allow bootp;
subnet 192.168.200.0 netmask 255.255.255.0 {
option routers 192.168.200.2;
option domain-name-servers 223.5.5.5,223.6.6.6;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.200.11 192.168.200.254;
filename "/pxelinux.0";
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.200.10;
}
启动dhcp服务
/etc/init.d/dhcpd start
三、安装配置TFTP
Yum安装tftp服务端
yum -y install tftp-server
修改tftp配置并启动xinetd服务
sed -i '/disable/s/yes/no/' /etc/xinetd.d/tftp
/etc/init.d/xinetd start
Yum安装syslinux引导加载程序,拷贝相关文件至tftp根目录