CentOS 7 常用命令

时间:2023-03-08 22:12:46
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.-.el7.x86_64 # SMP Tue Aug :: UTC x86_64 x86_64 x86_64 GNU/Linux
[root@ltt01 ~]# cat /etc/redhat-release
CentOS Linux release 7.4. (Core)

7、用户

#添加hadoop用户
[root@node1 ~]# useradd hadoop #为hadoop用户设置密码
[root@node1 ~]# passwd hadoop #查看hadoop用户信息
[root@node1 hadoop]# id hadoop
uid=(hadoop) gid=(hadoop) groups=(hadoop) #删除用户 -r 删除主目录和邮件池
[root@node1 ~]# userdel -rf hadoop

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

#文件只读
[root@node1 ~]# ls -l /etc/sudoers
-r--r----- root root May : /etc/sudoers
#为此文件添加写权限
[root@node1 ~]# chmod -v u+w /etc/sudoers
mode of ‘/etc/sudoers’ changed from (r--r-----) to (rw-r-----)
[root@node1 ~]# ls -l /etc/sudoers
-rw-r----- root root May : /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 (rw-r-----) to (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: #) Respect the privacy of others.
#) Think before you type.
#) With great power comes great responsibility. [sudo] password for hadoop: