New CentOS 7 Server Setup Commands
From Labrats.us
Install From Image, with 'minimal install' option
Post install configuration
Update /etc/yum.repo.d/CentOS-Base.repo for archive support
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ baseurl=http://vault.centos.org/7.9.2009/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ baseurl=http://vault.centos.org/7.9.2009/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Remove Network Manager software
# /bin/systemctl disable NetworkManager # /bin/systemctl disable NetworkManager-dispatcher # yum erase NetworkManager-tui NetworkManager-glib NetworkManager
Configure Network
Run the commands below to set up a static ip address (192.168.1.221) and hostname (test-centos-1).
# export remote_hostname=guest1 # export remote_ip=192.168.1.221 # export remote_gateway=192.168.1.1 # hostnamectl set-hostname $remote_hostname # sed -i.bak "s/.*BOOTPROTO=.*/BOOTPROTO=none/g" /etc/sysconfig/network-scripts/ifcfg-eth0 # cat << EOF >> /etc/sysconfig/network-scripts/ifcfg-eth0 IPADDR0=$remote_ip PREFIX0=24 GATEWAY0=$remote_gateway DNS1="216.136.95.2" DNS2="64.132.94.250" NM_CONTROLLED="no" EOF # systemctl restart network # systemctl enable network.service # systemctl enable sshd # systemctl start sshd # echo "checking connectivity" # ping www.google.com
Disable selinux
# setenforce 0 # sed -i.bak "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
Remove Postfix, and add needed packages.
# yum -y erase postfix # yum -y install finger nc net-snmp net-snmp-perl net-snmp-utils ntp perl-Date-Manip \ perl-DBD-SQLite sendmail sendmail-cf sssd tcp_wrappers tcpdump telnet tftp \ tog-pegasus traceroute vim-enhanced wget oddjob-mkhomedir net-tools yum-cron \ bind-utils
Alternately, you can leave Postfix and just install needed packages.
# yum -y install finger nc net-snmp net-snmp-perl net-snmp-utils ntp perl-Date-Manip \ perl-DBD-SQLite sssd tcp_wrappers tcpdump telnet tftp tog-pegasus traceroute \ vim-enhanced wget oddjob-mkhomedir net-tools yum-cron bind-utils
Fix Time Zone
# rm -f /etc/localtime # ln -s /usr/share/zoneinfo/MST7MDT /etc/localtime
Turn off rp_filter
# echo "net.ipv4.conf.default.rp_filter = 0" > /etc/sysctl.d/rpfilter.conf
Update required Packages
# yum update kernel bash nss nspr ntp glibc cvs
Reboot Server to apply new kernel
# shutdown -r now
Remove old kernel so system scans cleanly and update kernel tools
# rpm -qa | grep kernel # yum -y erase kernel-<old kernel version> # yum -y update kernel-tools kernel-tools-libs
Install VM Tools
If this is a virtual machine, install the open vm tools.
# yum -y install open-vm-tools