Linux操作系统Centos7的常用操作有哪些呢,根据我的经验,下面总结一下:
1. 静态IP地址的配置
1 2 |
ls /etc/sysconfig/network-scripts/ //查看网卡列表 vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 //编辑网卡配置 |
网卡的配置信息如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
TYPE=Ethernet BOOTPROTO=static //原是dhcp,改为static DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=enp1s0f0 UUID=f032d1e7-ccca-49c7-a845-5a02c404694b DEVICE=enp1s0f0 ONBOOT=yes //原no,改为yes IPADDR=192.168.1.100 //新增 GATEWAY=192.168.1.1 //新增 NETMASK=255.255.255.0 //新增 NM_CONTROLLED=no //新增 DNS1=8.8.8.8 //新增 DNS2=8.8.4.4 //新增 |
2. 关闭SELinux
selinux防火墙的临时开启和关闭
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
临时关闭selinux setenforce 0 永久关闭selinux //设置后,需要重启操作系统才能生效 vi /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 //修改enforcing为disabled # SELINUXTYPE= can take one of three two values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted |
3. 设置系统时间
CentOS7设置时间使用的是timedatectl 命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
(1) 读取时间 timedatectl //等同于 timedatectl status (2) 设置时间 timedatectl set-time "YYYY-MM-DD HH:MM:SS" (3) 列出所有时区 timedatectl list-timezones (4) 设置时区 timedatectl set-timezone Asia/Shanghai (5) 是否NTP服务器同步 timedatectl set-ntp yes //yes或者no (6) 将硬件时钟调整为与本地时钟一致 timedatectl set-local-rtc 1 |
4. 安装Net-tools工具
最小化安装了一下CentOS7,会发现系统没有ifconfig这个网络命令
1 |
yum install net-tools -y |
5. 配置Yum源
系统默认的yum源速度往往不尽人意,为了达到快速安装的目的,在这里修改yum源为国内源。
我们用的比较多的Yum源为阿里或者是网易的源,配置方法如下:
1 2 3 4 5 6 7 8 9 |
首先备份/etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 使用阿里云Yum源(CentOS7): wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 使用网易Yum源(CentOS7): wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo 运行yum makecache生成缓存 |
6. 查看常用的命令
1 2 3 4 5 6 |
ps -ef //将某个进程显示出来 df -h //查看磁盘的剩余大小和使用量 du -sh* //对当前目录下每一个目录和文件的大小分别进行汇总 free -m //查看内存大小,用M做单位 netstat -naltp //查看监听了哪些端口 find / -name "filename" //在根目录下查找特定的文件 |