服务器上线搭建系统环境

服务器上线搭建系统环境

场景:对新采购的一批(较大量)物理服务器搭建系统环境(以CentOS7.6为例)

需求:

1.根据现有结构部署工具(PXE+kickstart);

2.结合应用系统需求定制部署模版;

3.制作系统优化等一键执行脚本;

4.自动化部署实施;

5.根据定制的优化内容对自动化部署效果进行检验;

一、PXE的原理

PXE是在没有软驱、硬盘、CD-ROM的情况下引导计算机的一种方式,也就是BIOS将使用PXE协议从网络引导。
整个安装的过程是这样的:
  1. =>(在已做完radi)PXE网卡启动 => DHCP获得IP地址
  2. => 从TFTP上下载 pxelinux.0、vmlinuz、initr.img 等 => 引导系统进入安装步骤
  3. => 通过PEX linux 下载ks.cfg文件并跟据ks.cfg自动化安装系统 => 完成。

二、准备

1、若是虚拟机测试,先在编辑->虚拟网络编辑器->关闭NAT网络的DHCP功能
2、环境准备:配置一台服务器(192.168.10.12),需要支持dhcp,ftp/http,tftp
      另外根据需要制作相应的kickstart(ks.cfg)文件。关闭防火墙和selinux

三、配置

1、配置DHCP服务(udp/67)

# yum -y install dhcp
# vim /etc/dhcp/dhcp.conf
subnet 192.168.10.0 netmask 255.255.255.0 {
  range 192.168.10.192 192.168.10.200;
  option domain-name-servers 223.5.5.5;
  option routers 192.168.10.2;
  next-server 192.168.10.12;
  filename "pxelinux.0";
}

# systemctl start dhcpd

# netstat -antpu |grep dhcpd

2、配置tftp服务(udp/69) 、 ftp服务(tcp/20)

# yum -y install tftp-server vsftpd

# vim /etc/xinetd.d/tftp

disable = no

# systemctl restart tftp 

# systemctl restart vsftpd 

 3、准备yum源文件及kickstart文件

 

  

  

 

ks.cfg文件

#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use network installation media
url --url="ftp://192.168.10.12/cdrom"
# Use graphical install
# graphical
# Run the Setup Agent on first boot
firstboot --enable
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8

# Network information
network  --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --no-activate
#network  --bootproto=dhcp --device=em2 --onboot=off --ipv6=auto
#network  --bootproto=dhcp --device=em3 --onboot=off --ipv6=auto
#network  --bootproto=dhcp --device=em4 --onboot=off --ipv6=auto
network  --hostname=localhost.localdomain

# Root password
rootpw --iscrypted $6$ju0RQ8TVh7OXiVdG$B/XV/NS9KEvvfNafLOoIqeJkefzhAdQTIuCGyrOKTFYdyL8yR6Gmg.TV6g8Eos1L2ya6HM.1KH1EElowvaGEu0
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel --drives=sda
selinux --disabled
firewall --disabled
user --group=wheel --name=tony --gecos="tony"
reboot

# Disk partitioning information //磁盘为50G的硬盘,这里根据自己来进行修改
part /boot --fstype="xfs" --size=200
part / --fstype="xfs" --size=20480
part swap --fstype="swap" --size=2048
part /usr --fstype="xfs" --size=20480
part /tmp --fstype="xfs" --grow --size=1

%packages
@^minimal
#@core
#@base
%end

%post
yum -y install wget
mkdir /tmp/repo_bak
mv /etc/yum.repos.d/* /tmp/repo_bak
cd /etc/yum.repos.d/
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all && yum makecache
yum install -y epel-release
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum makecache
yum -y install ansible
yum -y install vim
systemctl disable postfix.service

dir=/etc/sysconfig/network-scripts
ifcfg=ens33
[ ! -f /usr/sbin/ifconfig ] && yum -y install net-tools  &>/dev/null
ipaddr=$(ifconfig $ifcfg | grep "inet " | awk '{print $2}')
netmask=$(ifconfig $ifcfg | grep "inet " | awk '{print $4}')
gateway=$(ip route show | sed -n 1p | awk '{print $3}')
mv -f $dir/ifcfg-$ifcfg $dir/ifcfg-$ifcfg.bak
cat > $dir/ifcfg-$ifcfg <<eof
TYPE=Ethernet
BOOTPROTO=none
PEERDNS=yes
NAME="$ifcfg"
DEVICE="$ifcfg"
ONBOOT="yes"
IPADDR=$ipaddr
NETMASK=$netmask
GATEWAY=$gateway
HWADDR=$(cat /sys/class/net/$ifcfg/address)
DNS1=114.114.114.114
DNS2=8.8.8.8
eof
systemctl restart network
%end

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值