首页 > 其他 > 详细

CentOS7基础优化与常用配置

时间:2020-07-17 19:53:54      阅读:85      评论:0      收藏:0      [点我收藏+]

最小化全新安装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生效。

关闭防火墙

‘‘‘
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  
#   $符号在这里需要两个撬棍,进行转义

添加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 oldboy

隐藏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

CentOS7基础优化与常用配置

原文:https://www.cnblogs.com/wangxiang135/p/13331704.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!