Table of Contents

How to use CentOS on Vagrant



CentOS8

Download CentOS8 box

https://app.vagrantup.com/boxes/search

centos/8    #Officail Vagrant
or
generic/centos8


Check after vagrant up

hostname
ip a |grep inet
localectl status  # Check LANG, keymap
timedatectl status  # Time zone
python --version


Settings after vagrant up

python
yum install python36

python3 -m pip -V   <- check version
python3 -m pip install --upgrade pip   <- pip upgrade
python3 -m pip -V   <- check version

pip search fabric3
pip install fabric3

#===========================================
# Basic Configuration
#===========================================
hostnamectl set-hostname centos8a
localectl set-locale LANG=ja_JP.utf8
timedatectl set-timezone Asia/Tokyo

#ssh
cp -f /etc/ssh/sshd_config  /etc/ssh/sshd_config.`date -d '1day ago' +%Y%m%d`
sed -i "s/^PasswordAuthentication.*no/PasswordAuthentication\tyes/g" /etc/ssh/sshd_config
sdiff -s /etc/ssh/sshd_config  /etc/ssh/sshd_config.`date -d '1day ago' +%Y%m%d`
systemctl reload sshd


#===========================================
# User
#===========================================
useradd kurity
echo 'kurity:kurity' | chpasswd


#===========================================
# yum
#===========================================
dnf -y update

# commands
rpm -q epel-release      > /dev/null 2>&1 || yum -y install epel-release
rpm -q bash-completion   > /dev/null 2>&1 || yum -y install bash-completion
rpm -q traceroute        > /dev/null 2>&1 || yum -y install traceroute
rpm -q vim-enhanced      > /dev/null 2>&1 || yum -y install vim-enhanced
rpm -q tree              > /dev/null 2>&1 || yum -y install tree
rpm -q telnet            > /dev/null 2>&1 || yum -y install telnet
rpm -q bind-utils        > /dev/null 2>&1 || yum -y install bind-utils
rpm -q tcpdump           > /dev/null 2>&1 || yum -y install tcpdump
rpm -q sysstat           > /dev/null 2>&1 || yum -y install sysstat
rpm -q tcpdump           > /dev/null 2>&1 || yum -y install tcpdump
rpm -q net-snmp          > /dev/null 2>&1 || yum -y install net-snmp
rpm -q net-snmp-utils    > /dev/null 2>&1 || yum -y install net-snmp-utils
rpm -q wget              > /dev/null 2>&1 || yum -y install wget
rpm -q rsync             > /dev/null 2>&1 || yum -y install rsync
rpm -q nmap              > /dev/null 2>&1 || yum -y install nmap
rpm -q net-tools         > /dev/null 2>&1 || yum -y install net-tools
rpm -q mailx             > /dev/null 2>&1 || yum -y install mailx
rpm -q nmap-ncat         > /dev/null 2>&1 || yum -y install nmap-ncat
rpm -q ccze              > /dev/null 2>&1 || yum -y install ccze

#
dnf install git

#docker
dnf install -y docker

#Infrastracture as Code
dnf install  ansible




CentOS7

Download CentOS7 box

https://app.vagrantup.com/boxes/search

centos/7    #Officail Vagrant
or
generic/centos7


Check after vagrant up

hostname
ip a |grep inet
localectl status  # Check LANG, keymap
timedatectl status  # Time zone
python --version


Settings after vagrant up

#===========================================
# Basic Configuration
#===========================================
hostnamectl set-hostname centos7
localectl set-locale LANG=ja_JP.utf8
timedatectl set-timezone Asia/Tokyo

#ssh
cp -f /etc/ssh/sshd_config  /etc/ssh/sshd_config.`date -d '1day ago' +%Y%m%d`
sed -i "s/^PasswordAuthentication.*no/PasswordAuthentication\tyes/g" /etc/ssh/sshd_config
sdiff -s /etc/ssh/sshd_config  /etc/ssh/sshd_config.`date -d '1day ago' +%Y%m%d`
systemctl reload sshd


#===========================================
# User
#===========================================
useradd kurity
echo 'kurity:kurity' | chpasswd


#===========================================
# yum
#===========================================
yum -y update

# commands
rpm -q epel-release      > /dev/null 2>&1 || yum -y install epel-release
rpm -q bash-completion   > /dev/null 2>&1 || yum -y install bash-completion
rpm -q traceroute        > /dev/null 2>&1 || yum -y install traceroute
rpm -q vim-enhanced      > /dev/null 2>&1 || yum -y install vim-enhanced
rpm -q tree              > /dev/null 2>&1 || yum -y install tree
rpm -q telnet            > /dev/null 2>&1 || yum -y install telnet
rpm -q bind-utils        > /dev/null 2>&1 || yum -y install bind-utils
rpm -q tcpdump           > /dev/null 2>&1 || yum -y install tcpdump
rpm -q sysstat           > /dev/null 2>&1 || yum -y install sysstat
rpm -q tcpdump           > /dev/null 2>&1 || yum -y install tcpdump
rpm -q net-snmp          > /dev/null 2>&1 || yum -y install net-snmp
rpm -q net-snmp-utils    > /dev/null 2>&1 || yum -y install net-snmp-utils
rpm -q wget              > /dev/null 2>&1 || yum -y install wget
rpm -q rsync             > /dev/null 2>&1 || yum -y install rsync
rpm -q nmap              > /dev/null 2>&1 || yum -y install nmap
rpm -q net-tools         > /dev/null 2>&1 || yum -y install net-tools
rpm -q mailx             > /dev/null 2>&1 || yum -y install mailx
rpm -q nmap-ncat         > /dev/null 2>&1 || yum -y install nmap-ncat
rpm -q ccze              > /dev/null 2>&1 || yum -y install ccze


#docker
yum install -y docker

#Infrastracture as Code
yum install -y ansible
yum install -y fabric

> vagrant package mycentos7 --output mycentos7.box




Vargant - How to use Vagrant