系统基础的配置与优化

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了系统基础的配置与优化相关的知识,希望对你有一定的参考价值。

关闭Selinux

关闭selinux的方法:

[[email protected] ~]# vim /etc/selinux/config SELINUX=disabled --改成disabled
或
[[email protected] ~]# sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config 

修改配置文件保存后永久生效,但要reboot重启才能生效

临时关闭的方法:重启后会失效

[[email protected] ~]# getenforce       –先查看状态
Enforcing       --表示selinux开启的

[[email protected] ~]# setenforce 0     --类似与关闭

[[email protected] ~] getenforce        --查看状态
Permissive      --表示selinux暂时不会拦截

选择运行级别

设定运行级别为3,表示使用文本命令行模式管理Linux,如果最小化安装的则无需设置,

[[email protected] ~]# runlevel   ---查看当前运行的级别

[[email protected] ~]# init 3           --临时切换到3级别重启失效

[[email protected] ~]# vim /etc/inittab         --永久修改改配置文件
id:3:initdefault:    --最后一行改为

Linux的7种运行级别 0~6的简单介绍

0:关机模式 (系统默认运行级别不能为0级别,否则系统不能正常启动)

1:单用户模式(用于系统维护)

2:多用户模式

3:完全的多用户模式(生产环境中默认的运行级别)

4:未设置,保留

5:图形模式

6:重启(系统默认运行级别不能为6级别,否则系统将不能正常启动)

关闭防火墙

查看防火墙状态:
[[email protected] ~]# /etc/init.d/iptables status 或 service status iptables

关闭防火墙:
[[email protected] ~]# /etc/init.d/iptables stop    或 service stop iptables

设置防火墙开机不启动
[[email protected] ~]# chkconfig --level 2345 iptables off

[[email protected] ~]# chkconfig |grep iptables
iptables 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭

重启防火墙:

[[email protected] ~]# /etc/init.d/iptables restart

设置字符集

字符集的配置文件
[[email protected] ~]# cat /etc/sysconfig/i18n  

设置中文字符集
[[email protected] ~]# echo ‘LANG="zh_CN.UTF-8"‘ > /etc/sysconfig/i18n

重新加载配置文件生效
[[email protected] ~]# source /etc/sysconfig/i18n

查看字符集
[[email protected] ~]# echo $LANG
zh_CN.UTF-8

注:生产环境中用英文字符集(en_US.UTF-8)以免乱码现象
(centos7下的字符集配置文件为/etc/locale.conf)

设置闲置账号超时时间

临时设置用户5分钟内没操作就自动退出

[[email protected] ~]# export TMOUT=300
[[email protected] ~]# timed out waiting for input: auto-logout  --这句是系统的提示

永久生效修改配置文件

[[email protected] ~]# echo ‘export TMOUT=300‘ >> /etc/profile

只针对某个用户就用户的家目录下的 .bash_profile 文件里加入即可。

隐藏系统的版本号

删除配置文件里的内容即可

[[email protected] ~]# vim /etc/issue

[[email protected] ~]# vim /etc/issue.net

配置静态IP地址

[[email protected] ~]#ifconfig eth0 查看获取的IP

[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0    --只需要配置下面几行就可以了

DEVICE=eth0 --网卡名
TYPE=Ethernet --网卡类型
ONBOOT=yes --开机自动开启网卡
BOOTPROTO=static --静止的
IPADDR=10.0.0.250 --指定IP
NETMASK=255.255.255.0 --掩码
GATEWAY=10.0.0.2 --网关
DNS=114.114.114.114 

重启网络
[[email protected] ~]# /etc/init.d/network restart

修改主机名

[[email protected] ~]# hostname anuo   --临时修改主机名 

[[email protected] ~]# vim /etc/sysconfig/network  --修改主机名的配置文件
NETWORKING=yes
HOSTNAME=anuo     --指定新的主机名

设置主机名和IP地址绑定
[[email protected] ~]# vim /etc/hosts     
10.0.0.250   anuo.com    --再配置文件里的加上这句

配置本地yum源

[[email protected] ~]# mkdir /yum --创建挂载点

[[email protected] ~]# mount /dev/sr0 /yum --把光盘挂载到/yum目录

[[email protected] ~]# echo "mount /dev/sr0 /yum" >> /etc/rc.local

[[email protected] ~]# chmod a+x /etc/rc.d/rc.local --把rc.local原文件加执行权限,开机会自动执行

配置本地yum源

[[email protected] ~]# rm /etc/yum.repos.d/* -rf
这里我删除了它所有的默认的配置(因为这些默认配置要连公网的源,速度太慢,还有公网下载的都是最新版本可能会造成系统不兼容等问题)
[[email protected] ~]# vim /etc/yum.repos.d/local.repo  --创建本地yum源配置文件(注:配置文件要以.repo结尾)

[local]     
name=local
baseurl=file:///yum     --注意:这行必须指定光盘挂载点的全路径
enabled=1
gpgcheck=0

配置完上面yum后 执行清空缓存和建立缓存命令

[[email protected] yum.repos.d]# yum clean all

[[email protected] yum.repos.d]# yum makecache fast

现在可以安装些系统常用的命令了

[[email protected] yum.repos.d]# yum install lrzsz tree net-tools wget elinks -y

以上是关于系统基础的配置与优化的主要内容,如果未能解决你的问题,请参考以下文章

linux系统基础优化和安全重点小结

Linux基础优化与安全小结

Linux 基础优化配置

[vscode]--HTML代码片段(基础版,reactvuejquery)

Linux系统基础优化

Linux 基础优化与安全总结