linux基础系统优化

1.配置yum源

1、备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/

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

3、之后运行yum makecache生成缓存
4、查看源列表yum repolist

[root@docker ~]# yum repolist 
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
源标识              源名称                                     状态
base/7/x86_64       CentOS-7 - Base - mirrors.aliyun.com       10,019
extras/7/x86_64     CentOS-7 - Extras - mirrors.aliyun.com        419
updates/7/x86_64    CentOS-7 - Updates - mirrors.aliyun.com     2,146
repolist: 12,584

2.配置epel

1、备份(如有配置其他epel源)

mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup

2、下载新repo 到/etc/yum.repos.d/

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

3.安装常用工具软件命令

yum install -y tree vim bash-completion* wget lsof nc nmap lrzsz telnet psmisc bind-utils net-tools

4.关闭selinux和防火墙

关闭selinux

[root@wsm ~]# vim /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled                         #修改为disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected proces
ses are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

或者执行setenforce 0

关闭防火墙

[root@wsm ~]# systemctl stop firewalld NetworkManager
[root@wsm ~]# systemctl disable firewalld NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
[root@wsm ~]# systemctl is-active firewalld NetworkManager
unknown
inactive
[root@wsm ~]# systemctl is-enabled firewalld NetworkManager
disabled
disabled

5.优化ssh

修改ssh配置文件

[root@wsm ~]# vim /etc/ssh/sshd_config 

UseDNS yes 改为 UseDNS no
GSSAPIAuthentication yes 改为 GSSAPIAuthentication no

修改完成,重启服务

[root@wsm ~]# systemctl restart sshd

6.时间同步

crontab -e
####每隔五分钟同步时间
* */5 * * * sh ntpdate ntp1.aliyum.com >/dev/null 2>&1
###注意要提前安装ntpdate命令

脚本

#!/bin/bash
#linux基础优化自动执行脚本
#作者:wsm
#时间:2019-7-10


#优化yum源,改为国内阿里源及配置epel源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup &&
\curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo &&
\curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#安装常用工具及软件
yum install -y tree vim bash-completion* wget lsof nc nmap lrzsz telnet psmisc bind-utils net-tools
#关闭selinux和防火墙
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config && setenforce 0
systemctl stop firewalld NetworkManager
systemctl disable firewalld NetworkManager
#优化ssh
sed -i 's#GSSAPIAuthentication yes#GSSAPIAuthentication no#g' /etc/ssh/sshd_config
sed -i 's#UseDNS yes#UseDNS no#g' /etc/ssh/sshd_config
systemctl restart sshd

你可能感兴趣的:(linux基础系统优化)