陈沙克

Apr 212021
 

靠ping是不太靠谱,telnet端口,经常需要装。今天在mac下。

nc -vz -w 2 www.baidu.com 80
Connection to www.baidu.com port 80 [tcp/http] succeeded!

挺方便,就几个参数

  • -v 详细信息
  • -z 不发送包给对方
  • -w 后面是数字,秒,表示多少时间结束,不等太长时间。
  • -u udp 协议,默认是tcp。上图可以看到。如果是dns端口检测,用u
nc -zv -w 2 -u 114.114.114.114 53
Connection to 114.114.114.114 port 53 [udp/domain] succeeded!

参考文章

  • https://www.jianshu.com/p/0f39dbd911ef
Apr 132021
 

儿子学python,需要用pygame,我就在mac上装一下。以前python版本是3.7,装完,python版本升级到3.9.

pip3 install pygame

这就装完了。测试一下。

python3 -m pygame.examples.aliens

能看到一个demo,比较有意思。

shake@ShakedeMacBook-Air ~ % python --version
Python 2.7.16
shake@ShakedeMacBook-Air ~ % python3 --version
Python 3.9.2
shake@ShakedeMacBook-Air ~ % 

查看一下安装的版本

shake@ShakedeMacBook-Air ~ % python3
Python 3.9.2 (v3.9.2:1a79785e3e, Feb 19 2021, 09:06:10) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 2.0.1 (SDL 2.0.14, Python 3.9.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> exit ()
Apr 022021
 

最近做镜像,折腾repo。记录一下,发现各个repo,居然最好用,体贴的是腾讯云。

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos6_base.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-6.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos8_base.repo

这样就基本搞定。不过有时候你会遇到key的问题。所以你可以

rpm --import https://mirrors.cloud.tencent.com/epel/RPM-GPG-KEY-EPEL-6'

这是epel,可以参考。这样基本就没啥问题。

  • https://mirrors.cloud.tencent.com/help/centos.html
Mar 302021
 

目前红帽已经不支持CentOS 6,也就导致网上的repo全部失效。这个时候,要做一个镜像,就变得比较麻烦。

DIB 已经失效,只能使用更早的版本,pip安装,所以就放弃,全部使用virt来进行定制。需要准备CentOS 6.8的repo,后续会提供。我是这CentOS 7.6 虚拟机里,进行下面的操作。

mkdir cloud-images
cd cloud-images
curl -O https://mirrors.ustc.edu.cn/centos-cloud/centos/6/images/CentOS-6-x86_64-GenericCloud-1605.qcow2

Virt

yum install libguestfs-tools-c libguestfs libguestfs-tools

必须运行这个才能正常使用,退出还需要重新运行

export LIBGUESTFS_BACKEND=direct
cp cloud-images/CentOS-6-x86_64-GenericCloud-1605.qcow2 /root/CentOS-6.8-x86.qcow2
export image_name='CentOS-6.8-x86.qcow2' 
virt-customize -a $image_name --timezone "Asia/Shanghai"
virt-customize -a $image_name --edit '/etc/selinux/config:s/SELINUX=enforcing/SELINUX=disabled/' 
virt-customize -a $image_name --delete "/etc/yum.repos.d/CentOS-*"
virt-customize -a $image_name --upload /root/CentOS-Base.repo:/etc/yum.repos.d/CentOS-Base.repo
virt-customize -a $image_name --upload /root/epel.repo:/etc/yum.repos.d/epel.repo
virt-customize -a $image_name --run-command 'yum clean all'
virt-customize -a $image_name --run-command 'yum makecache'
virt-customize -a $image_name --install [net-tools,wget,vim,unzip]
virt-customize -a $image_name --run-command "yum -y install qemu-guest-agent"
virt-customize -a $image_name --run-command "chkconfig qemu-ga on"
virt-customize -a $image_name --run-command 'yum -y install cloud-utils-growpart dracut-modules-growroot'
virt-customize -a $image_name --append-line '/etc/profile:alias vi=vim'

ssh相关

virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/GSS/#GSS/'
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/#UseDNS yes/UseDNS no/'
virt-customize -a $image_name --edit '/etc/cloud/cloud.cfg:s/ssh_pwauth:   0/ssh_pwauth: 1/'
virt-customize -a $image_name --edit '/etc/cloud/cloud.cfg:s/disable_root: 1/disable_root: 0/'

Cloud init

virt-customize -a $image_name --upload /etc/cloud/cloud.cfg.d/91-dib-cloud-init-datasources.cfg:/etc/cloud/cloud.cfg.d/91-dib-cloud-init-datasources.cfg

virt-customize -a $image_name --upload /etc/cloud/cloud.cfg.d/92-ec2-datasource.cfg:/etc/cloud/cloud.cfg.d/92-ec2-datasource.cfg

grub 修改

virt-customize -a $image_name --edit '/etc/grub.conf:s/serial --unit=0 --speed=115200/#serial --unit=0 --speed=115200/'
virt-customize -a $image_name --edit '/etc/grub.conf:s/terminal --timeout=1 serial console/#terminal --timeout=1 serial console/'
virt-customize -a $image_name --edit '/etc/grub.conf:s/rd_NO_DM/rd_NO_DM edd=off/'
virt-customize -a $image_name --edit '/etc/grub.conf:s/console=ttyS0,115200/ /'
Mar 262021
 

这里面其实就是记录一下做一个指定版本的镜像,所需要做的东西。假设DIB和virt已经装好。下面就是一个实际的操作过程。可以参考我上一篇文章。国内目前好像就中科大提供镜像下载。我这里下载的是7.6

https://mirrors.ustc.edu.cn/centos-cloud/centos/7/images/

我习惯就是

mkdir cloud-images
cd cloud-images
curl -O https://mirrors.ustc.edu.cn/centos-cloud/centos/7/images/CentOS-7-x86_64-GenericCloud-1905.qcow2

安装DIB和Virt

yum install centos-release-openstack-train
yum install diskimage-builder
yum install libguestfs-tools-c libguestfs-tools

设置环境变量, 如何你希望再build一个centos 7.9 镜像,那么你只需要把 avoid pacage update 这个去掉就可以。

export LIBGUESTFS_BACKEND=direct
export DIB_LOCAL_IMAGE="/root/cloud-images/CentOS-7-x86_64-GenericCloud-1905.qcow2" 
export DIB_RELEASE=7
export DIB_CLOUD_INIT_ALLOW_SSH_PWAUTH="yes"
export DIB_AVOID_PACKAGES_UPDATE=1
export image_name='CentOS-7.6-x86.qcow2'

设置好环境变量,后续就简单了。

openstack平台

DIB_CLOUD_INIT_DATASOURCES="ConfigDrive, OpenStack"  disk-image-create -a amd64 -o $image_name  -x --image-size 40 vm base centos disable-selinux cloud-init cloud-init-datasources dhcp-all-interfaces growroot

Zstack

disk-image-create -a amd64 -o  $image_name -x --image-size 40 vm base centos disable-selinux cloud-init dhcp-all-interfaces growroot

这样也就几分钟就可以创建出镜像。

# 设置时区

virt-customize -a $image_name --timezone "Asia/Shanghai" 

#安装工具

virt-customize -a $image_name --install [net-tools,wget,vim,unzip,qemu-guest-agent,epel-release] 

#启动服务
virt-customize -a $image_name --run-command 'systemctl enable qemu-guest-agent' 


#SSH服务
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/GSS/#GSS/'
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/#UseDNS yes/UseDNS no/'

#vim
virt-customize -a $image_name --append-line '/etc/profile:alias vi=vim'

#查看修改
virt-cat -a $image_name /etc/ssh/sshd_config 


#上传优化脚本和运行。可以选择不使用脚本,也是可以完成相关工作。

virt-customize -a $image_name --upload /root/centos.sh:/root/centos.sh 
virt-customize -a $image_name -chmod 755:/root/centos.sh 
virt-customize -a $image_name --run '/root/centos.sh'
virt-customize -a $image_name --run-command 'yum clean all'
virt-customize -a $image_name --run-command 'yum makecache'

不使用脚本,只使用virt-customize

virt-customize -a $image_name --delete '/etc/yum.repos.d/CentOS-*'
virt-customize -a $image_name --upload /root/CentOS.Base.repo:/etc/yum.repos.d/CentOS.Base.repo
virt-customize -a $image_name --upload /root/epel.repo:/etc/yum.repos.d/epel.repo
virt-customize -a $image_name --run-command 'yum clean all'
virt-customize -a $image_name --run-command 'yum makecache'
virt-customize -a $image_name --append-line '/etc/profile:alias vi=vim'

centos.sh 脚本的内容

!/bin/bash

sed -e 's!^metalink=!#metalink=!g' \
    -e 's!^#baseurl=!baseurl=!g' \
    -e 's!//download\.fedoraproject\.org/pub!//mirrors.tuna.tsinghua.edu.cn!g' \
    -e 's!http://mirrors\.tuna!https://mirrors.tuna!g' \
    -i.bak \
         /etc/yum.repos.d/epel.repo

sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-Base.repo

最后一步,安装zstack的agent

virt-customize -a $image_name --firstboot-command '/bin/bash -c "$(curl -s -S http://169.254.169.254/vm-tools.sh)"'

上传镜像

python -m SimpleHTTPServer 80

centos 7.6 repo模版 CentOS-Base.repo

[base]
name=CentOS-7.6.1810 - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-7.6.1810 - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-7.6.1810 - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centos-vaultplus]
name=CentOS-7.6.1810 - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.6.1810/centos-vaultplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

epel.repo

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
Mar 232021
 

最近打算搞裸机测试,如果用虚拟机来做裸机测试,最大的一个难点就是如何模拟IPMI。

OpenStack经常都是项目开发过程中,解决了很多现实的问题,专门开发了一个IPMI模拟工具。

yum -y install python3-pip python3-devel gcc libvirt-devel ipmitool
pip3 install --upgrade pip
pip3 install virtualbmc

上面的代码,应该是这物理机器上安装,当然你也可以这虚拟机安装,管理你虚拟机里创建出来的虚拟机。

参考下面的文档来操作。

参考文章

  • https://ikhsanputra.com/posts/2020-03-16-install-virtualbmc-on-centos-7/
  • https://segmentfault.com/a/1190000022482150
  • https://www.cnblogs.com/microman/p/6107879.html
  • https://ironic-book.readthedocs.io/zh_CN/latest/ironic/vbmc.html