linux系统的简单优化:
1.网卡的配置优化:
添加一块网卡,实现一个虚拟机有两块网卡(内网网卡 外网网卡)
vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.255.10
NETMASK=255.255.255.0
GATEWAY=192.168.255.2
DNS1=192.168.255.2
2.hosts优化,/etc/hosts下设置网络框架中的主机
[root@041840612cjd ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.28.5 lb01
172.16.28.6 lb02
172.16.28.7 web01
172.16.28.8 web02
172.16.28.9 web03
172.16.28.51 db01 db01.etianetian.org
172.16.28.31 nfs01
172.16.28.41 backup
172.16.28.61 m01
3.配置yum源和epel源
cd /etc/yum.repos.d
1)Base.repo 源 配置为国内的aliyun或者清华源
[Base]
name=Base
baseurl=https://mirror.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/
gpgcheck=0
enable=1
清空缓存重新建立缓存
[root@test ~]# yum clean all && yum makecache fast
2)epel源的配置
直接进行安装
[root@test ~]#yum -y install epel-release-7-13.noarch.rpm
4.关闭firewalld 和 selinux
firewalld:
[root@test ~]# systemctl stop firewalld
[root@test ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
selinux:
/etc/selinux/config
SELINUX=disable
[root@test ~]# setenforce 0 设置selinux临时关闭(shutdown 0 shutup 1)
[root@test ~]# getenforce
Permissive
永久关闭要修改配置文件
5.创建一个普通用户
[root@test ~]# useradd huajia
[root@test ~]# echo 123456 | passwd --stdin huajia
Changing password for user huajia.
passwd: all authentication tokens updated successfully.
配置普通用户的权限:vim /etc/sudoers
echo "oldboy ALL=(ALL) NOPASSWD:ALL " >> /etc/sudoers
tail -1 /etc/sudoers
visudo -c
oldboy ALL=(ALL) NOPASSWD:ALL
第一个ALL 表示所有计算机
第二个ALL 表示所有的用户
第三个ALL 表示所有的命令
NOPASSWD:ALL 表示输入命令无需密码
6.英文字符集优化
[root@test ~]# echo $LANG
en_US.UTF-8
[root@test ~]# localectl set-locale LANG=“en_US.UTF-8”
7.配置主机的时间同步服务 ntpdata + crond
[root@test ~]# yum -y install ntpdata
vim /var/spool/cron/root
#time sync by huajia 2021-6-5
*/5 * * * * /usr/sbin/ntpdate ntp1.aliyum.com > /dev/null 2>&1
8.加大系统的文件打开数量
说明:一个服务程序运行起来,会打开相应的文件
crond 定时任务服务启动后会打开相应文件,加载其中的配置
/var/spool/cron/root — 加载配置文件
/var/log/cron -----加载打开日志文件
lsof -i:22 查看22号端口打开文件的数量
lsof(list system open file)
设置系统打开文件最大65535 /etc/security/limits.conf
echo "* - nofile 65535 ">>/etc/security/limits.conf
9.ssh的优化
sed -i ‘s@#UseDNS yes@UseDNS no@g;s@GSSAPIAuthentication yes@GSSAPIAuthentication no@g’ /etc/ssh/sshd_config
systemctl reload sshd
UseDNS : 使用DNS反向解析 开启连接较慢(建议关闭)
GSSAPIAuthentication
10.安装基础的命令
yum -y lrzsz nmap tree dos2unix nc telnet wget lsof ntpdate bash-completion bash-completion-extra