美文网首页Hadoop系HadoopOpenStack
简单使用OpenStack创建实例

简单使用OpenStack创建实例

作者: 2010jing | 来源:发表于2017-05-06 19:21 被阅读3600次

    在搭建好的OpenStack环境,创建虚拟机。

    登录OpenStack

    login-openstack.png

    根据自己的账号信息登录。

    登录进去之后,查看网络是这样子的。

    main-network.png

    由于IP 有限,不能够给到用户直接将多个VM 挂载在该网络上,得由用户自行创建子网,创建路由,然后通过申请Floating IP来访问内网创建的VM。

    创建子网

    Network -- > Network Topology -- > Create Network

    create-subnet.png create-subnet-info-0.png create-subnet-info.png

    输入子网的一些信息

    Network Name: demo
    Subnet Name: demo_subnet
    Network Address: 10.0.1.0/24

    再查看网络 就可以看到创建的子网demo(橙色)

    created-subnetwork.png

    创建路由

    Network -- > Routers -- > Create Router

    create-router.png create-router-info-0.png

    路由信息
    Router Name: demo-router
    External Network: ext_net

    此时效果是这样的

    created-router.png

    给路由添加接口

    Network -- Router -- Interfaces -- Add Interface

    add-router-interface.png

    Select Subnet: demo_subnet

    add-router-interface-info-1.png

    效果如下

    add-router-interface-info-2.png

    创建VM实例

    Compute -- Instances -- Launch Instance

    create-instance.png

    Name: demo(随意)
    Count:1

    create-instance-1.png

    Source: Ubuntu

    create-instance-2.png

    Flavor: typical

    create-instance-3.png

    Network
    Network: demo

    create-instance-4.png

    Configuration

    #!/bin/sh
    passwd ubuntu<<EOF
    123456
    123456
    EOF
    sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
    service ssh restart
    

    这个配置很重要,否则创建VM后,你只能在网页端的console去访问,网页端实在太慢太卡,不大建议,很不方便。当然你也可以使用key pair, 但是这样你得在你要使用的电脑上有xxx.pem的文件。本人还是渴望方便一点,直接SSH 账号密码登录。

    命令简单解释:

    passwd ubuntu 是更改 ubuntu账号密码,因为openstack 提供的ubuntu 镜像,默认创建账号是ubuntu。
    这两个 123456 是你的密码 和 确认密码,自行更改。
    用sed 命令更改配置文件 允许密码认证登录。
    最后就是要重启一下SSH服务。

    create-instance-5.png

    最后点击 Launch Instance.

    Launch-Instance-1.png Launch-Instance-2.png

    这样,一个VM实例就创建出来。

    绑定Floating IP

    因为创建的VM是链接在你的子网内,外网不可以直接访问,这个时候需要给路由绑定Floating IP,才可以从外网访问你的VM。

    Associate Floating IP
    floating-ip-1.png floating-ip-2.png floating-ip-3.png floating-ip-4.png

    测试SSH访问

    可能一开始并不能够访问,因为没有在安全组添加规则。我们需要开通一下,添加规则就好。

    rule-1.png

    ALL ICMP - Ingress

    rule-2.png rule-3.png

    SSH

    rule-4.png rule-5.png

    添加完毕之后,就开始测试了。

    $ ssh ubuntu@192.168.9.15
    

    192.168.9.15 是你对应VM的 Floating IP

    ![ssh-2.png](http:https://img.haomeiwen.com/i454212/4ba5269ae247be69.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

    重复上面的操作,再创建两个VM。

    other-vm.png

    这样我们就可以通过Floating IP 去访问其他虚拟机。

    ssh-3.png ssh-4.png

    相关文章

      网友评论

      • 王城_4b6a:大神您好,我使用openstack创建完ubuntu实例登录控制台时提示“Your installation CD-ROM couldn’t be mounted. This probably means that the CD-ROM was not in the drive. If so you can insert it and try again.
        Retry mounting the CD-ROM? <Yes>/<No>”
        创建windows实例登录控制台提示“Boot failed : not a bootable disk”,
        创建centos实例登录控制台提示“No disk selected”

        上面的三个问题应该属于同一问题,请问怎么解决?
      • 徐士林:问题多多啊大神,镜像用的centos,没有初始密码进不去。想直接通过ssh连接,但是你最后的终端是哪里的呀。我是在跳转机上弄的?
        2010jing: @2010jing 终端是链接到你创建的实例啊,本文也是
        2010jing: @徐士林 我的终端是链接到创建的实例
        2010jing: @徐士林 我是用openstack提供的镜像,需要设置configuration,见文中。 如果不行你再在openstack页面上去登录模拟终端去做一些设置,centos和Ubuntu应该大同小异

      本文标题:简单使用OpenStack创建实例

      本文链接:https://www.haomeiwen.com/subject/pxkytxtx.html