Centos7.X新安装linux系统基础配置

普通Linux分区方式:
/根分区 Linux系统必须要有的,相当于 Windows的C盘,系统程序相关的。
/boot分区 存放内核相关程序 是可选的 5 6给200M,7给256M(工作中1-2G)
swap分区 虚拟分区 作用内存不够的时候 系统就会把swap当做内存用。
防止因为内存不够死机。物理内存在8G以上,一般就给8G(可以给1.5倍)。
物理内存小于8G,就按1.5倍内存来给,例如:2G内给3G swap大小。
内存不够,swap分区来凑。
修改IP地址
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
IPADDR=172.x.x.137
NETMASK=255.255.255.0
GATEWAY=172.x.x254
ONBOOT=yes
USERCTL=yes
BOOTPROTO=static
 
 修改DNS
vi /etc/resolv.conf
# Generated by NetworkManager
nameserver 202.96.134.133
nameserver 114.114.114.114
 
systemctl restart network ###重启网络服务
 
配置yum环境(aliyun、epel)
yum -y install wget
cd /etc/yum.repos.d/ && mv CentOS-Base.repo CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
 
下载常用软件(生成本地缓存(install搜索)、补全、wget、vim、上传下载)
#CentOS6和CentOS7都要安装的企业运维常用基础工具包
yum install tree nmap dos2unix lrzsz nc lsof wget tcpdump htop iftop iotop sysstat nethogs traceroute vim lsof -y
#CentOS7要安装的企业运维常用基础工具包
yum install psmisc net-tools bash-completion vim-enhanced -y
yum makecache fast ##更新yum
yum -y update ##把补丁更新到最新
优化ssh 
vim /etc/ssh/sshd_config
UseDNS no
systemctl restart sshd ##重启sshd
修改selinux配置
vim /etc/selinux/config ###永久修改,但修改完需要重启才生效,但我们服务器一般很少重启,所以一般配合临时修改与配置修改的方式
SELINUX=disabled
setenforce 0 ##临时修改,因为配置文件修改后需要重新启动才生效
getenforce ###查看是否生效

如果大家是centos7默认是firewalld,但由于个人喜欢使用iptalbe所以一般安装操作系统后都会把firewalld卸载或者关了

rpm -e firewalld ###卸载firewalld
yum remove firewalld ###此方式不建议大家使用,因为会把一些依赖删除

systemctl disable firewalld ### 如果没有写在也可以通过此方式把firewalld关闭开机启动

systemctl stop firewalld
安装iptables
yum -y install iptables iptables-services ##安装iptables,注意此处需要安装iptables iptables-services否则iptables无法适应
systemctl start iptables ##开启iptables
systemctl enable iptables ##设置开机启动
常用命令iptables -L -n ###此命令用来查看配置的策略

原文地址:https://www.cnblogs.com/--smile/p/11055160.html