Linux学习--第15周

1、PAM和goole模块实现ssh双因子认证

(1) 在手机应用市场搜索:身份验证器或authenticator,并安装APP
(2) 配置好epel源,安装google-authenticator
    yum -y info google-authenticator
(3) 运行google-authenticator,这是安装配置向导,根据询问,进行绑定服务器的配置,
    期间需要在浏览器中访问生成的ur,生成二维码,然后打开手机上安装的身份验证器APP进行扫码,进行绑定手机。
(4) 更改/etc/pam.d/sshd配置文件,添加如下行保存
    auth required pam_google_authenticator.so
(5) 编辑/etc/ssh/sshd_config文件,找到下行
    ChallengeResponseAuthentication no
    更改为
    ChallengeResponseAuthentication yes
(6) 重启SSH服务
    service sshd restart

2、使用chrony实现内网时间同步

使用10.0.0.81这台机器作为内网中的时间同步服务器,来为内网10.0.0.0/24内网网段提供时间服务.10.0.0.71作为测试客户端,来获得时间服务
(1) 安装chronyd服务
    [root@CentOS8 ~]#yum -y install chrony 
(2) 编辑配置文件/etc/chrony.conf
    [root@CentOS8 ~]#grep "^[^#]" /etc/chrony.conf
    server ntp.aliyun.com iburst
    driftfile /var/lib/chrony/drift
    makestep 1.0 3
    rtcsync
    allow 10.0.0.0/24
    keyfile /etc/chrony.keys
    leapsectz right/UTC
    logdir /var/log/chrony
(3) 启动chronyd服务
    [root@CentOS8 ~]#systemctl start chronyd
(4) 在客户端上安装chronyd服务
    [root@CentOS7-1 ~]#yum -y install chronyyum
(5) 在客户端上编辑配置文件/etc/chrony.conf
    [root@CentOS7-1 ~]#grep "^[^#]" /etc/chrony.conf
    server 10.0.0.81 iburst
    driftfile /var/lib/chrony/drift
    makestep 1.0 3
    rtcsync
    logdir /var/log/chrony
(6) 客户端上启动chronyd服务
    [root@CentOS7-1 ~]#systemctl start chronyd
(7) 验证测试
    [root@CentOS7-1 ~]#chronyc sources -v
    210 Number of sources = 1

    .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
    / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
    | /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
    ||                                                 .- xxxx [ yyyy ] +/- zzzz
    ||      Reachability register (octal) -.           |  xxxx = adjusted offset,
    ||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
    ||                                \     |          |  zzzz = estimated error.
    ||                                 |    |           \
    MS Name/IP address         Stratum Poll Reach LastRx Last sample               
    ===============================================================================
    ^* 10.0.0.81                     3   6   377    53   +149us[ +198us] +/-   24ms

3、利用cobbler实现系统自动安装

(1) 环境准备
    1) 准备两台主机
        一台主机:CentOS 7 充当 Cobbler,http,dhcp,tftp 服务器,并关闭防火墙和SELinux
        一台主机:充当测试机,用于实现自动化安装Linux系统
    2) 网络要求:关闭Vmware软件中的NAT模式中的DHCP服务,两个主机网卡基于NAT模式
(2) 安装相关包并启动服务
    [root@centos7 ~]#yum install cobbler dhcp -y
    [root@centos7 ~]#systemctl enable --now cobblerd httpd tftp dhcpd
(3) 修改cobbler相关的配置
    1) 运行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 : ksvalidator was not found, install pykickstart
        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-phrasehere' 'your-password-here'" to generate new one
        9 : fencing tools were not found, and are required to use the (optional) power
        management features. install cman or fence-agents to use them

    2) 生成新密码,默认安装好的系统root密码为cobbler
        [root@centos7 ~]#openssl passwd -1 'magedu'
        $1$1spuisnh$j34LNmyTQWs3l6xKxCZY60
    3) 根据以上提示,只需要做1,2,8这三项即可,修改下面四行
        [root@centos7 ~]#vim /etc/cobbler/settings
        default_password_crypted: "$1$1spuisnh$j34LNmyTQWs3l6xKxCZY60"
        next_server:< tftp服务器的 IP 地址>
        server:<cobbler服务器的 IP 地址>
        manage_dhcp:1 #设置为1,表示通过cobbler生成dhcpd.conf配置文件
    4) 再次运行cobbler check
        [root@CentOS7-1 ~]#cobbler check
        The following are potential configuration items that you may want to fix:
        1 : enable and start rsyncd.service with systemctl
        2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
        3 : 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
        4 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
    5) 重启cobblerd服务
        [root@centos7 ~]#systemctl restart cobblerd
(4) 实现dhcp服务
    修改dhcp的模版文件下面的行,用来生成dhcp的配置文件
        [root@centos7 ~]#vim /etc/cobbler/dhcp.template
        subnet 10.0.0.0 netmask 255.255.255.0 {
        option routers             10.0.0.254;
        option domain-name-servers 223.5.5.5,223.6.6.6;
        option subnet-mask         255.255.255.0;
        range dynamic-bootp        10.0.0.150 10.0.0.200;
        default-lease-time         21600;
        max-lease-time             43200;
        next-server                $next_server;
    生成dhcp的配置文件
        [root@centos7 ~]#cobbler sync
    重启dhcpd服务
        [root@centos7 ~]#systemctl start dhcpd
(5) 下载启动的相关文件
    [root@CentOS7-1 ~]#cobbler get-loaders
    task started: 2021-02-23_112737_get_loaders
    task started (id=Download Bootloader Content, time=Tue Feb 23 11:27:37 2021)
    path /var/lib/cobbler/loaders/README already exists, not overwriting existing content, use --force if you wish to update
    path /var/lib/cobbler/loaders/COPYING.elilo already exists, not overwriting existing content, use --force if you wish to update
    path /var/lib/cobbler/loaders/COPYING.yaboot already exists, not overwriting existing content, use --force if you wish to update
    path /var/lib/cobbler/loaders/COPYING.syslinux already exists, not overwriting existing content, use --force if you wish to update
    path /var/lib/cobbler/loaders/elilo-ia64.efi already exists, not overwriting existing content, use --force if you wish to update
    path /var/lib/cobbler/loaders/yaboot already exists, not overwriting existing content, use --force if you wish to update
    path /var/lib/cobbler/loaders/pxelinux.0 already exists, not overwriting existing content, use --force if you wish to update
    path /var/lib/cobbler/loaders/menu.c32 already exists, not overwriting existing content, use --force if you wish to update
    path /var/lib/cobbler/loaders/grub-x86.efi already exists, not overwriting existing content, use --force if you wish to update
    path /var/lib/cobbler/loaders/grub-x86_64.efi already exists, not overwriting existing content, use --force if you wish to update
    *** TASK COMPLETE ***

    [root@centos7 ~]#ls /var/lib/cobbler/loaders
    COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README
    COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot

    [root@centos7 ~]#tree /var/lib/tftpboot/
    /var/lib/tftpboot/
    ├── boot
    ├── etc
    ├── grub
    ├── images
    ├── images2
    ├── ppc
    ├── pxelinux.cfg
    └── s390x
    8 directories, 0 files

    [root@CentOS7-1 ~]#cobbler sync

    [root@CentOS7-1 ~]#tree /var/lib/tftpboot/
    /var/lib/tftpboot/
    ├── boot
    │   └── grub
    │       └── menu.lst
    ├── etc
    ├── grub
    │   ├── efidefault
    │   ├── grub-x86_64.efi
    │   ├── grub-x86.efi
    │   └── images -> ../images
    ├── images
    ├── images2
    ├── memdisk
    ├── menu.c32
    ├── ppc
    ├── pxelinux.0
    ├── pxelinux.cfg
    │   └── default
    ├── s390x
    │   └── profile_list
    └── yaboot
    10 directories, 10 files
(6)  修改菜单的标题信息(可选)
    [root@centos7 ~]#vim /etc/cobbler/pxe/pxedefault.template
    MENU TITLE Cobbler | http://www.magedu.com/
    [root@centos7 ~]#cobbler sync
    [root@centos7 ~]#cat /var/lib/tftpboot/pxelinux.cfg/default
    DEFAULT menu
    PROMPT 0
    MENU TITLE Cobbler | http://www.magedu.com/ #默认为:http://cobbler.github.io/
    TIMEOUT 200
    TOTALTIMEOUT 6000
    ONTIMEOUT local
    LABEL local
    MENU LABEL (local)
    MENU DEFAULT
    LOCALBOOT -1
    MENU end
(7) 导入CentOS系统的安装文件,生成相应的YUM源
    [root@centos7 ~]#cobbler import --name=centos-8.1-x86_64 --path=/misc/cd --
    arch=x86_64
    [root@centos7 ~]#mount /dev/sr1 /mnt
    mount: /dev/sr1 is write-protected, mounting read-only
    [root@centos7 ~]#cobbler import --name=centos-7.7-x86_64 --path=/mnt --
    arch=x86_64
    [root@centos7 ~]#du -sh /var/www/cobbler/ks_mirror/*
    11G /var/www/cobbler/ks_mirror/centos-7.7-x86_64
    7.2G /var/www/cobbler/ks_mirror/centos-8.1-x86_64
    12K /var/www/cobbler/ks_mirror/config
    [root@centos7 ~]#cobbler distro list
    centos-7.7-x86_64
    centos-8.1-x86_64
    [root@centos7 ~]#cobbler profile list
    centos-7.7-x86_64
    centos-8.1-x86_64
(8) 准备 kickstart文件,并关联至指定的YUM源
    1) 将应答文件放到对应的目录中
    [root@CentOS7-1 ~]#ll /var/lib/cobbler/kickstarts
    -rw-r--r-- 1 root root  990 Feb 22 20:39 centos8.cfg
    -rw-r--r-- 1 root root  741 Feb 23 11:59 centos7.cfg
    2) 将kickstart文件,关联指定的YUM源和生成菜单列表
    [root@centos7 ~]#cobbler profile add --name=CentOS-8.1_test --distro=CentOS-8.1-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos8.cfg
    [root@centos7 ~]#cobbler profile add --name=CentOS-7.7_test --distro=CentOS-7.7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg
    3) 删除默认生成的菜单
    [root@centos7 ~]#cobbler profile remove --name=centos-8.1-x86_64
    [root@centos7 ~]#cobbler profile remove --name=centos-7.7-x86_64
    [root@centos7 ~]#cobbler profile list
    CentOS-7.7_test
    CentOS-8.1_test
    4) 删除默认的菜单列表
    [root@centos7 ~]#cobbler profile remove --name=CentOS8.0-x86_64
(9) 测试客户端基于Cobbler实现自动安装

猜你喜欢

转载自blog.51cto.com/14255962/2668199