ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

cobbler进阶

2020-11-24 17:30:22  阅读:454  来源: 互联网

标签:进阶 lib centos 64 var cobbler x86


文章目录


在这里插入图片描述

1. 用脚本来自动创建虚拟机

1. 查看vm6在哪儿

[root@localhost ~]# find / -name centos-7*
/var/lib/tftpboot/images/centos-7-x86_64
/var/lib/cobbler/config/distros.d/centos-7-x86_64.json
/var/lib/cobbler/config/profiles.d/centos-7-x86_64.json
/var/lib/cobbler/kickstarts/centos-7-x86_64.ks
/var/www/cobbler/images/centos-7-x86_64
/var/www/cobbler/ks_mirror/config/centos-7-x86_64.repo
/var/www/cobbler/ks_mirror/centos-7-x86_64
/var/www/cobbler/links/centos-7-x86_64
[root@localhost ~]# cd /var/lib/cobbler/config/
[root@localhost config]# pwd
/var/lib/cobbler/config
[root@localhost config]# ls
distros.d  images.d       packages.d  repos.d
files.d    mgmtclasses.d  profiles.d  systems.d
[root@localhost config]# ls systems.d/
vm6.json

2. 生成一台新虚拟机,获取MAC地址

在这里插入图片描述

3. 写脚本


[root@localhost ~]# mkdir /scripts
[root@localhost ~]# cd /scripts/
[root@localhost scripts]# ls

[root@localhost systems.d]# cat vm6.json  查看vm6,将这些内容复制到脚本里
{"comment": "", "status": "production", "kickstart": "/var/lib/cobbler/kickstarts/centos-7-x86_64.ks", "name_servers_search": [], "ks_meta": {}, "kernel_options_post": {}, "image": "", "redhat_management_key": "<<inherit>>", "virt_path": "<<inherit>>", "power_user": "", "kernel_options": {"biosdevname": "0", "net.ifnames": "0"}, "ctime": 1606202644.640662, "name_servers": ["114.114.114.114"], "mtime": 1606202644.640662, "enable_gpxe": false, "template_files": {}, "gateway": "192.168.50.2", "uid": "MTYwNjIwMjY0NC42NDYzNDIwMDIuNTUzMzI", "virt_auto_boot": 0, "power_type": "ipmitool", "virt_cpus": "<<inherit>>", "mgmt_parameters": "<<inherit>>", "boot_files": {}, "hostname": "maqiang", "repos_enabled": false, "mgmt_classes": [], "power_pass": "", "netboot_enabled": true, "ipv6_autoconfiguration": false, "profile": "centos-7-x86_64", "virt_type": "xenpv", "interfaces": {"eth0": {"ipv6_address": "", "interface_type": "", "static": true, "cnames": [], "mtu": "", "management": false, "interface_master": "", "mac_address": "00:50:56:39:76:A5", "ipv6_prefix": "", "virt_bridge": "xenbr0", "netmask": "255.255.255.0", "bonding_opts": "", "ip_address": "192.168.50.250", "dhcp_tag": "", "static_routes": [], "ipv6_mtu": "", "ipv6_static_routes": [], "if_gateway": "", "dns_name": "", "bridge_opts": "", "connected_mode": false, "ipv6_secondaries": [], "ipv6_default_gateway": ""}}, "power_address": "", "proxy": "<<inherit>>", "fetchable_files": {}, "virt_file_size": "<<inherit>>", "ldap_enabled": false, "monit_enabled": false, "ipv6_default_device": "", "virt_pxe_boot": 0, "virt_disk_driver": "<<inherit>>", "owners": "<<inherit>>", "name": "vm6", "virt_ram": "<<inherit>>", "power_id": "", "server": "<<inherit>>", "redhat_management_server": "<<inherit>>", "depth": 2, "ldap_type": "authconfig", "template_remote_kickstarts": 0}[root@localhost systems.d]# 

写脚本
[root@localhost scripts]# vim create_cobbler_system.sh               
#!/bin/bash
{
        "comment": "",
        "status": "production",
        "kickstart": "/var/lib/cobbler/kickstarts/centos-7-x86_64.ks",
        "name_servers_search": [],
        "ks_meta": {},
        "kernel_options_post": {},
        "image": "",
        "redhat_management_key": "<<inherit>>",
        "virt_path": "<<inherit>>",
        "power_user": "",
        "kernel_options": {
                "biosdevname": "0",
                "net.ifnames": "0"
        },
        "ctime": 1606202644.640662,
        "name_servers": ["114.114.114.114"],
        "mtime": 1606202644.640662,
        "enable_gpxe": false,
        "template_files": {},
        "gateway": "192.168.50.2",
        "uid": "MTYwNjIwMjY0NC42NDYzNDIwMDIuNTUzMzI",
        "virt_auto_boot": 0,
        "power_type": "ipmitool",
        "virt_cpus": "<<inherit>>",
        "mgmt_parameters": "<<inherit>>",
        "boot_files": {},
        "hostname": "node7.example.com",                  将名字改为7
        "repos_enabled": false,
        "mgmt_classes": [],
        "power_pass": "",
        "netboot_enabled": true,
        "ipv6_autoconfiguration": false,
        "profile": "centos-7-x86_64",
        "virt_type": "xenpv",
        "interfaces": {
                "eth0": {
                        "ipv6_address": "",
                        "interface_type": "",
                        "static": true,
                        "cnames": [],
                        "mtu": "",
                        "management": false,
                        "interface_master": "",
                        "mac_address": "00:50:56:27:08:EF",            修改MAC地址,就是刚才新创建的虚拟机MAC地址
                        "ipv6_prefix": "",
                        "virt_bridge": "xenbr0",
                        "netmask": "255.255.255.0",
                        "bonding_opts": "",
                        "ip_address": "192.168.50.251",            改ip为251,之前是250
                        "dhcp_tag": "",
                        "static_routes": [],
                        "ipv6_mtu": "",
                        "ipv6_static_routes": [],
                        "if_gateway": "",
                        "dns_name": "",
                        "bridge_opts": "",
                        "connected_mode": false,
                        "ipv6_secondaries": [],
                        "ipv6_default_gateway": ""
                }
        },
        "power_address": "",
        "proxy": "<<inherit>>",
        "fetchable_files": {},
        "virt_file_size": "<<inherit>>",
        "ldap_enabled": false,
        "monit_enabled": false,
        "ipv6_default_device": "",
        "virt_pxe_boot": 0,
        "virt_disk_driver": "<<inherit>>",
        "owners": "<<inherit>>",
        "name": "vm7",                                    将名字改为vm7
        "virt_ram": "<<inherit>>",
        "power_id": "",
        "server": "<<inherit>>",
        "redhat_management_server": "<<inherit>>",
        "depth": 2,
        "ldap_type": "authconfig",
        "template_remote_kickstarts": 0
}

EOF

执行脚本
[root@localhost scripts]# bash create_cobbler_system.sh 


[root@localhost systems.d]# ls
vm6.json  vm7.json

4. 重启服务

[root@localhost systems.d]# systemctl restart cobblerd
[root@localhost systems.d]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      5      127.0.0.1:25151               *:*                  
LISTEN     0      5       *:873                 *:*                  
LISTEN     0      128     *:22                  *:*                  
LISTEN     0      100    127.0.0.1:25                  *:*                  
LISTEN     0      5      :::873                :::*                  
LISTEN     0      128    :::80                 :::*                  
LISTEN     0      128    :::22                 :::*                  
LISTEN     0      100       ::1:25                 :::*                  
LISTEN     0      128    :::443                :::*      

5. 同步cobbler


[root@localhost systems.d]# cobbler sync
task started: 2020-11-24_163608_sync
task started (id=Sync, time=Tue Nov 24 16:36:08 2020)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos-7-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-39-76-a5
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/01-00-50-56-39-76-A5
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos-7-x86_64/initrd.img
copying images
generating PXE configuration files
generating: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-39-76-a5
generating: /var/lib/tftpboot/grub/01-00-50-56-39-76-A5
generating: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-27-08-ef
generating: /var/lib/tftpboot/grub/01-00-50-56-27-08-EF
generating PXE menu structure
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos-7-x86_64/initrd.img
Writing template files for centos-7-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos-7-x86_64
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout: 
received on stderr: 
running: service dhcpd restart
received on stdout: 
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service

running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

6. 重新登陆cobbler_web页面会有vm7生成

在这里插入图片描述

2. 删除vm6

  1. 删除vm6.json
[root@localhost systems.d]# ls
vm6.json  vm7.json
[root@localhost systems.d]# rm -rf vm6.json 
[root@localhost systems.d]# ls
vm7.json

重启
[root@localhost systems.d]# systemctl restart cobblerd

同步
[root@localhost systems.d]# cobbler sync
task started: 2020-11-24_165654_sync
task started (id=Sync, time=Tue Nov 24 16:56:54 2020)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos-7-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-39-76-a5
removing: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-27-08-ef
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/01-00-50-56-39-76-A5
removing: /var/lib/tftpboot/grub/01-00-50-56-27-08-EF
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos-7-x86_64/initrd.img
copying images
generating PXE configuration files
generating: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-27-08-ef
generating: /var/lib/tftpboot/grub/01-00-50-56-27-08-EF
generating PXE menu structure
copying files for distro: centos-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos-7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos-7-x86_64/initrd.img
Writing template files for centos-7-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos-7-x86_64
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout: 
received on stderr: 
running: service dhcpd restart
received on stdout: 
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service

running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***
[root@localhost systems.d]# 

  1. 重新登陆cobbler_web查看vm6已被删除
    在这里插入图片描述

3. 开启vm7验证

在这里插入图片描述

标签:进阶,lib,centos,64,var,cobbler,x86
来源: https://blog.csdn.net/yi_qingjun/article/details/110085414

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有