Nginx DHCP TFTP Kickstart搭建自动安装系统

简介:

        之前使用Cobbler搭建自动安装系统,最近Cobbler网站http://www.cobblerd.org/无法访问,执行命令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 http://nginx.org/download/nginx-1.8.0.tar.gz
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 http://mirrors.aliyun.com/centos/6.6/isos/x86_64/CentOS-6.6-x86_64-bin-DVD1.iso
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根目录

yum -y install syslinux
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cd /App/web/CentOS-6.6-x86_64/isolinux/
cp vesamenu.c32 boot.msg splash.jpg vmlinuz initrd.img  memtest /var/lib/tftpboot/
mkdir -p /var/lib/tftpboot/pxelinux.cfg
cp isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
  • 修改启动菜单/var/lib/tftpboot/pxelinux.cfg/default,特别注意menu default这个配置决定了默认启动哪个选项,如果是【label linux】下,服务器一旦重启将删除所有分区并格式化,非常危险,一定要修改此项。

default vesamenu.c32
prompt 0
timeout 60

display boot.msg

menu background splash.jpg
menu title Welcome to CentOS 6.6!
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 linux
  menu label ^Install or upgrade an existing system
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.200.10/CentOS-6.6-x86_64/ks.cfg ksdevice=em1 
label vesa
  menu label Install system with ^basic video driver
  kernel vmlinuz
  append initrd=initrd.img xdriver=vesa nomodeset
label rescue
  menu label ^Rescue installed system
  kernel vmlinuz
  append initrd=initrd.img rescue
label local
  menu label Boot from ^local drive
  menu default
  localboot 0xffff
label memtest86
  menu label ^Memory test
  kernel memtest
  append -



四、添加Kickstart配置

  • Web目录中添加kickstart配置文件/App/web/CentOS-6.6-x86_64/ks.cfg

install
keyboard us
lang zh_CN
url --url=http://192.168.200.10/CentOS-6.6-x86_64/
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw  --iscrypted $6$y0UTGMGnCEgUJmUB$IPcaQ8ipx24V8lAq.XepGoilvjXM9kFs5YrivQQoejYmLOmeVXSeM6IvzxtdsUJ0CFuTMzANEmlj5FOluuwy40
auth --useshadow --passalgo=sha512
reboot
firewall --disabled
firstboot --disable
selinux --disabled
logging --level=info
timezone  Asia/Shanghai
bootloader --location=mbr
zerombr yes
clearpart --all --initlabel
part /boot --fstype ext4 --size=200
part swap --size=2048
part / --fstype ext4 --size=200 --grow

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

%post
ServiceList=`chkconfig --list | grep '0' | awk '{print $1}' | grep -Ev 'sshd|network|crond|syslog'`
for Service in $ServiceList
do
/etc/init.d/$Service stop
chkconfig --level 0123456 $Service off
done

cat >> /etc/sysctl.conf << EOF
vm.swappiness = 0
net.core.rmem_default = 262144
net.core.rmem_max = 16777216
net.core.wmem_default = 262144
net.core.wmem_max = 16777216
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_max_tw_buckets = 10000
net.ipv4.ip_local_port_range = 1024 65500
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_mem = 786432 1048576 1572864
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
fs.inotify.max_user_watches = 1048576
EOF
sysctl -p

cat >> /etc/security/limits.conf << EOF
* - nofile 1048576
* - nproc  65536
* - stack  1024
EOF

cat >> /etc/profile << EOF
ulimit -n 1048576
ulimit -u 65536
ulimit -s 1024

alias grep='grep --color=auto'
export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
EOF

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0

sed -i 's/.*UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's/.*GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config
/etc/init.d/sshd restart

cat >> $HOME/.bash_profile << EOF
export PATH=/App/script:\$PATH
EOF

mkdir -p /App/script /App/src

mount --bind /dev/shm /tmp
echo "/bin/mount --bind /dev/shm /tmp" >> /etc/rc.local



五、检查相关服务监听端口

  • http:80、dhcp:67、tftp:69

netstat -tunlp | grep -E '(0.0.0.0:80|0.0.0.0:67|0.0.0.0:69)'

如下图说明各服务已监听

wKioL1W0emDyXQ6DAAHbEjM4D5A745.jpg






      本文转自dongsong1117 51CTO博客,原文链接:http://blog.51cto.com/dongsong/1678460,如需转载请自行联系原作者




相关文章
|
18天前
|
负载均衡 Java 应用服务中间件
nginx安装在linux上
nginx安装在linux上
43 2
|
24天前
|
应用服务中间件 nginx
树莓派安装Nginx服务结合内网穿透实现无公网IP远程访问
树莓派安装Nginx服务结合内网穿透实现无公网IP远程访问
|
4天前
|
应用服务中间件 nginx Docker
docker安装nginx
`docker search`找镜像,`pull`下载,后台 `-d` 运行容器,命名 `--name`,映射端口 `-p`。本机测试,确保服务器安全组开放端口,公网通过`http://ip:port`访问。用`docker stop id`停止容器。[查看详情](https://blog.csdn.net/javayoungcoolboy/article/details/134976510)
|
5天前
|
应用服务中间件 网络安全 nginx
nginx(1.13.7)首次安装出现:【make: *** 没有规则可以创建“default”需要的目标“build” 问题】解决措施
nginx(1.13.7)首次安装出现:【make: *** 没有规则可以创建“default”需要的目标“build” 问题】解决措施
|
8天前
|
Ubuntu 应用服务中间件 nginx
ubuntu编译安装nginx及安装nginx_upstream_check_module模块
以上是编译安装Nginx和安装 `nginx_upstream_check_module`模块的基本步骤。根据你的需求和环境,你可能需要进一步配置Nginx以满足特定的要求。
19 3
|
13天前
|
弹性计算 应用服务中间件 Shell
一键编译安装Nginx脚本
【4月更文挑战第30天】
22 1
|
14天前
|
关系型数据库 MySQL 应用服务中间件
centos7在线安装jdk1.8+tomcat+mysql8+nginx+docker
现在,你已经成功在CentOS 7上安装了JDK 1.8、Tomcat、MySQL 8、Nginx和Docker。你可以根据需要配置和使用这些服务。请注意,安装和配置这些服务的详细设置取决于你的具体需求。
52 2
|
16天前
|
监控 负载均衡 网络协议
|
18天前
|
负载均衡 前端开发 应用服务中间件
Nginx安装与使用
Nginx安装与使用
48 0
|
20天前
|
应用服务中间件 Linux 网络安全
【Linux】中如何安装nginx
【Linux】中如何安装nginx
38 0