CentOS7基础优化与常用配置

最小化全新安装CentOS7基础优化

配置yum源

mkdir -p /tmp/repo-bak  
mv /etc/yum.repos.d/* /tmp/repo-bak/  

配置阿里云基础yum源和epel源

cd /etc/yum.repos.d/  
curl http://mirrors.aliyun.com/repo/Centos-7.repo -o Centos-7.repo  
curl http://mirrors.aliyun.com/repo/epel-7.repo -o epel-7.repo

#CentOS7默认没有wget,curl的-o参数表示下载到的文件保存的路径和名称。
#阿里云镜像 https://opsx.alibaba.com/mirror

安装常用软件

yum install net-tools vim tree htop iotop iftop \
iotop lrzsz sl wget unzip telnet nmap nc psmisc \
dos2unix bash-completion sysstat rsync nfs-utils -y

#lrzsz - 用作上传下载
#bash-completion - 参数也支持自动补全,该功能需要重新连接Xshell生效。

修改时区

echo "ZONE=Asia/Shanghai" >> /etc/sysconfig/clock   
rm -f /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
timedatectl set-timezone Asia/Shanghai

关闭防火墙

systemctl disable firewalld.service  
systemctl stop firewalld.service  

关闭SELinux

sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config  
setenforce 0  

优化ulimit

echo '* - nofile 65535' >> /etc/security/limits.conf

最大默认打开的文件数是1024,这里改成了65535

历史命令记录改为1万条

sed -i '/^HISTSIZE=/c HISTSIZE=10000' /etc/profile

把命令提示符改为绿色

echo "export PS1='\e[32m[\u@\h \W]\\$ \e[0m'" >> /etc/profile  
source /etc/profile  
#   $符号在这里需要两个撬棍,进行转义

永久关闭linux swap

sysctl -w vm.swappiness=0                       #临时生效
echo "vm.swappiness = 0">> /etc/sysctl.conf     #永久生效(尽量不使用交换分区,注意不是禁用)
swapoff -a && swapon -a                         #可以执行命令刷新一次SWAP(将SWAP里的数据转储回内存,并清空SWAP里的数据)
sysctl -p                                       #(执行这个使其生效,不用重启)

添加vim配置文件

cat ~/.vimrc    
set tabstop=4    
set shiftwidth=4    
set expandtab " 使用空格替换TAB    

set nocompatible " 关闭兼容模式(无需兼容vi)    
set showcmd " 输入的命令显示出来,看的清楚些    

hi MatchParen ctermbg=Black guibg=lightblue    

" Must Exists   

添加一个普通用户wx

useradd wx
echo '123456' | passwd --stdin wx

隐藏Linux版本信息显示

cp /etc/issue /etc/issue.bak
> /etc/issue
cp /etc/issue.net /etc/issue.net.bak
> /etc/issue.net

CentOS7修改网卡为eth0

编辑网卡信息

cd /etc/sysconfig/network-scripts/  #进入网卡目录
mv ifcfg-eno16777728 ifcfg-eth0  #重命名网卡名称
cat ifcfg-eth0  #编辑网卡信息
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
NAME=eth0  #name修改为eth0
ONBOOT=yes
IPADDR=192.168.56.12
NETMASK=255.255.255.0
GATEWAY=192.168.56.2
DNS1=192.168.56.2

修改grub

cat /etc/sysconfig/grub  #编辑内核信息,添加红色字段的
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb net.ifnames=0 biosdevname=0 quiet"
GRUB_DISABLE_RECOVERY="true"
grub2-mkconfig -o /boot/grub2/grub.cfg  #生成启动菜单
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-229.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-229.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-1100f7e6c97d4afaad2e396403ba7f61
Found initrd image: /boot/initramfs-0-rescue-1100f7e6c97d4afaad2e396403ba7f61.img
Done

验证是否修改成功

reboot  #必须重启系统生效
yum install net-tools  #默认centos7不支持ifconfig 需要看装net-tools包
ifconfig eth0  #在次查看网卡信息
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.12  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::20c:29ff:fe5c:7bb1  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:5c:7b:b1  txqueuelen 1000  (Ethernet)
        RX packets 152  bytes 14503 (14.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 98  bytes 14402 (14.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
posted @ 2020-07-17 18:01  国际一级退堂鼓鼓手  阅读(350)  评论(0编辑  收藏  举报