環境準備(01)起動後にsshdを自動的に実行するcentos 6を作成する.8容器

4879 ワード

概要


開発環境はWindows 10を使用しており、Hadoopの学習にはLinuxの環境が必要であるため、DockerでCentOSコンテナを実行し、このコンテナの中でHadoop学習環境の構築を徐々に改善している.

1.公式centosの実行:6.8ミラーリング

  • このミラーにsshdをインストールし、commitを新しいミラーhadoop 001にし、runの新しいミラーhadoop 001をrunがsshdを起動するコンテナhadoop 001にし、コンテナの外部からこのコンテナにアクセスすることができる.
  • の後のhadoopの学習環境は、このコンテナhadoop 001にインストールされる.
  • PS D:\dockerfile> docker run -it --name centos-ssh -h centos-ssh centos:6.8 /bin/bash
    

    2.Openssh-serverのインストール

    [root@centos-ssh /]# yum -y install openssh-server
    

    3.sshdを起動するための2つの鍵を生成する

  • はパスワードを送って一緒に車に戻らせた.
  • [root@centos-ssh /]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
    Generating public/private rsa key pair.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
    Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
    The key fingerprint is:
    47:63:a5:5b:66:85:28:ab:35:cd:82:60:47:38:1c:d6 root@centos-ssh
    The key's randomart image is:
    +--[ RSA 2048]----+
    |   .o=.    ....  |
    |   .* E . .o..   |
    |   . + . == +    |
    |      . =oo*     |
    |       oSoo      |
    |      .  .       |
    |                 |
    |                 |
    |                 |
    +-----------------+
    
    [root@centos-ssh /]# ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
    Generating public/private dsa key pair.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /etc/ssh/ssh_host_dsa_key.
    Your public key has been saved in /etc/ssh/ssh_host_dsa_key.pub.
    The key fingerprint is:
    a4:6c:ab:0f:64:c2:a7:01:e5:7b:e8:89:bc:2f:02:b9 root@centos-ssh
    The key's randomart image is:
    +--[ DSA 1024]----+
    |  .              |
    | o               |
    |. .     .        |
    | o o . o         |
    | .* = + S        |
    |+o X . .         |
    |oo+ . .          |
    |E..  o           |
    |..o....          |
    +-----------------+
    

    4.コンテナのrootパスワードの設定

    [root@centos-ssh /]# echo "root:111111"|chpasswd
    

    5.sshdサービスの起動

    [root@centos-ssh /]# /usr/sbin/sshd
    
    [root@centos-ssh /]# netstat -antp
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      98/sshd
    tcp        0      0 :::22
    

    6.容器centos-sshを終了する

    [root@centos-ssh /]# exit
    exit
    

    7.コンテナcentos-sshを新しいミラーhadoop 001に再commitする

    PS D:\dockerfile> docker commit centos-ssh hadoop001
    sha256:21d4598b1d068c5d73ee93a9f160cdafc4aad803025a722472cd9bf775ed3004
    
    PS D:\dockerfile> docker images
    REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
    hadoop001            latest              21d4598b1d06        8 seconds ago       281MB
    nginx                latest              cd5239a0906a        4 weeks ago         109MB
    centos               latest              49f7960eb7e4        4 weeks ago         200MB
    rabbitmq             3.7.5-management    c51d1c73d028        8 weeks ago         149MB
    mysql/mysql-server   5.7                 3cc9613ef3ba        2 months ago        244MB
    centos               6.8                 6704d778b3ba        8 months ago        195MB
    centos               7.4.1708            3afd47092a0e        8 months ago        197MB
    mysql                5.6.35              a0f5d7301767        15 months ago       329MB
    

    8.ミラーhadoop 001をコンテナhadoop 001として実行

  • コンテナhadoop 001のポート22は、ホストの9010にマッピングされる.
  • コンテナhadoop 001を実行するとsshd,/usr/sbin/sshd-Dが起動します.
  • PS D:\dockerfile> docker run -itd --name hadoop001 -h hadoop001 -p 9010:22 hadoop001 /usr/sbin/sshd -D
    280146223e2ee93bc3393d17f19880c877f0b4f47439bfb28edadcd8d23846de
    
    PS D:\dockerfile> docker exec -it hadoop001 /bin/bash
    [root@hadoop001 /]#
    
    [root@hadoop001 /]# netstat -antp
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1/sshd
    tcp        0      0 :::22
    
    [root@hadoop001 /]# exit
    exit
    

    9.ホストから接続

    PS D:\dockerfile> ssh root@localhost -p 9010
    The authenticity of host '[localhost]:9010 ([::1]:9010)' can't be established.
    RSA key fingerprint is SHA256:xcND608ckilJni8LV7ClloBcwT860z8Ko6nhUpRUpYI.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '[localhost]:9010' (RSA) to the list of known hosts.
    root@localhost's password:
    [root@hadoop001 ~]#