设为首页 收藏本站
查看: 2032|回复: 0

[经验分享] openstack私有云布署实践【16.2 Ubuntu1404 只有根分区镜像制作】

[复制链接]

尚未签到

发表于 2017-6-24 23:20:15 | 显示全部楼层 |阅读模式
之所以要只有根分区镜像,是因为在创建VM或者调整云主机的硬盘大小时,它能自动扩容。无需人工介入

在原来的物理机10.40.41.1的CentOS 6.7上制作镜像。
宿主机坱要安装KVM相关软件:
yum groupinstall Virtualization "Virtualization Client" -y
yum install libvirt libguestfs-tools qemu virt-manager virt-viewer qemu-kvm virt-install bridge-utils -y
service libvirtd start
chkconfig libvirtd on

材料有
ubuntu-14.04.3-server-amd64.iso-----ubuntu官网上有得下载

上传至10.40.41.1的物理机上的/home目录下

10.40.41.1所在的网段预先网卡配了DHCP。目的是为了简化我们的安装过程,如果你的安装过程中没有网络,步骤会少许不一样,你得熟知安装这程每一步中的提示意思

创建镜像的硬盘文件
mkdir /mnt/sdf1/ubuntu1404/
cd /mnt/sdf1/ubuntu1404/
qemu-img create -f qcow2 ubuntu1404.qcow2 20G

CentOS6.7宿主机上的执行命令
[iyunv@bunker ubuntu1404]# virt-install --name ubuntu1404 --ram 4096 --vcpus 2 --network bridge=kvmbr0,model=e1000 --disk=/mnt/sdf1/ubuntu1404/ubuntu1404.qcow2,format=qcow2,device=disk,bus=virtio  --cdrom=/home/ubuntu-14.04.3-server-amd64.iso  --vnc --vncport=5971 --vnclisten=0.0.0.0 --os-type=linux --force

CentOS7.2宿主机上的执行命令

virt-install --name test --ram 4096 --vcpus 2 --network bridge=kvmbr0  --disk=/mnt/sde1/test/test.raw,size=20,bus=virtio  --cdrom=/home/ubuntu-14.04.3-server-amd64.iso  --graphics vnc,listen=0.0.0.0,port=5910 --os-type=linux --force --noautoconsole


开始安装......
创建域......                                                                                                                                                                       |    0 B     00:00     
无法打开显示:
运行 'virt-viewer --help' 来查看可用命令行选项的完整列表

域安装仍在进行。您可以重新连接
到控制台以便完成安装进程。
[iyunv@bunker ubuntu1404]#

接下使用VNC连接,目的是为了分区1个根分区
DSC0000.png

这里选择英文版,它不像CentOS ,我们是因为怕系统安装完成后,它默认系统界面帮我转成中文,在登录界面上显示编码格式会有问题

DSC0001.png
DSC0002.png

DSC0003.png

DSC0004.png

DSC0005.png

DSC0006.png

DSC0007.png



DSC0008.png
ubuntu默认要求使用一个普通用户登录,我们先配,后期可改
DSC0009.png
设置用户venic的密码为:venic8888
DSC00010.png
DSC00011.png
DSC00012.png

自动联网查看时区后,发现是一个重庆的,问题也不大,但我们如果选择否,可以重选 为其它地方时区,比如香港
DSC00013.png

到了选择磁盘分区,关键,因为我们要分成一个区,只有/ 根分区
DSC00014.png
DSC00015.png

DSC00016.png


DSC00017.png
DSC00018.png


DSC00019.png
DSC00020.png
DSC00021.png


保持默认操作
DSC00022.png
DSC00023.png


DSC00024.png
DSC00025.png

不要填代理,直接继续
DSC00026.png
不动它,让它设置atp-get源
DSC00027.png
不选 更新
DSC00028.png
只开启ssh功能,其它不装,要最小化安装
DSC00029.png

接下来真正开始安装
DSC00030.png
写grub引导
DSC00031.png
DSC00032.png



虚拟机装完后默认被会宿主机关机,需要再开机

[iyunv@bunker ~]# virsh start ubuntu1404

再用VNC连进去,查看获取的IP是多少,再用SSH登录进去
DSC00033.png

看到DHCP分配的IP是:10.40.41.154。使用ssh登录,使用sudo su -切换到root模式,密码使用venic的密码
DSC00034.png
vi /etc/ssh/sshd_config,修改以下1处PermitRootLoing配置

PermitRootLogin yes
尾部添加这个
UseDNS no

vi /etc/ssh/ssh_config 添加禁止加host_know和认证
    GSSAPIAuthentication no
    GSSAPIDelegateCredentials no
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null


保存退出,重启ssh
service ssh restart

在外部验证ssh 功能是否正常。

查看网卡信息,只这1张网卡,无误,这里没有试验双网卡
vi /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp

修改允许启动时console访问输出
vi /etc/default/grub
GRUB_TIMEOUT=1
GRUB_CMDLINE_LINUX="console=ttyS0,115200"

运行update-grub命令


安装cloud-init
apt-get install cloud-init -y

修改元数据在启动下的下发配置,以下贴出生产环境的全部配置。部分是修改过的,比如允许root登录,修改apt-get的源禁止更新等等
vi /etc/cloud/cloud.cfg
# The top level settings are used as module
# and system configuration.

# A set of users which may be applied and/or used by various modules
# when a 'default' entry is found it will reference the 'default_user'
# from the distro configuration specified below
users:
   - default

# If this is set, 'root' will not be able to ssh in and they
# will get a message to login instead as the above $user (ubuntu)
disable_root: false

# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: false

# Example datasource config
# datasource:
#    Ec2:
#      metadata_urls: [ 'blah.com' ]
#      timeout: 5 # (defaults to 50 seconds)
#      max_wait: 10 # (defaults to 120 seconds)

# The modules that run in the 'init' stage
cloud_init_modules:
- migrator
- seed_random
- bootcmd
- write-files
- growpart
- resizefs
- set_hostname
- ca-certs
- rsyslog
- users-groups

# The modules that run in the 'config' stage
cloud_config_modules:
# Emit the cloud config ready event
# this can be used by upstart jobs for 'start on cloud-config'.
- emit_upstart
- disk_setup
- mounts
- locale
- set-passwords
- grub-dpkg
- package-update-upgrade-install
- landscape
- timezone
- puppet
- chef
- salt-minion
- mcollective
- disable-ec2-metadata
- runcmd
- byobu

# The modules that run in the 'final' stage
cloud_final_modules:
- rightscale_userdata
- scripts-vendor
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- scripts-user
- ssh-authkey-fingerprints
- keys-to-console
- phone-home
- final-message
- power-state-change

# System and/or distro specific settings
# (not accessible to handlers/transforms)
system_info:
   # This will affect which distro class gets used
   distro: ubuntu
   # Default user name + that default users groups (if added/used)
   default_user:
     name: ubuntu
     lock_passwd: True
     gecos: Ubuntu
     groups: [adm, audio, cdrom, dialout, dip, floppy, netdev, plugdev, sudo, video]
     sudo: ["ALL=(ALL) NOPASSWD:ALL"]
     shell: /bin/bash
   # Other config here will be given to the distro class and/or path classes
   paths:
      cloud_dir: /var/lib/cloud/
      templates_dir: /etc/cloud/templates/
      upstart_dir: /etc/init/
   ssh_svcname: ssh


替换apt-get的源更新
vi /etc/apt/sources.list

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

更新系统:apt-get update  -y

安装开机自启动的工具:ysv-rc-conf
当然默认apt-get安装的服务在执行service XXX start时就开机自启动了,比如zabbix-agent和salt-minion它是使用到/etc/init/X.conf的脚本,我是暂不需要用到这个ysv-rc-conf 开机自启的工具


都安装一些基础包
建议更新一下GCC和openssl软件,因为低版本的openssl的攻击的太常见了,
还有zabbix-agent和salt-minion等等
设置chrony时钟同步服务器

另外一些linux内核特性的配置和文件句柄ulimit的优化,可以参考其它文档




最终在宿主机上压缩镜像就可以上传至openstack
virt-sparsify --compress /tmp/centos-6.5.qcow2 centos-6.5-cloud.qcow2
镜像制作到此结束

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-387767-1-1.html 上篇帖子: openstack常见问题汇总 下篇帖子: 虚拟化概念总结
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表