Skip to content

Latest commit

 

History

History
301 lines (225 loc) · 8.13 KB

centos-setup.md

File metadata and controls

301 lines (225 loc) · 8.13 KB

CentOS Setup

Install CentOS with a flash drive

Remember to add the user to administrator group when create an user.

Setup network

  1. List ethernet card

    nmcli d
  2. Open Network manager and edit connection.

    nmtui

    Choose “Automatic” in IPv4 CONFIGURATION and check Automatically connect check box and press OK and quit from Network manager.

  3. Reset network service

    service network restart
  4. Forwarding external port to port 22 manually. This setup is not necessary if the router has the capability of forwarding ports.

    firewall-cmd --zone=public --add-masquerade --permanent
    firewall-cmd --zone=public --add-forward-port=port=6301:proto=tcp:toport=22 --permanent
    firewall-cmd --reload

Setup UI (if CentOS minimal)

  1. List available package groups

    yum group list
  2. Install Gnome GUI packages

    yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
  3. Enable GUI on system startup

    ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
  4. Reboot the machine to start the server in the graphical mode

    reboot

Bridge network

  1. Disabling NetworkManager

    chkconfig NetworkManager off
    chkconfig network on
    service NetworkManager stop
    service network start
  2. Open ifcfg-em1 (or ifcfg-eth0 depending on what ethernet card you have) in /etc/sysconfig/network-scripts. Make the following changes.

    #TYPE=Ethernet
    PROXY_METHOD=none
    BROWSER_ONLY=no
    #BOOTPROTO=dhcp <-------------It is very important to change dhcp to static
    BOOTPROTO=static
    #DEFROUTE=yes
    #IPV4_FAILURE_FATAL=no
    #IPV6INIT=yes
    #IPV6_AUTOCONF=yes
    #IPV6_DEFROUTE=yes
    #IPV6_FAILURE_FATAL=no
    #IPV6_ADDR_GEN_MODE=stable-privacy
    NAME=em1
    UUID=7c87469d-30c3-453f-854a-104142f03bee
    DEVICE=em1
    ONBOOT=yes
    BRIDGE=br0   <---------------This line is also very important
  3. Modify/Create ifcfg-br0 in the same folder to define bridge device

    DEVICE="br0"
    BOOTPROTO=static
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    ONBOOT=yes
    TYPE=Bridge
    DELAY=0
    IPADDR=192.168.29.190
    NETMASK=255.255.255.0
    GATEWAY=192.168.29.1
  4. Restart networking

    service network restart
  5. Check shared physical device

    brctl show

    A table that similar to the following should show up

    bridge name bridge id STP enabled interfaces
    br0 8000.f8b156c47f7d no em1
    vnet0
    vnet1
    virbr0 8000.5254006ad49e yes virbr0-nic

Setup VM

  1. Install KVM

    yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install
  2. Start the libvirtd service

    systemctl enable libvirtd
    systemctl start libvirtd
  3. Verify kvm installation. Make sure KVM module loaded using lsmod command and grep command.

    lsmod | grep -i kvm

Option 1: Create VM via commandline

  1. Direct to /var/lib/libvirt/images, and download CentOS image from web.

    cd /var/lib/libvirt/images
    wget http://mirror.trouble-free.net/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1804.iso
  2. Use virt-install to create VM

    virt-install \
    --virt-type=kvm \
    --name centos7 \
    --ram 2048 \
    --vcpus=1 \
    --os-variant=centos7.0 \    
    --cdrom=/var/lib/libvirt/boot/CentOS-7-x86_64-Minimal-1804.iso \
    --network=bridge=br0,model=virtio \
    --graphics vnc \
    --disk path=/var/lib/libvirt/images/centos7.qcow2,size=40,bus=virtio,format=qcow2
  3. Intall virt-viewer

    yum install virt-viewer
  4. Launch VM with virt-viewer

    virt-viewer --domain-name VMName

Option 2: Create VM via virt-manager

  1. Install virt-manager

    yum install virt-manager
  2. Start virt-manager

    virt-manager
  3. Follow the UI instructions to create VM

Setup network for VM

  1. Repeat the process of Setup network to setup network for VM.

  2. Open ifcfg-em1 (or ifcfg-eth0 depending on what ethernet card you have) in /etc/sysconfig/network-scripts. Make the following changes. NOTE: Unlike the step described in Bridge network, the change of ifcfg-em1 (or ifcfg-eth0) do not need a bridge.

    TYPE=Ethernet
    PROXY_METHOD=none
    BROWSER_ONLY=no
    BOOTPROTO=static        <---------- change dhcp to static is important
    #DEFROUTE=yes
    #IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    #IPV6_DEFROUTE=yes
    #IPV6_FAILURE_FATAL=no
    #IPV6_ADDR_GEN_MODE=stable-privacy
    NAME=eth0
    UUID=a71e47e3-8622-459b-b9b3-a1b41f93fa64
    DEVICE=eth0
    ONBOOT=yes
    IPADDR=192.168.29.192   <------------ assign an address for VM
    NETMASK=255.255.255.0
    GATEWAY=192.168.29.1
    DNS1=192.168.29.1

Setup UI for VM

Repeat the process of Setup UI to setup UI for VM. NOTE: again this step is only needed if use CentOS minimal.

Clone VMs

Option 1: clone VM via commandline

Using virt-clone to clone a guest. NOTE: Before proceeding with cloning, shut down the virtual machine.

virt-clone --original srcVMName --name newVMName --auto-clone

Option 2: clone VM via virt-manager

Refer to this link for clone VM via GUI.

Change IP address for cloned machine

  1. If you are using commandline, first, run virt-viewer to launch the cloned VM.
virt-viewer --domain-name newVMName
  1. Open ifcfg-em1 (or ifcfg-eth0 depending on what ethernet card you have) in /etc/sysconfig/network-scripts, and modify the value of IPADDR.

  2. Restart network service

    service network restart

Check connectivity

  1. Check connectivity to host machine. Use the router address

    ssh -p 6701 [email protected]
  2. Check connectivity to guest machine. Use the static address that assigned to each machine.

References

Setup network: https://lintut.com/how-to-setup-network-after-rhelcentos-7-minimal-installation/

Setup UI:https://www.itzgeek.com/how-tos/linux/centos-how-tos/install-gnome-gui-on-centos-7-rhel-7.html

Bridge network: https://wiki.libvirt.org/page/Networking#Bridged_networking_.28aka_.22shared_physical_device.22.29

Create VM: https://www.cyberciti.biz/faq/how-to-install-kvm-on-centos-7-rhel-7-headless-server/ https://www.linuxtechi.com/install-kvm-hypervisor-on-centos-7-and-rhel-7/

Clone VM: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_deployment_and_administration_guide/cloning-a-vm