Table of Content
install centos7 from iso
- download latest centos7 x64 minimal from link
- create new vm from virtualbox, choice redhat x64
memory 1GB HD 50GB disable audio, usb
- user: vagrant/vagrant, root/vagrant
NIC
ip addr
enp0s3 there without ip assigned.
changed to root, enable NAT enp0s3 ONBOOT,
$ su - # sed -i '/ONBOOT=no/ s/ONBOOT=no/ONBOOT=yes/' /etc/sysconfig/network-scripts/ifcfg-enp0s3 # sed -i '/UUID/d' /etc/sysconfig/network-scripts/ifcfg-enp0s3
then reboot.
ssh setup
ssh service is running,
[vagrant@centos7 ~]$ systemctl -l --type service --all|grep sshd sshd.service loaded active running OpenSSH server daemon [vagrant@centos7 ~]$ systemctl status sshd.service ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2017-12-31 21:09:00 EST; 10min ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 1086 (sshd) CGroup: /system.slice/sshd.service └─1086 /usr/sbin/sshd -D
add port forward 127.0.0.1:2222 to guest 22 in VB NAT setting.
then ssh to vm via ssh client , I use putty.
verify access
$ ip addr 2: enp0s3:mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:79:56:b7 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3 valid_lft 86166sec preferred_lft 86166sec inet6 fe80::1f1:31fd:187f:4f30/64 scope link valid_lft forever preferred_lft forever
access to Internet,
[vagrant@centos7 ~]$ ping -c 2 google.ca PING google.ca (172.217.12.67) 56(84) bytes of data. 64 bytes from dfw28s05-in-f3.1e100.net (172.217.12.67): icmp_seq=1 ttl=48 time=44.0 ms 64 bytes from dfw28s05-in-f3.1e100.net (172.217.12.67): icmp_seq=2 ttl=48 time=43.3 ms
add vagrant to sudo
[root@centos7 ~]# groupadd sudo [root@centos7 ~]# usermod -a -G sudo vagrant
make vagrant as sudo passwordless,
switch to root
[root@centos7 ~]# echo vagrant ALL=NOPASSWD:ALL > /etc/sudoers.d/vagrant [root@centos7 ~]# chmod 0440 /etc/sudoers.d/vagrant [root@centos7 ~]# ls -ltr /etc/sudoers.d total 4 -r--r-----. 1 root root 25 Dec 31 19:18 vagrant [root@centos7 ~]# cat /etc/sudoers.d/vagrant vagrant ALL=NOPASSWD:ALL
test sudo,
[vagrant@centos7 ~]$ sudo pwd /home/vagrant
ssh insecure keypair
[vagrant@centos7 ~]$ mkdir -p /home/vagrant/.ssh [vagrant@centos7 ~]$ chmod 0700 /home/vagrant/.ssh [vagrant@centos7 ~]$ curl -Lo /home/vagrant/.ssh/authorized_keys \ https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 409 100 409 0 0 662 0 --:--:-- --:--:-- --:--:-- 663 [vagrant@centos7 ~]$ chmod 0600 /home/vagrant/.ssh/authorized_keys [vagrant@centos7 ~]$ chown -R vagrant /home/vagrant/.ssh
verify sshd_config for authorized_keys,
[vagrant@centos7 ~]$ sudo cat /etc/ssh/sshd_config|grep authorized_keys AuthorizedKeysFile .ssh/authorized_keys
restart ssh service
[vagrant@centos7 ~]$ sudo /bin/systemctl restart sshd.service [vagrant@centos7 ~]$ sudo /bin/systemctl status sshd.service
update system
$ sudo yum -y update && sudo yum -y upgrade $ sudo yum install git $ curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" $ sudo python get-pip.py $ pip --version pip 9.0.1 from /usr/lib/python2.7/site-packages (python 2.7) $ sudo yum install dos2unix $ sudo yum install wget $ sudo yum install bzip2
SELinux to permissive mode
$ [vagrant@centos7 ~]$ sudo sed -i -e 's/^SELINUX=.*/SELINUX=permissive/' /etc/selinux/config
guest tool
fix kernel name issue,
$ ll /usr/src/kernels/
total 8
drwxr-xr-x. 22 root root 4096 Dec 31 21:30 3.10.0-693.11.1.el7.x86_64.debug
$ cd /usr/src/kernels/
$ sudo ln -s /usr/src/kernels/3.10.0-693.11.1.el7.x86_64.debug 3.10.0-693.11.1.el7.x86_64
$ export KERN_DIR=/usr/src/kernels/uname -r
install necessary package,
sudo yum install dkms gcc make kernel-devel bzip2 binutils patch libgomp glibc-headers glibc-devel kernel-headers
install Guest Additions,
$ sudo mount /dev/sr0/ /mnt $ cd /mnt $ sudo -E ./VBoxLinuxAdditions.run Verifying archive integrity... All good. Uncompressing VirtualBox 5.1.30 Guest Additions for Linux........... VirtualBox Guest Additions installer Removing installed version 5.1.30 of VirtualBox Guest Additions... Copying additional installer modules ... Installing additional modules ... vboxadd.sh: Starting the VirtualBox Guest Additions. Could not find the X.Org or XFree86 Window System, skipping.
-E is important, otherwise KERN_DIR env still missing.
test shared folder
add shared folder C:\oldhorse to oldhorse in virtualbox GUI, then reboot vm.
$ df -h |grep oldhorse oldhorse 440G 255G 186G 58% /media/sf_oldhorse $ mount |grep oldhorse oldhorse on /media/sf_oldhorse type vboxsf (rw,nodev,relatime)
this is just for test, vagrant will mount current folder to /vagrant by itself.
clean up
sudo dd if=/dev/zero of=/EMPTY bs=1M sudo rm -f /EMPTY sudo yum clean packages sudo yum clean headers sudo yum clean all sudo rm -rf /var/cache/yum cat /dev/null > ~/.bash_history && history -c
package vagrant box
$ mkdir ~/vagant/centos7box $ cd ~/vagant/centos7box $ vagrant package --output dreamcloud-centos7-vagrant.box --base centos7 ==> centos7: Clearing any previously set forwarded ports... ==> centos7: Exporting VM... ==> centos7: Compressing package to: C:/oldhorse/portableapps/msys64/home/oldhorse/vagrant/centos7box/dreamcloud-centos7-vagrant.box
643M dreamcloud-centos7-vagrant.box
test vagrant box
$ vagrant box add dreamcloud/centos7 dreamcloud-centos7-vagrant.box ==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'dreamcloud/centos7' (v0) for provider: box: Unpacking necessary files from: file://C:/oldhorse/portableapps/msys64/home/oldhorse/vagrant/centos7box/dreamcloud-centos7-vagrant.box box: Progress: 100% (Rate: 966M/s, Estimated time remaining: 0:00:01) ==> box: Successfully added box 'dreamcloud/centos7' (v0) for 'virtualbox'! $ vagrant box list|grep centos7 dreamcloud/centos7 (virtualbox, 0) $ vagrant init dreamcloud/centos7 AVagrantfile
has been placed in this directory. You are now ready tovagrant up
your first virtual environment! Please read the comments in the Vagrantfile as well as documentation onvagrantup.com
for more information on using Vagrant.
finally let’s boot up the box,
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! [default] GuestAdditions 5.1.30 running --- OK. ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => C:/oldhorse/portableapps/msys64/home/oldhorse/vagrant/centos7box
login to vm,
$ vagrant ssh [vagrant@centos7 ~]$ df -h|grep vagrant vagrant 440G 257G 183G 59% /vagrant [vagrant@centos7 vagrant]$ ping google.ca 64 bytes from dfw28s05-in-f3.1e100.net (172.217.12.67): icmp_seq=1 ttl=48 time=43.5 ms 64 bytes from dfw28s05-in-f3.1e100.net (172.217.12.67): icmp_seq=2 ttl=48 time=43.7 ms