운영 방법|SSH 자동화 클 러 스 터 관리,자동화 스 크 립 트 관리

15190 단어 자동화 운영
호스트 계획
호스트
IP
호스트 관리
192.168.182.10
호스트 관리-1
192.168.182.11
호스트 관리-2
192.168.182.12
2.SSH 클 러 스 터 관리
1.ssh 명령 을 사용 하여 관리 되 는 호스트 의 현재 시간 조회
[root@localhost ~]# ssh -l root 192.168.182.11 date
root@192.168.182.11's password: 
2020  02  05      19:19:01 CST

[root@localhost ~]# ssh -l root 192.168.182.12 date
root@192.168.182.12's password: 
2020  02  05      19:19:07 CST

2.키 생 성ssh-keygen,비밀 로그 인 면제
  • 호스트 생 성 키 쌍 관리ssh-keygen
  • [root@localhost ~]# ssh-keygen					///       
    
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:2oL59QLNUNyK/ylwHD0nvd5/YcJZH0PiXknnJqDm6IE root@localhost.localdomain
    The key's randomart image is:
    +---[RSA 2048]----+
    |       . .       |
    |        o . .. o.|
    |       o o o..+.o|
    |      o o * o..*o|
    |       BS= +o.+o+|
    |     oEoO . .= o.|
    |    o o=oo o .o .|
    |     . o+.o . . .|
    |      .  o.    .o|
    +----[SHA256]-----+
    
  • 호스트 키 의 저장 위치 관리
  • [root@localhost ~]# cd /root/.ssh/
    [root@localhost .ssh]# ls
    id_rsa(  )  id_rsa.pub(  )  known_hosts
    
  • 제어 호스트 에 키 보 내기
  • [root@localhost .ssh]# for i in {0,1,2}; do ssh-copy-id -i 192.168.1.1$i ; done
    
  • 관리 되 는 호스트 의 공개 키 저장 위치
  • [root@test .ssh]# pwd
    /root/.ssh
    [root@test .ssh]# ls
    authorized_keys(    )
    
  • 이 때 관리 되 는 호스트 를 조회 할 때 비밀 번 호 를 입력 할 필요 가 없습니다
  • [root@localhost ~]# ssh -l root 192.168.182.10 date
    2020  02  05      19:39:33 CST
    [root@localhost ~]# ssh -l root 192.168.182.11 date
    2020  02  05      19:39:37 CST
    [root@localhost ~]# ssh -l root 192.168.182.12 date 
    2020  02  05      19:39:43 CST
    

    3.ssh 스 크 립 트 클 러 스 터 관리 사용
  • 관리 되 는 호스트 목록 작성
  • [root@localhost ~]# cat ip_list.txt 
    192.168.182.10
    192.168.182.11
    192.168.182.12
    
  • ssh 자동화 클 러 스 터 관리 스 크 립 트 작성
  • [root@localhost ~]# vim auto_for_ssh.sh
    
    #!/bin/bash
    #auto remote exec command
    ############################
    
    IP_FILES="/root/ip_list.txt"				///         
    COMMAND="$*"								///      
    
    for IP in `cat $IP_FILES`					///             IP  
    do
            echo -e "\033[32mThe $IP remote command follow results:\033[0m"  	///   
            ssh -l root $IP "$COMMAND"			///ssh        
            echo 								///  
    done
    
  • ssh 자동화 클 러 스 터 관리 스 크 립 트+명령 실행
  • [root@localhost ~]# sh auto_for_ssh.sh date
    The 192.168.182.10 remote command follow results:
    2020  02  05      19:53:18 CST
    
    The 192.168.182.11 remote command follow results:
    2020  02  05      19:53:18 CST
    
    The 192.168.182.12 remote command follow results:
    2020  02  05      19:53:19 CST
    

    좋은 웹페이지 즐겨찾기