澳门新葡萄京娱乐网站-澳门新葡萄京888官网-所有平台

热门关键词: 澳门新葡萄京娱乐网站,澳门新葡萄京888官网

澳门新葡萄京娱乐网站提供方向脚本

作者: 澳门新葡萄京娱乐网站  发布:2019-12-11

试验注解:

在自动化布置时,会有的时候SSH别的机器去操作,但是每一趟的密码验证却很令人窝火,特别是相当短的密码,由此SSH免密登入就突显供给;

在机器数目非常多的时候,使用更过的高频是Ansible分发并施行SSH免密登入脚本,使得每台机器之间都能免密登录。

试行求证:

实验情况:

  • 宿主机系统   :Fedora 28 WorkStation
  • 虚拟机微电脑 :Virt-Manager 1.5.1
  • 设想机配置   :ha1  CentOS 7.2 1511 (minimal)   virbr0: 192.168.122.57
                 ha2  CentOS 7.2 1511 (minimal)   virbr0: 192.168.122.58
                 ha3  CentOS 7.2 1511 (minimal)   virbr0: 192.168.122.59

试验意况:

  • 宿主机系统   :Fedora 28 WorkStation
  • 设想机微处理器 :Virt-Manager 1.5.1
  • 设想机配置   :ha1  CentOS 7.2 1511 (minimal)   virbr0: 192.168.122.57
                 ha2  CentOS 7.2 1511 (minimal)   virbr0: 192.168.122.58
                 ha3  CentOS 7.2 1511 (minimal)   virbr0: 192.168.122.59

执行步骤:

  1. ### 安装系统并配备互联网(全体虚构机都需联网)

  2. ### 先操作第生龙活虎台虚构机(ha1)

  3. ### 编写主机名与IP的映照关系

    1 [root@ha1 ~]# vi /etc/hosts
    2 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    3 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    4 192.168.122.57    ha1
    5 192.168.122.58    ha2
    6 192.168.122.59    ha3
    
  4. ### 创设公有密钥

     1 [root@ha1 ~]# ssh-keygen -t rsa 
     2 Generating public/private rsa key pair.
     3 Enter file in which to save the key (/root/.ssh/id_rsa): 
     4 /root/.ssh/id_rsa already exists.
     5 Overwrite (y/n)? y
     6 Enter passphrase (empty for no passphrase): 
     7 Enter same passphrase again: 
     8 Your identification has been saved in /root/.ssh/id_rsa.
     9 Your public key has been saved in /root/.ssh/id_rsa.pub.
    10 The key fingerprint is:
    11 40:c3:81:eb:60:49:2e:f7:fe:59:bb:ef:7d:ad:bb:06 root@ha2
    12 The key's randomart image is:
    13 +--[ RSA 2048]----+
    14 |     o+.         |
    15 |  . ....         |
    16 | o . ..          |
    17 |. * .  .         |
    18 | + +    S        |
    19 |    o       E    |
    20 |   .    .    . . |
    21 |    .  o . .  o .|
    22 |     .o o+o .o++ |
    23 +-----------------+
    
  5. ### 发送公有密钥至远程机器

    1 [root@ha1 ~]# ssh-copy-id root@192.168.122.58
    2 [root@ha1 ~]# ssh-copy-id root@192.168.122.59
    
  6. ### 以上是单台设想机的逐一施行命令的点子,将以上操作写成脚本(脚本在本文末尾PS处)

  7. ### 上面操作别的设想机(ha2、ha3)

    1 # 虚拟机ha2
    2 [root@ha2 ~]# chmod 777 build-ssh-credit.sh 
    3 [root@ha2 ~]# ./build-ssh-credit.sh 
    
    1 # 虚拟机ha3
    2 [root@ha3 ~]# chmod 777 build-ssh-credit.sh 
    3 [root@ha3 ~]# ./build-ssh-credit.sh 
    
  8. ### 至此,三台虚构机之间互相会见都不需求输入密码,达成了SSH的免密登录

  9. ### Complete!!!

尝试步骤:

PS:公钥伊始化和完毕SSH免密登录的台本(build-ssh-credit.sh卡塔尔(英语:State of Qatar),直接拷贝就可采纳。

#!/usr/bin/bash

# 安装expect,minimal没有此rpm包,需联网或有本地yum源
yum install expect -y
expect << EOF
set timeout 10

# 创建公有密钥

spawn ssh-keygen -t rsa
expect {
        "*to save the key" {send "n";exp_continue}
        "*(y/n)" {send "yr";exp_continue}
        "Enter passphrase" {send "n";exp_continue}
        "Enter same passphrase" {send "n";exp_continue}
}

EOF

#  获取/etc/hosts文件中除localhost的映射关系
ip_list=`grep -v 'localhost' /etc/hosts | awk -F ' ' '{print $1,$2}'`
for ip in $ip_list
do
expect << EOF
        set timeout 2

        # 发送公有密钥
        spawn ssh-copy-id root@$ip
        expect {
                "yes/no" {send "yesr";exp_continue}
                "password" {send "000000r";exp_continue}
        }

        # 拷贝/etc/hosts文件到远程机器
        spawn scp /etc/hosts $ip:/etc
        expect {
                "yes/no" {send "yesr";exp_continue}
                "password" {send "rootr";exp_continue}
        }
EOF
done

 

宿主机上操作:首要涉及ntp服务器的搭建以至fencing的结构

  1. ### 确认保证宿主机系统是联网的,配置互联网请参谋 此链接

  2. ### 安装 virt-manager

    # dnf install virt-manager libvirt
    
  3. ### 使用virt-manager成立kvm虚构机并配置kvm虚构机 请参谋 此链接

  4. ### 安装fence、ntpd等软件

    # dnf install -y ntp fence-virtd fence-virtd-multicast fence-virtd-libvirt fence-virt*
    
  5. ### 配置ntpd 设置区时为北京

    # timedatectl list-timezones | grep Shanghai
    # timedatectl set-timezone Asia/Shanghai
    

    ### 校勘ntp配置文件

    # 删除原配置中的相关配置项
    # sed -e '/^server/d' -e '/^#server/d' -e '/^fudge/d' -e '/^#fudge/d' -i /etc/ntp.conf
    
    # 在结尾添加ntp服务器配置
    # sed -e '$a server 127.127.1.0' -e '$a fudge 127.127.1.0 stratum' -i /etc/ntp.conf 
    

    ### 安装开机自启、开启服务并查看情形

    # systemctl enable ntpd.service && systemctl start ntpd.service && systemctl status ntpd.service
    

     

    ntpq -c peers 
    ntpq -c assoc 
    timedatectl 
    
  6. ### 配置fence-virtd

    ### 创建 /etc/cluster 文件夹

    # mkdir -p /etc/cluster
    

    ### 生成fence_xvm.key文件

    # echo fecb9e62cbcf4e54dcfb > /etc/cluster/fence_xvm.key
    

    ### 初始化fence_virtd

    # fence_virtd -c
    

    ### 确认模块搜索路线 澳门新葡萄京娱乐网站 1 确认监听情势 澳门新葡萄京娱乐网站 2 确认监听IP地址以及端口 澳门新葡萄京娱乐网站 3 确认监听网卡接口 澳门新葡萄京娱乐网站 4 确认密钥路线 澳门新葡萄京娱乐网站 5 确认后端设想化模块 澳门新葡萄京娱乐网站 6 确认Libvirt URL 澳门新葡萄京娱乐网站 7 是不是替换文件 澳门新葡萄京娱乐网站 8

    ### 设置开机自启、开启服务并查看情形

    # systemctl enable fence_virtd && systemctl start fence_virtd && systemctl status fence_virtd
    
  7. ### 验证fencevirtd 查询全部情况的虚构机

    # fence_xvm -o list
    

    ###  查询结果如下图: 澳门新葡萄京娱乐网站 9

  8. ### Fencing操作 关闭全部已张开的设想机

    # 启动(on)、关机(off)、重启(reboot)、状态获取(status)
    # fence_xvm -o off -H HA1
    # fence_xvm -o off -H HA2
    # fence_xvm -o off -H HA3
    

    ### 再一次询问,结果如下图: 澳门新葡萄京娱乐网站 10

kvm设想机上操作:首要涉及Ntp服务同步和Pacemaker集群的搭建

  1. ### 配置kvm虚拟机

  2. ### 安装ntpd、pcs等软件

    # yum install -y ntp pcs pacemaker corosync fence-agents-all resource-agents
    
  3. ### 配置ntpd 与宿主机上操作看似,此处不再实行

    1 # timedatectl set-timezone Asia/Shanghai
    2 
    3 # sed -i s/^server.*// /etc/ntp.conf
    4 # echo "server 192.168.43.177 iburst" >> /etc/ntp.conf
    5 # echo "SYNC_HWCLOCK=yes" >> /etc/sysconfig/ntpdate
    6 # systemctl enable ntpd.service && systemctl start ntpd.service && systemctl status ntpd.service
    

    ### 查询当前光阴设置

    # timedatectl
    
  4. ### 配置Pacemaker集群 检查是还是不是安装Pacemaker软件 创立Fencing设备密钥Key

    # mkdir -p /etc/cluster
    # echo fecb9e62cbcf4e54dcfb > /etc/cluster/fence_xvm.key
    

    ### 设置hacluster客户密码

    # echo 000000|passwd --stdin hacluster
    

    ### 创设Pacemaker集群 创设时索要打开授权认证,以至须要丰盛到集群的主机名

    # pcs cluster auth ha1 ha2 ha3 -u hacluster -p 000000 --force
    

    ### 设置集群的称号时索要钦赐集群名称和急需加上到集群的主机名

    # pcs cluster setup --force --name openstack-ha ha1 ha2 ha3
    

    ### 设置在集群具备节点运行时启用corosync和pacemaker

    # pcs cluster enable --all
    

    ### 设置在集群具备节点都张开集群

    # pcs cluster start --all
    

    ### 查询集群状态

    # pcs status
    

    ### 为了达成对虚构机的Fencing操作,必要为Pacemaker集群配置Stonith财富

    1 # pcs stonith create fence1 fence_xvm multicast_address=225.0.0.12
    2 # pcs stonith create fence2 fence_xvm multicast_address=225.0.0.12
    3 # pcs stonith create fence3 fence_xvm multicast_address=225.0.0.12
    

    ### 查询集群状态

    [root@ha1 ~]# pcs status
    Cluster name: openstack-ha
    Stack: corosync
    Current DC: ha1 (version 1.1.18-11.el7_5.3-2b07d5c5a9) - partition with quorum
    Last updated: Thu Aug 16 15:30:59 2018
    Last change: Thu Aug 16 12:44:03 2018 by root via cibadmin on ha1
    
    3 nodes configured
    3 resources configured
    
    Online: [ ha1 ha2 ha3 ]
    
    Full list of resources:
    
     fence1    (stonith:fence_xvm):    Started ha1
     fence2    (stonith:fence_xvm):    Started ha2
     fence3    (stonith:fence_xvm):    Started ha3
    
    Daemon Status:
      corosync: active/enabled
      pacemaker: active/enabled
      pcsd: active/enabled
    

    ### 查询当前 Pacemaker 集群中的 Stonith 财富

    [root@ha1 ~]# pcs stonith show
     fence1    (stonith:fence_xvm):    Started ha1
     fence2    (stonith:fence_xvm):    Started ha2
     fence3    (stonith:fence_xvm):    Started ha3
    

     

     

本文由澳门新葡萄京娱乐网站发布于澳门新葡萄京娱乐网站,转载请注明出处:澳门新葡萄京娱乐网站提供方向脚本

关键词: