CentOS 7 常用命令

1、防火墙

yum install firewalld #安装firewalld 防火墙

systemctl start firewalld.service #开启防火墙

systemctl stop firewalld.service  #关闭防火墙

systemctl enable firewalld.service  #开机自动启动

systemctl disable firewalld.service  #关闭开机自动启动

systemctl status firewalld  #查看状态

firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

firewall-cmd --get-active-zones  #获取活动的区域

firewall-cmd --get-service  #获取所有支持的服务

 2、网络服务

#重启网络服务
systemctl retart network.service 
或
systemctl restart network

#启动网络服务
systemctl start network.service
或
systemctl start network

#停止网络服务
systemctl stop network.service
或
systemctl stop network

#查看IP 
ip a

 3、selinux

#查看selinux状态
sestatus  

#临时关闭
setenforce 0

#永久关闭,可以修改配置文件/etc/selinux/config,将其中SELINUX设置为disabled。(开启状态为 enforcing )

 4、路由网关

#查看路由表
ip route

5、hostname

vi /etc/hostname   #修改名字重启有效即可

6、查询系统信息

[root@ltt01 ~]# uname
Linux
[root@ltt01 ~]# uname -a
Linux ltt01.bg.com 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@ltt01 ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

 7、用户

#添加hadoop用户
[root@node1 ~]# useradd hadoop

#为hadoop用户设置密码
[root@node1 ~]# passwd hadoop

#查看hadoop用户信息
[root@node1 hadoop]# id hadoop
uid=1000(hadoop) gid=1000(hadoop) groups=1000(hadoop)

#删除用户  -r  删除主目录和邮件池
[root@node1 ~]# userdel -rf hadoop

 8、为普通用户设置sudo ,化身root进行操作

#文件只读
[root@node1 ~]# ls -l /etc/sudoers
-r--r----- 1 root root 3938 May 22 15:29 /etc/sudoers
#为此文件添加写权限
[root@node1 ~]# chmod -v u+w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)
[root@node1 ~]# ls -l /etc/sudoers
-rw-r----- 1 root root 3938 May 22 15:29 /etc/sudoers

#编辑
[root@node1 ~]# vi /etc/sudoers
root    ALL=(ALL)       ALL
hadoop  ALL=(ALL)       ALL

#收回写权限
[root@node1 ~]# chmod -v u-w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0640 (rw-r-----) to 0440 (r--r-----)

9、使用sudo 

[root@node1 ~]# su hadoop
[hadoop@node1 root]$ cat /etc/sudoers
cat: /etc/sudoers: Permission denied
[hadoop@node1 root]$ sudo cat /etc/sudoers

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for hadoop: 

  

  

 

  

原文地址:https://www.cnblogs.com/tijun/p/8650697.html