zoukankan      html  css  js  c++  java
  • LinuxDay20——运维自动化之系统部署

    anaconda

    anaconda负责安装系统向导,默认为GUI界面,如果我们使用ks自动应答安装的话建议使用TUI界面来安装

    在安装启动界面我们可以按esc键来自己手动指定安装启动选项

    anaconda选项:

    1)linux askmethod 在稍后的安装中手动选择安装源

    本地光盘、硬盘、NFS、FTP、HTTP

    2)linux dd 加载驱动盘

    3)linux ks=xxx   指定安装ks文件

    • DVD drive: ks=cdrom:/PATH/TO/KICKSTART_FILE
    • Hard drive: ks=hd:device:/directory/KICKSTART_FILE
    • HTTP server: ks=http://host:port/path/to/KICKSTART_FILE
    • FTP server: ks=ftp://host:port/path/to/KICKSTART_FILE
    • HTTPS server: ks=https://host:port/path/to/KICKSTART_FILE
    • NFS server:ks=nfs:host:/path/to/KICKSTART_FILE

    4)linux nonet 不启用网络

    5)linux noprobe 不装载其他的硬件设备

    6)linux rescue 进入救援模式

    7)linux 正常安装

    8)local 从硬盘启动

    9)linux text 以字符界面安装

    10)linux ip={DHCP | 192.168.0.1} netmask=255.255.255.0 gateway=192.168.0.1 dns=114.114.114.114 ks=http://192.168.0.1/ks.cfg 设置IP并从网络获取ks文件

    11)linux ip={DHCP | 192.168.0.1} netmask=255.255.255.0 gateway=192.168.0.1 dns=114.114.114.114 repo=http://192.168.0.1  设置IP地址并指定从repo源安装

    • ip=IPADDR
    • netmask=MASK
    • gateway=GW
    • dns=DNS_SERVER_IP
    • ifname=NAME:MAC_ADDR

    12)linux vnc vncpassword="PASSWORD" 使用vnc调用安装界面

    在光盘下的isolinux/文件夹为anaconda的工作目录文件存放位置

    ls -l isolinux/
    -r--r--r--. 1 root root     2048 Sep  6  2017 boot.cat    模拟mbr文件
    -rw-r--r--. 1 root root       84 Sep  5  2017 boot.msg     
    -rw-r--r--. 1 root root      281 Sep  5  2017 grub.conf    grub的配置文件
    -rw-r--r--. 1 root root 48434768 Sep  5  2017 initrd.img    ramdisk文件
    -rw-r--r--. 1 root root    24576 Sep  5  2017 isolinux.bin    grub的第二阶段
    -rw-r--r--. 1 root root     3032 Sep  5  2017 isolinux.cfg    配置文件(启动菜单定制文件)
    -rw-r--r--. 1 root root   190896 Nov  6  2016 memtest    内存测试文件
    -rw-r--r--. 1 root root      186 Oct  1  2015 splash.png    背景图片
    -r--r--r--. 1 root root     2215 Sep  6  2017 TRANS.TBL
    -rw-r--r--. 1 root root   152976 Nov  6  2016 vesamenu.c32   光盘启动的图形界面菜单风格
    -rwxr-xr-x. 1 root root  5877760 Aug 23  2017 vmlinuz    内核文件
    

      启动菜单的配置文件isolinux/isolinux.cfg

    # cat isolinux/isolinux.cfg 
    default vesamenu.c32 提供图形菜单风格
    #prompt 1
    timeout 600 菜单选择超时时间
    
    display boot.msg
    
    menu background splash.jpg  背景图片
    menu title Welcome to CentOS 6.9!  菜单上方提示信息
    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
      menu default 默认选择
      kernel vmlinuz
      append initrd=initrd.img  向内核传递参数
    

      

    anaconda工作过程

    Anaconda安装系统分成三个阶段:

    1、安装前配置阶段

    安装过程使用的语言

    键盘类型

    安装目标存储设备

    Basic Storage:本地磁盘

    特殊设备:iSCSI

    设定主机名

    配置网络接口

    时区

    管理员密码

    设定分区方式及MBR的安装位置

    创建一个普通用户

    选定要安装的程序包

    2、安装阶段

    在目标磁盘创建分区,执行格式化操作等

    将选定的程序包安装至目标位置

    安装bootloader和initramfs

    3、图形模式首次启动

    iptables

    selinux

    core dump

     

    kickstart

    示例:使用 system-config-kickstart 来创建ks文件(CentOS7.x)

    1、配置yum,安装软件

    图形化界面:yum groupinstall desktop

    kickstart软件:yum system-config-kickstart

    2、图形化界面执行,并进行配置

    system-config-kickstart

    参考ks.cfg配置文件:

    #platform=x86, AMD64, or Intel EM64T
    #version=DEVEL
    # Install OS instead of upgrade
    install
    # Keyboard layouts
    keyboard 'us'
    # Root password
    rootpw --iscrypted $1$.4cA9H18$yFklftvKKTJ78OmWBqAPz1
    # System language
    lang en_US
    # System authorization information
    auth  --useshadow  --passalgo=sha512
    # Use CDROM installation media
    url --url="http://192.168.0.6/centos/7/"
    # Use text mode install
    text
    # SELinux configuration
    selinux --disabled
    # Do not configure the X Window System
    skipx
    
    # Firewall configuration
    firewall --disabled
    # Network information
    network  --bootproto=dhcp --device=eth0 --onboot=on
    # Reboot after installation
    reboot
    # System timezone
    timezone Asia/Shanghai
    # System bootloader configuration
    bootloader --append="net.ifnames=0" --location=mbr
    # Clear the Master Boot Record
    zerombr
    # Partition clearing information
    clearpart --all --initlabel
    # Disk partitioning information
    autopart
    
    %packages
    @core
    %end
    

      

    制作自动应答光盘

    我们现在已经有一个ks文件了,接下来需要把ks文件加入到光盘文件中来实现自动安装

    1、准备安装文件

    [root@centos7 ~]# mkdir -p /data/myiso
    [root@centos7 ~]# cp -r /media/cdrom/ /data/myiso/
    [root@centos7 ~]# cp /data/ks_7_mini.cfg /data/myiso/cdrom/ksdir/

    2、编辑配置文件

    [root@centos7 ~]# vim /data/myiso/cdrom/isolinux/isolinux.cfg #增加一个label
    label linux
      menu label ^Ks_Install CentOS 7_mini
      kernel vmlinuz
      append initrd=initrd.img text ks=cdrom:/ksdir/ks_7_mini.cfg

    3、制作ISO文件

    [root@centos7 ~]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS_7.5_x86_64" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /data/CentOS-7.5-x86_64.iso /data/myiso/cdrom

    mkisofs命令

    • -o 指定映像文件的名称
    • -b 指定在制作可开机光盘时所需的开机映像文件
    • -c 制作可开机光盘时,会将开机映像文件中的 no-eltorito-catalog 全部内容作成一个文件
    • -no-emul-boot 非模拟模式启动
    • -boot-load-size 4 设置载入部分的数量
    • -boot-info-table 在启动的图像中现实信息
    • -R 或 -rock 使用 Rock RidgeExtensions
    • -J 或 -joliet 使用 Joliet 格式的目录与文件名称
    • -v 或 -verbose 执行时显示详细的信息
    • -T 或 -translation-table 建立文件名的转换表,适用于不支持 Rock RidgeExtensions 的系统上

    PXE安装系统

    Preboot Excution Environment 预启动执行环境,Intel公司研发,基于Client/Server的网络模式,支持远程主机通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,PXE可以引导和安装Windows,linux等多种操作系统。

    pxe工作原理

    1. Client向PXE Server上的DHCP发送IP地址请求消息,DHCP检测Client是否合法(主要是检测Client的网卡MAC地址),如果合法则返回Client的IP地址,同时将启动文件pxelinux.0的位置信息一并传送给Client
    2. Client向PXE Server上的TFTP发送获取pxelinux.0请求消息,TFTP接收到消息之后再向Client发送pxelinux.0大小信息,试探Client是否满意,当TFTP收到Client发回的同意大小信息之后,正式向Client发送pxelinux.0
    3. Client执行接收到的pxelinux.0文件
    4. Client向TFTP Server发送针对本机的配置信息文件(在TFTP 服务的pxelinux.cfg目录下),TFTP将配置文件发回Client,继而Client根据配置文件执行后续操作。
    5. Client向TFTP发送Linux内核请求信息,TFTP接收到消息之后将内核文件发送给Client
    6. Client向TFTP发送根文件请求信息,TFTP接收到消息之后返回Linux根文件系统
    7. Client启动Linux内核
    8. Client下载安装源文件,读取自动化安装脚本

    示例:配置pxe服务器端,支持CentOS6和CentOS7的安装(pxe+dhcpd+tftp-server+httpd)

    准备环境:CentOS6.9,静态IP(必须):192.168.0.6,CentOS6.9和CentOS7.5的ISO镜像

    关闭防火墙和selinux

    [root@centos6 ~]# yum install -y dhcp tftp-server httpd syslinux
    [root@centos6 ~]# mkdir /media/centos{6,7}
    [root@centos6 ~]# mount -r /dev/sr0 /media/centos6/
    [root@centos6 ~]# mount -r /dev/sr1 /media/centos7/

    1)配置dhcp

    [root@centos6 ~]# vim /etc/dhcp/dhcpd.conf
    log-facility local7; #记录日志级别
    subnet 192.168.0.0 netmask 255.255.255.0 {   #分配子网,和自己主机一个网段
      range 192.168.0.100 192.168.0.254; #地址池
      option domain-name-servers 114.114.114.114; #DNS
      option domain-name "pxe.test.org"; #搜索域
      option routers 192.168.0.1; #路由网关
      default-lease-time 600; #默认租约时间
      max-lease-time 7200; #最大租约时间
      next-server 192.168.0.6; #*指向tftp服务器地址,此处指向本机
      filename "pxelinux.0"; #pxe文件名,系统默认为pxelinux.0
    }
    [root@centos6 ~]# service dhcpd start #启动dhcp服务
    [root@centos6 ~]# chkconfig dhcpd on #加入开机启动

    2)配置tftp-server

    [root@centos6 ~]# chkconfig tftp on
    [root@centos6 ~]# service xinetd start

    3)准备启动文件

    [root@centos6 ~]# cd /var/lib/tftpboot/
    [root@centos6 tftpboot]# mkdir centos{6,7}
    [root@centos6 tftpboot]# mkdir pxelinux.cfg/
    [root@centos6 tftpboot]# cp /media/centos6/isolinux/{initrd.img,vmlinuz} centos6/
    [root@centos6 tftpboot]# cp /media/centos7/isolinux/{initrd.img,vmlinuz} centos7/
    [root@centos6 tftpboot]# cp /media/centos6/isolinux/{boot.msg,splash.jpg,vesamenu.c32} .
    [root@centos6 tftpboot]# cp /usr/share/syslinux/pxelinux.0 .
    [root@centos6 tftpboot]# install -m 644 /media/centos6/isolinux/isolinux.cfg pxelinux.cfg/default
    [root@centos6 tftpboot]# vim pxelinux.cfg/default 
    default vesamenu.c32
    timeout 60
    display boot.msg
    menu background splash.jpg
    menu title Welcome to CentOS !
    label linux
      menu label ^Install centos6.9_mini
      kernel centos6/vmlinuz
      append initrd=centos6/initrd.img ks=http://192.168.0.6/ksdir/ks6_mini.cfg
    label linux
      menu label ^Install centos7.5_mini
      kernel centos7/vmlinuz
      append initrd=centos7/initrd.img ks=http://192.168.0.6/ksdir/ks7_mini.cfg
    label local
      menu default
      menu label Boot from ^local drive
      localboot 0xffff
    [root@centos6 tftpboot]# tree 
    .
    ├── boot.msg
    ├── centos6
    │   ├── initrd.img
    │   └── vmlinuz
    ├── centos7
    │   ├── initrd.img
    │   └── vmlinuz
    ├── pxelinux.0
    ├── pxelinux.cfg
    │   └── default
    ├── splash.jpg
    └── vesamenu.c32

    4)准备安装源

    [root@centos6 ~]# mkdir -p /var/www/html/centos/{6,7}
    [root@centos6 ~]# mount -r /dev/sr0 /var/www/html/centos/6/
    [root@centos6 ~]# mount -r /dev/sr1 /var/www/html/centos/7/
    [root@centos6 ~]# mkdir -p /var/www/html/ksdir/
    [root@centos6 ~]# cp ks6_mini.cfg ks7_mini.cfg /var/www/html/ksdir/
    [root@centos6 ~]# service httpd start 
    [root@centos6 ~]# chkconfig httpd on

    5)检查并测试

    [root@centos6 ~]# netstat -tnul  #查看以下端口是否都监听
    tcp        0      0 :::80                       :::*                        LISTEN   
    udp        0      0 0.0.0.0:67                  0.0.0.0:*     
    udp        0      0 0.0.0.0:69                  0.0.0.0:*    

    cobbler

    pex的二次封装,由Python开发,提供CLI和Web管理,cobbler在epel源中,安装时需要配置epel源。

    工作原理:

    1. client裸机配置了从网络启动后,开机后会广播包请求DHCP服务器(cobbler server)发送其分配好的一个IP
    2. DHCP服务器(cobbler server)收到请求后发送responese,包括其ip地址
    3. client裸机拿到ip后再向cobbler server发送请求OS引导文件的请求
    4. cobbler server告诉裸机OS引导文件的名字和TFTP server的ip和port
    5. client裸机通过上面告知的TFTP server地址通信,下载引导文件
    6. client裸机执行执行该引导文件,确定加载信息,选择要安装的os,期间会再向cobbler server请求kickstart文件和os image
    7. cobbler server发送请求的kickstart和os iamge
    8. client裸机加载kickstart文件
    9. client裸机接收os image,安装该os image

    配置文件:

    /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日志

    cobbler常用命令:

    cobbler check 核对当前设置是否有问题

    cobbler list 列出所有的cobbler元素

    cobbler report 列出元素的详细信息

    cobbler sync 同步配置到数据目录,更改配置最好都要执行下

    cobbler reposync 同步yum仓库

    cobbler distro 查看导入的发行版系统信息

    cobbler system 查看添加的系统信息

    cobbler profile 查看配置信息

    cobbler profile report --name=xxxx 查看ks文件的详细信息

    示例:配置一个cobbler服务器

    环境:CentOS7.5,epel源,IP:192.168.0.7

    1、安装并启动需要服务

    [root@centos7 ~]# yum install cobbler dhcp
    [root@centos7 ~]# systemctl enable cobblerd dhcpd httpd tftp
    [root@centos7 ~]# systemctl start cobblerd httpd tftp

    2、 检查环境,按照提示修改对应项

    [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. #修改配置文件中server参数为自己的主机IP
    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. #修改配置文件中next_server指向tftp服务器,这里我也指向自己的IP
    3 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment: https://github.com/cobbler/cobbler/wiki/Selinux #将selinux关闭
    4 : change 'disable' to 'no' in /etc/xinetd.d/tftp #将tftp服务启动
    5 : 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. #执行cobbler get-loaders下载启动引导的文件
    6 : enable and start rsyncd.service with systemctl #启动rsync服务
    7 : debmirror package is not installed, it will be required to manage debian deployments and repositories #安装支持deb包的组件,现在安装CentOS不需要此组件
    8 : 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 #修改配置文件中password的参数为自己指定的安装完系统后的root密码
    9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them #fencing设备的配置
    
    Restart cobblerd and then run 'cobbler sync' to apply changes.

      1)

    [root@centos7 ~]# vim /etc/cobbler/settings 
    server: 192.168.0.7

      2)

    [root@centos7 ~]# vim /etc/cobbler/settings 
    next_server: 192.168.0.7

      3)

    [root@centos7 ~]# setenforce 0
    [root@centos7 ~]# getenforce 
    Permissive

      4)

    前边已经启动过了,这里就不需要再次启动了,此报错是CentOS6中的修改方式

      5)

    [root@centos7 ~]# cobbler get-loaders

      6)

    [root@centos7 ~]# systemctl start rsyncd.service
    [root@centos7 ~]# systemctl enable rsyncd.service

      7)

    如果需要安装Debian系列的系统可以执行 yum install debmirror 命令

      8)

    [root@centos7 ~]# openssl passwd -1
    Password: ******
    Verifying - Password: ******
    $1$wyB5xyxu$N7aNVlpb7uivVwTbIBC6F/ #复制此密码到配置文件中,修改default_password_crypted参数
    [root@centos7 ~]# vim /etc/cobbler/settings
    default_password_crypted: "$1$wyB5xyxu$N7aNVlpb7uivVwTbIBC6F/"  #安装系统的root密码

      9)

    关于物理电源管理的配置,此时先不做配置了

    3、配置dhcp

    [root@centos7 ~]# vim /etc/cobbler/settings 
    manage_dhcp: 1
    [root@centos7 ~]# vim /etc/cobbler/dhcp.template #cobbler的配置dhcp模板,修改此文件后同步即可生效
    subnet 192.168.0.0 netmask 255.255.255.0 {  #修改为自己的网段
         option routers             192.168.0.1; #路由地址
         option domain-name-servers 114.114.114.114; #DNS
         option subnet-mask         255.255.255.0; #子网掩码
         range dynamic-bootp        192.168.0.100 192.168.0.254; #地址池
         default-lease-time         21600;
         max-lease-time             43200;
         next-server                $next_server;
         class "pxeclients" {
              match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
              if option pxe-system-type = 00:02 {
                      filename "ia64/elilo.efi";
              } else if option pxe-system-type = 00:06 {
                      filename "grub/grub-x86.efi";
              } else if option pxe-system-type = 00:07 {
                      filename "grub/grub-x86_64.efi";
              } else if option pxe-system-type = 00:09 {
                      filename "grub/grub-x86_64.efi";
              } else {
                      filename "pxelinux.0";
              }
         }
    
    }

    4、同步配置并重启服务

    [root@centos7 ~]# cobbler sync
    [root@centos7 ~]# systemctl restart cobblerd

    到这里cobbler已经配置完毕了,接下来我们只需要将发行版的源和ks文件导入

    导入发行版,可能会比较慢,而且要确认硬盘有足够的空间

    [root@centos7 ~]# cobbler import --path=/media/cdrom/ --name=CentOS-7.5-x86_64 --arch=x86_64

    查看一下是否导入成功

    [root@centos7 ~]# cobbler distro list
       CentOS-7.5-x86_64

    cobbler会自动生成一个自动应答的配置文件,我们需要将它删除

    [root@centos7 ~]# cobbler profile list
       CentOS-7.5-x86_64
    [root@centos7 ~]# cobbler profile remove --name=CentOS-7.5-x86_64

    接下来导入我们准备好的ks文件

    注意:需要将ks文件中的url改为 url --url=$tree

    [root@centos7 ~]# cp ks7_mini.cfg /var/lib/cobbler/kickstarts/
    [root@centos7 ~]# cobbler distro list 
       CentOS-7.5-x86_64
    [root@centos7 ~]# cobbler profile add --name=CentOS-7.5-x86_64_Mini --distro=CentOS-7.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_mini.cfg

    导入成功

    [root@centos7 ~]# cobbler profile list 
       CentOS-7.5-x86_64_Mini

    到此为止,我们已经配置好了一台cobbler服务器了,接下来做安装测试

    cobbler的web管理

    [root@centos7 ~]# yum install cobbler-web
    [root@centos7 ~]# htdigest -c /etc/cobbler/users.digest Cobbler test1 创建管理用户
    [root@centos7 ~]# systemctl restart httpd
    在浏览器中访问https://192.168.0.7/cobbler_web

    cobbler_web用户管理认证方式:

    文件方式:

    # htdigest -c /etc/cobbler/users.digest Cobbler test1

    pam模块认证方式:

    # vim /etc/cobbler/modules.conf
    module = authn_pam
    # useradd -s /sbin/nologin test2
    # echo test2 |passwd --stdin test2
    # vim /etc/cobbler/users.conf
    [admins]
    admin = "test2"
    cobbler = ""
    # systemctl restart cobblerd
  • 相关阅读:
    listbox,tree定位item后显示出来
    dbgrideh导出Excel
    ---注册job 设置时间 必须在命令窗口内执行
    四舍五入函数 function MyRound2
    解决delphi7注册过期方法
    Trunc错误浮点计算处理
    BGridEh,同时也用了DBGrid。在OnDrawColmnCell事件中调用DefaultDrawColumnCell,编译时却提示Incom
    不能借助DLL的全局变量来达到两个应用程序间的数据传递,除非使用内存映像文件
    JavaScript实现换肤功能
    echarts图表隐藏之后再展示出现变形
  • 原文地址:https://www.cnblogs.com/Gmiaomiao/p/9104334.html
Copyright © 2011-2022 走看看