CentOS7 优化

1、配置网卡

vi /etc/sysconfig/network-scripts/ifcfg-ens33      # ifcfg-ens33 OR ifcfg-eth0 视情况而定

BOOTPROTO=static                   # dhcp更改,启用静态IP地址
ONBOOT=yes                         # 开启自动启用网络连接
IPADDR="192.168.1.100"             # 设置的静态IP地址
NETMASK="255.255.255.0"            # 子网掩码
GATEWAY="192.168.1.1"              # 网关地址

systemctl restart network          # 重启网络
ping  www.baidu.com                # 测试网络是否正常

2、关闭iptables、firewall

#关闭firewall  centos7
systemctl stop firewalld        # 停止firewall防火墙
systemctl disable firewalld     # 禁止开机自启firewall防火墙
systemctl status  firewalld     # 查看firewall防火墙状态

3、关闭selinux---(重启系统生效)

sed -i.bak 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config

#临时关闭
setenforce 0
getenforce

4、ssh连接速度慢优化

sed -i.bak 's@#UseDNS yes@UseDNS no@g;s@^GSSAPIAuthentication yes@GSSAPIAuthentication no@g'  /etc/ssh/sshd_config

#重启ssh服务
systemctl restart sshd

5、更改yum源---(阿里镜像源)

yum install -y wget

#创建repo.bak备份原始源
mkdir /etc/yum.repos.d/repo.bak
mv /etc/yum.repos.d/C*  /etc/yum.repos.d/repo.bak

#下载阿里repo源和epel源到yum.repos.d目录
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

6、安装其他小软件

yum install -y git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim net-tools lrzsz tar unzip telnet nmap tree dos2unix nc telnet lsof ntpdate bash-completion bash-completion-extras

7、加大文件描述

ulimit -a       # 用来显示当前的各种用户进程限制
ulimit -n       # 查看当前用户默认的最大文件句柄数
lsof |wc -l     # 查看所有进程的文件打开数
lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr|more  # 查看当前进程打开了多少句柄数,注意第一列是句柄数,第二列是进程id
yum install -y lsof
lsof -i:22

加大文件描述
echo '*               -       nofile          65536' >>/etc/security/limits.conf

查看是否添加到limits.conf文件中
tail -1 /etc/security/limits.conf

临时修改
ulimit -n 65536
bash
ulimit -n 查看
bash
说明:
一个服务程序运行起来,会打开相应的文件
crond定时任务服务---systemctl start crond --- 打开相应文件
/var/spool/cron/root --- 加载打开配置文件
/var/log/cron --- 加载打开日志文件

8、英文字符集

echo $LANG    # 查看当前字符集

localectl set-locale LANG="en_US.UTF-8"

9、修改主机名

hostname [参数] [主机名]                # 临时修改
hostnamectl set-hostname <主机名>       # 永久修改

hostname       # 查看主机名

10、提权user用户可以sudo (可选配置)

useradd user   # 用户名
echo 123456|passwd --stdin user
\cp /etc/sudoers /etc/sudoers.ori
echo "user  ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoers
tail -1 /etc/sudoers
visudo -c
 
posted @ 2022-05-17 21:59  荔枝的汁  阅读(97)  评论(0编辑  收藏  举报