CentOS 7 常用初始化配置

本文介绍了CentOS常用的基础配置,当然生产环境还需慎重配置。

关闭防火墙

1
2
3
4
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
systemctl stop firewalld
systemctl disable firewalld

更换系统源

1
2
3
4
5
6
7
8
rm -rf /etc/yum.repos.d/*.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
sed -i '/aliyuncs/d' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
sed -i '/aliyuncs/d' /etc/yum.repos.d/epel.repo
yum clean all
yum makecache fast

更换网卡名称

1
2
3
4
5
6
7
8
9
# vim /etc/default/grub

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0"
GRUB_DISABLE_RECOVERY="true"
1
2
3
4
grub2-mkconfig -o /boot/grub2/grub.cfg
cd /etc/sysconfig/network-scripts/
mv ifcfg-ens33 ifcfg-eth0
vim ifcfg-eth0

禁用ipv6

1
2
3
4
5
6
7
8
9
# vim /etc/default/grub

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="ipv6.disable=1 rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0"
GRUB_DISABLE_RECOVERY="true"

删除多余kernel

1
2
3
uname -r
rpm -qa | grep kernel
yum remove xxx

yum update 不升级内核版本

如果不想升级内核及系统版本,则在执行 yum update之前在 /etc/yum.conf 的 [main] 后面添加以下配置

1
2
exclude=kernel* 
exclude=centos-release*

自动以root身份登陆gnome桌面

在/etc/gdm/custom.conf 的[daemon]下面添加:

1
2
3
[daemon]
AutomaticLoginEnable=True
AutomaticLogin=root #你想自动登录的用户名