centos7 系统初始化配置


1、设置ip地址

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens192
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
NAME="ens192"
DEVICE="ens192"
ONBOOT="yes"
IPADDR="192.168.82.232"
PREFIX="24"
GATEWAY="192.168.82.1"
DNS1="114.114.114.114"
[root@localhost ~]#

2、修改主机名

hostnamectl set-hostname postmail

3、更改yum源、update

#备份现有源配置
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#下载并替代本地源
yum install -y wget
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#修改Centos-7.repo文件将所有$releasever替换为7
yum install -y vim
vim /etc/yum.repos.d/CentOS-Base.repo
#输入替换命令
%s/$releasever/7/g

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum clean all yum makecache #添加epel源 yum install -y epel-release #update yum -y update

 如果wget不能通过yum安装,则rpm安装

#rpm安装wget
rpm -ivh http://mirrors.163.com/centos/7/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm

4、关闭防火墙

#查看防火墙状态
[root@postmail ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2022-03-29 16:06:36 CST; 3min 0s ago
     Docs: man:firewalld(1)
 Main PID: 26416 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─26416 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

Mar 29 16:06:35 postmail systemd[1]: Starting firewalld - dynamic firewall daemon...
Mar 29 16:06:36 postmail systemd[1]: Started firewalld - dynamic firewall daemon.
Mar 29 16:06:36 postmail firewalld[26416]: WARNING: AllowZoneDrifting is enabled. This i...w.
Hint: Some lines were ellipsized, use -l to show in full.
[root@postmail ~]#

#关闭防火墙
[root@postmail ~]# systemctl stop firewalld
[root@postmail ~]#
#关闭开机启动防火墙
[root@postmail ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@postmail ~]#

5、关闭selinux

#查看selinux状态
[root@postmail ~]# getenforce
Enforcing
#临时关闭
[root@postmail ~]# setenforce 0
[root@postmail ~]# getenforce
Permissive
#永久关闭
#SELINUX=enforcing 改为 SELINUX=disabled
[root@postmail ~]# vim /etc/sysconfig/selinux
[root@postmail ~]#

6、调整系统时区

[root@postmail ~]# timedatectl set-timezone Asia/Shanghai
[root@postmail ~]# timedatectl set-local-rtc 0
[root@postmail ~]# systemctl restart rsyslog
[root@postmail ~]# systemctl restart crond
[root@postmail ~]#

7、关闭系统不需要的服务

[root@postmail ~]# ss -tnl
State       Recv-Q Send-Q Local Address:Port                Peer Address:Port
LISTEN      0      128                *:22                             *:*
LISTEN      0      100        127.0.0.1:25                             *:*
LISTEN      0      128             [::]:22                          [::]:*
LISTEN      0      100            [::1]:25                          [::]:*
[root@postmail ~]# systemctl stop postfix && systemctl disable postfix
Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.
[root@postmail ~]#
[root@postmail ~]# ss -tnl
State       Recv-Q Send-Q Local Address:Port                Peer Address:Port
LISTEN      0      128                *:22                             *:*
LISTEN      0      128             [::]:22                          [::]:*

8、安装net-tools

[root@postmail ~]# yum install -y net-tools