KVM configuration whole process

Install Ubuntu 18.04 server(username: fengsiyun)

RAID 1 configure 300G system disk,2T data diskinstall net-tools

network:

    version: 2

    ethernets:

        eno1:
    
            dhcp4: no

            dhcp6: no

        eno2:

            dhcp4: yes

            dhcp6: yes

        eno3:

            dhcp4: yes

            dhcp6: yes

        eno4:

            dhcp4: no

            dhcp6: no

    bridges:

        br0:

            interfaces: [eno1]

            dhcp4: no

            addresses: [192.168.0.140/24]

            gateway4: 192.168.0.1

            nameservers:

                addresses: [192.168.0.1]

#Install KVM required software

sudo apt-get install qemu qemu-kvm libvirt-bin  bridge-utils  virt-manager  

#Start service

sudo service libvirtd start

#And set to start automatically

sudo update-rc.d libvirtd enable

#Install remote desktop

sudo apt-get install xrdp vnc4server tightvncserver xubuntu-desktop

#Write xfce4-session to xsession

echo “xfce4-session” >~/.xsession

#Open xrdp service

sudo service xrdp restart

 

# During the installation process, it was found that the "/" partition space is insufficient. Add a 2T hard disk, expand the vg, expand the root partition by 100G, create a new logical volume lv-3 1T, and mount it to /opt. The final partition and mount are as follows:

#Create a new virtual machine hard disk with a capacity of 40G and the format of qcow2

sudo qemu-img create -f qcow2 /opt/kvm/win2k12-0.qcow2 40G

#virt-install Install Windows server 2k12 

  • --name win2k12-1 #Virtual machine name
  • --ram 4096 #Virtual machine memory
  • --vcpus 2 #Virtual machine logical cpu number
  • --network bridge=br0 #Network card configuration information, Windows server 2016 virtual machine do not configure model=virtio, otherwise it will not be networked
  • --cdrom /home/fengsiyun/media/disk2/cn_windows_server_2012_r2_vl_with_update_x64_dvd_6052729.iso #Mirror file
  • --disk path=/opt/kvm/win2k12-1.qcow2,format=qcow2,size=40 #hard disk
  • --disk /home/fengsiyun/media/disk2/virtio-win-0.1.160_amd64.vfd,device=floppy #Windows driver
  • --os-type win #operating system type
  • --os-variant win2k12 #Detailed type
  • --graphics vnc,listen=0.0.0.0,keymap=en-us,port=6001,password=niancloud #graphic interface configuration information
  • --virt-type sqm     
  • --noautoconsole
  • --hvm #full virtualization
  • --autostart #Start with the host
  • --accelerate #performance optimization
sudo virt-install --description "ARK Server Manager" --name win2k12-1 --ram 4096 --vcpus 2 --network bridge=br0 --cdrom /home/fengsiyun/media/disk2/cn_windows_server_2012_r2_vl_with_update_x64_dvd_6052729.iso --disk path=/opt/kvm/win2k12-1.qcow2,format=qcow2,size=40 --disk /home/fengsiyun/media/disk2/virtio-win-0.1.160_amd64.vfd,device=floppy --os-type win --os-variant win2k12 --graphics vnc,listen=0.0.0.0,keymap=en-us,port=6001,password=niancloud --virt-type kvm --noautoconsole --hvm --autostart --accelerate

#Install and configure FTP server

#Install vsftpd

sudo apt-get -y install vsftpd

#Backup the original configuration file

sudo mv /etc/vsftpd.conf /etc/vsftpd.conf.orig

#Create a new system user

sudo useradd -m -s /bin/bash ftpwunian

#Set the ftp file directory

cd /home/ftpwunian/

sudo mkdir -p www/ftp

sudo chown ftpwunian:ftpwunian /home/ftpwunian/www/ftp

sudo chmod -Rf  755 /home/ftpwunian/

#Set the user name and password file for user login:

sudo mkdir /etc/vsftpd/

sudo vim /etc/vsftpd/login.txt

wunian
000000

#login.txt After setting up, we will use db_load to encrypt

#Install db-util

sudo apt-get -y install db-util

sudo db_load -T -t hash -f /etc/vsftpd/login.txt /etc/vsftpd/login.db

sudo rm -rf login.txt

#Create required documents for PAM verification

 sudo vim /etc/pam.d/vsftpd.virtual

auth required pam_userdb.so db=/etc/vsftpd/login

account required pam_userdb.so db=/etc/vsftpd/login

# /etc/vsftpd.conf

listen=YES

listen_ipv6=NO

anonymous_enable=NO

#启用系统用户的写权限

local_enable=YES

write_enable=YES

local_umask=022

dirmessage_enable=YES

use_localtime=YES

xferlog_enable=YES

connect_from_port_20=YES

xferlog_file=/var/log/vsftpd.log

xferlog_std_format=YES

#配置vsftpd用户禁止切换上级目录的权限

chroot_local_user=YES

chroot_list_enable=NO

allow_writeable_chroot=YES

secure_chroot_dir=/var/run/vsftpd/empty

pam_service_name=vsftpd

rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem

rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key

ssl_enable=NO

#启用vsftpd虚拟用以及虚拟用户账号配置目录

guest_enable=YES

pam_service_name=vsftpd.virtual

user_config_dir=/etc/vsftpd/vu

#配置是否启用被动连接和端口号范围

pasv_enable=YES

pasv_min_port=5900

pasv_max_port=5999

#Configure the relevant permissions of virtual users

sudo mkdir /etc/vsftpd/vu

sudo vim / etc / vsftpd / vu / wunian

guest_username=ftpwunian #表示的是设置FTP对应的系统用户为ftpwunian

local_root=/home/ftpwunian/www/ftp/ #表示使用本地用户登录到ftp时的默认目录

virtual_use_local_privs=YES #虚拟用户和本地用户有相同的权限

anon_umask=133 #表示文件上传的默认掩码

#Firewall open ports 5900-5999

sudo ufw allow 5900:5999/tcp

#Restart vsftpd, and set to start automatically

sudo systemctl restart vsftpd

sudo systemctl enable vsftpd

Virtual machine disk expansion

Expand the Windows virtual machine capacity by 60G, and then expand the volume

qemu-img resize win2k16-1.qcow2 60G

 

Guess you like

Origin blog.csdn.net/geeksoarsky/article/details/86713203