@mrz1
2018-01-16T10:28:19.000000Z
字数 12740
阅读 2078
笔记
网络配置
静态指定
动态获取: bootp:boot protocol MAC与IP一一静态对应
dhcp:增强的bootp,动态
DHCP: (Dynamic Host Configuration Protocol)
动态主机配置协议
局域网协议,UDP协议
主要用途:
用于内部网络和网络服务供应商自动分配IP地址给用户
用于内部网络管理员作为对所有电脑作集中管理的手段
使用场景
自动化安装系统
解决IPV4资源不足问题
同网段多DHCP服务(广播机制)
DHCP服务必须基于本地
先到先得的原则
相关协议
Arp
rarp
跨网段
RFC 1542 Compliant Routers
dhcrelay: 中继代理
Linux DHCP协议的实现程序:dhcp, dnsmasq(dhcp,dns)
Dhcp Server
/usr/sbin/dhcpd
/etc/dhcp/dhcpd.conf--> /etc/rc.d/init.d/dhcpd
/etc/dhcp/dhcpd6.conf--> /etc/rc.d/init.d/dhcpd6
/usr/sbin/dhcrelay
/etc/rc.d/init.d/dhcrelay
dhcp server:67/udp
dhcp client: 68/udp
dhcpv6 client:546/udp
Dhcp client
dhclient
自动获取的IP信息:/var/lib/dhclient
/etc/dhcp/dhcpd.conf:
帮助参考:man 5 dhcpd.conf
全局配置
subnet {
...
}
host {
}
地址分配记录
/var/lib/dhcpd/dhcpd.leases
option domain-name "magedu.com";
option domain-name-servers 192.168.0.1,8.8.8.8;
default-lease-time 86400;
max-lease-time 86400;
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.1 192.168.100.200;
option routers 192.168.100.1;
}
yum install dhcp
rpm -ql dhcp //找到这两个
/etc/dhcp/dhcpd.conf
/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf //因为/etc/dhcp/dhcpd.conf是空的
编写/etc/dhcp/dhcpd.conf文件
[root@centos7 ~]#cat /etc/dhcp/dhcpd.conf
option domain-name "zhangqifei.com";
option domain-name-servers 114.114.114.114,8.8.8.8; //DNS解析
option routers 192.168.109.1;//全局默认网关
default-lease-time 84600; //有效期
max-lease-time 84600; //特殊要求最大有效期
log-facility local7;
subnet 192.168.109.0 netmask 255.255.255.0 { //网段
range 192.168.109.100 192.168.109.200; //分配ip范围 如果这里写网关,就是这些范围ip,外面的网关是全局的这里不设置网关会是全局网关
filename "pxelinux.0";/文件名网络中启动程序的文件名
next-server 192.168.100.100;(tftp)//程序的文件名地址
}
host fantasia { //绑定mac地址,分配默认ip
hardware ethernet 08:00:07:26:c0:a5;
fixed-address 192.168.109.101;
这里网关和DNS都可以单独设置
}
启动服务 systemctl start dhcpd
查看端口 ss -ntlup //服务器端udp67端口,客户端udp68端口
查看网关 route -n
查看DNS cat /etc/resolv.conf
dhcp数据库 /var/lib/dhcpd/dhcpd.leases
[root@centos7 ~]#cat /var/lib/dhcpd/dhcpd.leases //发放地址的
#lease 192.168.109.100 {
starts 6 2018/01/13 06:41:45;
ends 0 2018/01/14 06:11:45;
tstp 0 2018/01/14 06:11:45;
cltt 6 2018/01/13 06:41:45;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 00:0c:29:12:6c:bc;
}
[root@centos7 ~]#cat /var/lib/dhclient/dhclient-eth0.leases //接受地址的数据库 可以看到从哪里获取的多有信息
rpm -qi dnsmasq
)
安装前准备:关闭防火墙和SELINUX,DHCP服务器静态IP
安装软件包
httpd tftp-server dhcp syslinux system-config-kickstart
配置文件共享服务:
systemctl enable httpd
systemctl start httpd
mkdir /var/www/html/centos/7
mount /dev/sr0 /var/www/html/centos/7
准备kickstart文件
/var/www/html/ks/centos7.cfg 注意:权限
配置tftp服务
systemctl enable tftp.socket
systemctl start tftp.socket
配置DHCP服务
vim /etc/dhcp/dhcpd.conf
option domain-name "example.com";
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.1 192.168.100.200;
filename "pxelinux.0";
next-server 192.168.100.100;
}
systemctl enable dhcpd
systemctl start dhcpd
准备相关文件
mkdir /var/lib/tftpboot/pxelinux.cfg/
cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
cp /misc/cd/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/
cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
文件列表如下:
/var/lib/tftpboot/
├──initrd.img
├──menu.c32
├──pxelinux.0
├──pxelinux.cfg
└──default
├──vmlinuz
准备启动菜单
Vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 600
menu title PXE INSTALL MENU
label auto
menu label Auto Install CentOS 7
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.100.100/ks/centos7.cfg label manual
menu label Manual Install CentOS 7
kernel vmlinuz
append initrd=initrd.img inst.repo=http://192.168.100.100/centos/7
label local
menu default
menu label ^Boot from local drive
localboot 0xffff
安装前准备:关闭防火墙和SELINUX,DHCP服务器静态IP
安装相应软件包
1.yum install dhcp httpd tftp-server syslinux
2.chkconfig httpd on
chkconfig dhcpd on
chkconfig tftp on (因为tftp受xinetd管理所以xinetd也许启动)
chkconfig xinetd on 或者修改/etc/xinetd.d/tftp文件中disable=no
service httpd start
service xneted start
3.准备yum 源和相关目录
mkdir -pv /var/www/html/centos/{6,ks}
mount /dev/sr0 /var/www/html/centos/6
4.准备kickstart文件
/var/www/html/centos/ks/centos6.cfg
注意权限:
chmod 644 /var/www/html/centos/ks/centos6.cfg
5.准备相关的启动文件
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /misc/cd/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg/
cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
cp /misc/cd/isolinux/{vesamenu.c32,boot.msg,splash.jpg} /var/lib/tftpboot/
6.[root@centos7 ~]#Vim /var/lib/tftpboot/pxelinux.cfg/default(准备启动菜单文件)
default vesamenu.c32
timeout 60
display boot.msg
menu background splash.jpg
menu title Welcome to CentOS 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
menu title PXE INSTALL CentOS 6
label desktop
menu label ^Install desktop CentOS 7
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.109.143/ksdir/ks6-pxe.cfg
label mini
menu label install ^Mini CentOS 6
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.109.143/ksdir/ks6-mini.cfg
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
CentOS 6目录结构如下
[root@centos7 tftpboot]#tree
.
├── boot.msg
├── splash.jpg
├── initrd.img
├── pxelinux.0
├── vesamenu.c32
├── pxelinux.cfg
│ └── default
└── vmlinuz
配置dhcp服务
[root@centos7 ~]#vim /etc/dhcp/dhcpd.conf //编写这个文件
option domain-name "zhangqifei.com";
option domain-name-servers 114.114.114.114,8.8.8.8; //DNS解析
option routers 192.168.109.1;//全局默认网关
default-lease-time 84600; //有效期
max-lease-time 84600; //特殊要求最大有效期
log-facility local7;
subnet 192.168.109.0 netmask 255.255.255.0 { //网段
range 192.168.109.100 192.168.109.200; //分配ip范围 如果这里写网关,就是这些范围ip,外面的网关是全局的这里不设置网关会是全局网关
filename "pxelinux.0";/文件名网络中启动程序的文件名
next-server "192.168.109.143";(tftp)//程序的文件名地址
}
例也可以这样:
host fantasia { //绑定mac地址,分配默认ip
hardware ethernet 08:00:07:26:c0:a5;
fixed-address 192.168.109.101;
这里网关和DNS都可以单独设置
}
Cobbler:
- 快速网络安装linux操作系统的服务,支持众多的Linux发行版:Red Hat、Fedora、CentOS、Debian、Ubuntu和SuSE,也可以支持网络安装windows
- PXE的二次封装,将多种安装参数封装到一个菜单
- Python编写
- 提供了CLI和Web的管理形式
安装包
cobbler基于EPEL源
cobbler 服务集成(不需要可以不安装)
PXE
DHCP
rsync
Http
DNS
Kickstart
IPMI 电源管理
检查cobbler环境
cobbler check
安装:yum install cobbler dhcp
配置文件目录/etc/cobbler
/etc/cobbler/settings : cobbler 主配置文件
/etc/cobbler/iso/: iso模板配置文件
/etc/cobbler/pxe: pxe模板文件
/etc/cobbler/power: 电源配置文件
/etc/cobbler/user.conf: web服务授权配置文件
/etc/cobbler/users.digest: web访问的用户名密码配置文件
/etc/cobbler/dhcp.template: dhcp服务器的的配置末班
/etc/cobbler/dnsmasq.template: dns服务器的配置模板
/etc/cobbler/tftpd.template: tftp服务的配置模板
/etc/cobbler/modules.conf: 模块的配置文件
数据目录
/var/lib/cobbler/config/: 用于存放distros,system,profiles 等信息配置文件
/var/lib/cobbler/triggers/: 用于存放用户定义的cobbler命令
/var/lib/cobbler/kickstart/: 默认存放kickstart文件
/var/lib/cobbler/loaders/: 存放各种引导程序镜像目录
/var/www/cobbler/ks_mirror/: 导入的发行版系统的所有数据
/var/www/cobbler/images/ : 导入发行版的kernel和initrd镜像用于远程网络启动
/var/www/cobbler/repo_mirror/: yum 仓库存储目录
日志目录
/var/log/cobbler/installing: 客户端安装日志
/var/log/cobbler/cobbler.log : cobbler日志
systemctl enable cobblerd
cobbler commands介绍
cobbler check 核对当前设置是否有问题
cobbler list 列出所有的cobbler元素
cobbler report 列出元素的详细信息
cobbler sync 同步配置到数据目录,更改配置最好都要执行下
cobbler reposync 同步yum仓库
cobbler distro 查看导入的发行版系统信息
cobbler system 查看添加的系统信息
cobbler profile 查看配置信息
cobbler remove 删除对应列表 --name=名字
先删除 profile 在删除distro 列表名
cobbler profile rename --help 查看帮助
cobbler profile rename --name=原名字 --newname=新名字
/etc/cobbler/settings中重要的参数设置
default_password_crypted: "$1$gEc7ilpP$pg5iSOj/mlxTxEslhRvyp/"
manage_dhcp:1
manage_tftpd:1
pxe_just_once:1 下次在重装默认不会安装(怕覆盖你系统)
next_server:< tftp服务器的IP 地址>
server:<cobbler服务器的IP 地址>
[root@centos7 ~]#cobbler check
httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback:
Traceback (most recent call last): //这种重启httpd服务
[root@centos7 ~]#systemctl restart httpd
[root@centos7 ~]#systemctl status httpd
执行Cobbler check命令会报如下异常
[root@centos7 ~]#cobbler check
The following are potential configuration items that you may want to fix:
1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work. This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely. Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
Restart cobblerd and then run 'cobbler sync' to apply changes.
执行Cobbler check报错解决方式
1. 修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名(自己的ip 384行)
2. 修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址(自己的ip 272行)
3.change 'disable' to 'no' in /etc/xinetd.d/tftp centos7不用管
4. 如果当前节点可以访问互联网,执行“cobbler get-loaders”命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中
5 enable and start rsyncd.service with systemctl 用不到不用管
6 debian系统 不用管
7. 执行"openssl passwd -1"生成密码,
并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值
8.也不用管 集群相关
修改 /etc/cobbler/dhcp.tempplate 网段地址范围等 变量不用动执行cobbler sync 同步一下就行 默认dhcp启动
生成yum源 先挂载两张centos6、7盘在复制两张盘
cobbler import --path=/mnt/centos7/ --name=Centos-7.4
cobbler import --path=/mnt/centos6/ --name=Centos-6.9
复制完成就可以安装了
之后自己修改根据自己的需求配置应答文件
url --url=$tree 这里使用变量
下载启动菜单:
联网:cobbler get-loaders
不联网:cp/usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot
管理distro
cobbler import --name=centos-6.9-x86_64 --path=/media/cdrom--arch=x86_64
管理profile
cobbler profile add --name=centos-6.9-x86_64-basic--distro=centos-6.9-x86_64 --kickstart= /var/lib/cobbler/kickstarts/centos-6.9-x86_64.cfg
查看profiles
cobbler profile list //安装列表
cobbler distro list //yum源列表
查看引导文件
cat /var/lib/tftpboot/pxelinux.cfg/default
同步cobbler配置
cobbler sync
多系统引导方案
cobbler import --name=CentOS-7-x86_64 --path=/media/cdromcobbler distro listcobbler profile listcobbler sync
cobbler-web
提供cobbler的基于web管理界面,epel源
yum install cobbler-web
认证方式
认证方法配置文件:/etc/cobbler/modules.conf
支持多种认证方法:
authn_configfile
authn_pam
使用authn_configfile模块认证cobbler_web用户
vim /etc/cobbler/modules.conf
[authentication]
module=authn_configfile
创建其认证文件/etc/cobbler/users.digest,并添加所需的用户
htdigest -c /etc/cobbler/users.digest Cobbler admin
注意:添加第一个用户时,使用“-c”选项,后续添加其他用户时不要再使用,cobbler_web的realm只能为Cobbler
使用authn_pam模块认证cobbler_web用户
vim /etc/cobbler/modules.conf
[authentication]
module =authn_pam
创建cobbler用户:useradd -s /sbin/nologin cobbler
echo magedu |passwd --stdin cobbler
vim /etc/cobbler/users.conf
[admins]
admin = "cobbler"
Web访问cobbler
重启cobblerd服务
通过https://cobblerserver/cobbler_web访问