kvm無人值守安裝centos 7虛擬機
阿新 • • 發佈:2018-03-06
fire qcow parse clear conn port body LV linu
centos 7安裝好KVM之後還要安裝虛擬機,通過VNC連接手動安裝centos 7虛擬機太麻煩了,所以無人值守安裝是做好的。簡單記錄下。
無人值守安裝centos 7前提是要安裝KVM,並且能手動創建虛擬機。
首先創建centos7.ks.cfg文件 vi /root/centos7.ks.cfg
install #禁用第一次啟動時設置系統的向導 firstboot --disabled eula --agreed reboot # 系統語言 lang en_US.UTF-8 keyboard us # 設置時區 timezone --isUtc Asia/Shanghai # 關閉selinux和防火墻 selinux--disabled firewall --disabled # 開啟的服務 services --enabled=sshd,ntpd,ntpdate,network # 網絡設置比較復雜,建議安裝後再設置 # network --hostname pandora # 啟動方式、自動分區 clearpart --all --initlabel bootloader --location=mbr autopart --type=lvm zerombr # root 密碼為123@abc# auth --useshadow --enablemd5 rootpw --iscrypted $6$nLlYENVDvCsM/2SX$ZD6JgRkeuN1nW239DA53b33Yyl7j0MuAKCY/CKQ/YSdA3/6sBOqInIO67JJmssHb3HTCQLj4OlVfzwt7m8Bin0
#rootpw 123456 (明文) #repo --name=base --baseurl=http://centos.mirrors.ovh.net/ftp.centos.org/7/os/x86_64 #url --url="http://centos.mirrors.ovh.net/ftp.centos.org/7/os/x86_64" # 最小化安裝 %packages --nobase --ignoremissing @core #安裝一些組件 acpid net-tools ntp ntpdate wget %end %post echo "ttyS0" >> /etc/securetty sed -i ‘s/1:2345:respawn:\/sbin\/mingetty tty1/co:2345:respawn:\/sbin\/agetty ttyS0 115200 vt100-nav/‘ /etc/inittab sed -i ‘s/^HISTSIZE=.*$/HISTSIZE=100/‘ /etc/profile # /etc/security/limits.conf [ -z "`cat /etc/security/limits.conf | grep ‘nproc 65535‘`" ] && cat >> /etc/security/limits.conf < <EOF * soft nproc 65535 * hard nproc 65535 * soft nofile 65535 * hard nofile 65535 EOF [ -z "`cat /etc/rc.local | grep ‘ulimit -SH 65535‘`" ] && echo "ulimit -SH 65535" >> /etc/rc.local [ -z "`cat ~/.bashrc | grep ^PS1`" ] && echo ‘PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[35;40m\]\W\[\e[0m\]]\\$ "‘ >> /root/.bashrc # /etc/sysctl.conf sed -i ‘s/net.ipv4.tcp_syncookies.*$/net.ipv4.tcp_syncookies = 1/g‘ /etc/sysctl.conf [ -z "`cat /etc/sysctl.conf | grep ‘fs.file-max‘`" ] && cat >> /etc/sysctl.conf < < EOF fs.file-max=65535 net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.tcp_max_syn_backlog = 262144 net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.route.gc_timeout = 100 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_synack_retries = 1 net.core.somaxconn = 65535 net.core.netdev_max_backlog = 262144 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_max_orphans = 262144 EOF %end
關於配置裏面的root的密碼,首先看看python 的版本
[root@pandora qemu]# python -V Python 2.7.5 python的版本大於2.7的,運行設置密碼 python -c ‘import crypt,getpass; print(crypt.crypt(getpass.getpass(), crypt.mksalt(crypt.METHOD_SHA512)))‘ python的版本小於於2.7的,運行 python -c ‘import crypt; print crypt.crypt("CLEARTEXTPASSWORD", "$6$saltsalt$")‘ 當然,直接用腳本配置裏面的123@abc#的密碼也可以,安裝完後更改root密碼
接著用virt-install安裝虛擬機,就會自動按照centos7.ks.cfg的配置完成安裝
virt-install --accelerate --name=centos7-docker--hvm --virt-type kvm --boot hd --disk path=/home/storage/centos7-docker.qcow2,format=qcow2,size=300,sparse=true,cache=none,bus=scsi --network bridge:br0 --vcpus=8 --ram=8192 --os-type=linux --os-variant=rhel7 --graphics none --serial pty --console pty --location /home/iso/CentOS-7-x86_64-DVD-1511.iso --initrd-inject /home/iso/conf/base7.cfg --extra-args "inst.ks=file:/base7.cfg console=ttyS0"
kvm無人值守安裝centos 7虛擬機