1、查看系统版本信息
[root@shell ~]#
[root@shell ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@shell ~]#
[root@shell ~]# cat /etc/os-release
2、查看内核版本
[root@shell ~]# uname -r
3.10.0-862.el7.x86_64
[root@shell ~]#
3、永久修改主机名
[root@shell ~]# hostnamectl set-hostname shell #非交互式设置主机名
[root@shell ~]# cat /etc/hostname #交互式修改主机名
4、设置字符集
[root@shell ~]# echo $LANG #查看当前默认字符集是什么
zh_CN.UTF-8
[root@shell ~]# echo "LANG=zh_CN.UTF-8" > /etc/locale.conf #非交互式永久设置字符集
[root@shell ~]# cat /etc/locale.conf #交互式永久设置中文字符集
LANG="zh_CN.UTF-8"
[root@shell ~]#
[root@shell ~]# localectl
5、非交互式设置账号和密码
[root@shell ~]# useradd xinhua && echo “xinhua@2020” | passwd --stdin xinhua #非交互式添加账号xinhua并设置密码为xinhua@2020
[root@shell ~]# echo "123456"|passwd --stdin xinhua && history -c #非交互式修改用户xinhua的密码为123456
6、关闭 NetworkManager
在CentOS系统上,目前有NetworkManager和network两种网络管理工具。如果两种都配置会引起冲突,而且NetworkManager在网络断开的时候,会清理路由,如果一些自定义的路由,没有加入到NetworkManager的配置文件中,路由就被清理掉,网络连接后需要自定义添加上去。
目前在CentOS上的NetworkManager版本比较低,而且比较适合有桌面环境的系统,所以服务器上保留network服务即可,将NetworkManager关闭,并且禁止开机启动。
[root@shell ~]# systemctl status NetworkManager #查看NetworkManager状态
[root@shell ~]# systemctl stop NetworkManager #关闭NetworkManager
[root@shell ~]# systemctl disable NetworkManager #关闭开机自启动
7、centos-7 更换阿里云yum源
默认国外的 yum源(软件仓库)获取比较慢,所以换成国内的镜像源
1)备份原来的yum源文件
[root@shell ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2)下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
[root@shell ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者使用如下命令,两条命令效果一样
[root@shell ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3)添加阿里云epel源
[root@shell ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
4)清理原缓存并生成新的yum缓存
[root@shell ~]# yum clean all
[root@shell ~]# yum makecache
[root@shell ~]# yum repolist
8、linux设置登录超时自动退出
设置用户在不操作的情况下,linux系统将用户自动登出,需要使用的时候,重新输入密码即可
[root@shell ~]# vi /etc/profile
# 在配置文件最末尾加入以下一行内容,300秒表示5分钟不操作就需要重新输入密码登录,时间可以自定义
export TMOUT=300
[root@shell ~]# tail -1 /etc/profile
[root@shell ~]# source /etc/profile #配置完成执行此命令,使配置立即生效
9、设置登录超时自动锁屏
此设置仅针对安装有桌面环境的linux
依次点击:用用程序 —>系统工具 —>设置—>隐私—>锁屏—>黑屏至锁屏的等待时间
10、CentOS 关闭一些不必要的启动项,减少系统资源消耗
CentOS-7 已不再使用 chkconfig 管理启动项
使用 systemctl list-unit-files 可以查看启动项
[root@shell ~]# systemctl list-unit-files #查看centos-7存在哪些启动项
[root@shell ~]#
[root@shell ~]# systemctl list-unit-files | grep enabled #查看当前centos-7系统存在哪些开机自启动项
11、ssh服务远程登录配置
/etc/ssh/sshd_config #ssh服务的配置文件
为了安全起见一般需要修改的地方,ssh服务的默认端口+是否允许root用户远程登录;
当然了也可以不修改(根据公司实际要求来权衡)
如果修改了的话,一定要重启ssh服务,使配置生效
12、查看环境变量
env
[root@shell ~]# env
13、调整系统文件描述符数量
[root@shell ~]# ulimit -n
系统文件描述符默认大小为1024,文件描述符对于高并发的Linux服务器来说,这个默认值是不够的
[root@shell ~]# echo '* - nofile 65535' >> /etc/security/limits.conf #调整文件描述符数值为65535
[root@shell ~]# tail -1 /etc/security/limits.conf
[root@shell ~]# logout #修改完以后,退出重新登录使修改生效
14、给重要文件、敏感文件加锁
chattr +i /etc/{passwd,shadow,group,gshadow} #给文件加锁,加锁以后没法删除文件
lsattr -a /etc/{passwd,shadow,group,gshadow} #查看上锁的效果
chattr -i /etc/{passwd,shadow,group,gshadow} #给文件解锁
15、安装常用命令
[root@shell ~]#
[root@shell ~]# yum install lrzsz lsof nmap tree nc dos2unix bash-completion net-tools bind-utils vim wget
16、Linux内核优化