Linux基本命令四

该文章内容包括四部分,分别为
1.vi命令
2.系统信息 进程 ps -ef|grep xxx 端口号 netstat -nlp |grep xxx
3.连接拒绝 (权限受限 ping telnet )
4.高危命令 rm -rf /
5.常用的命令 wget yum rpm 压缩解压

vi命令

在这里插入图片描述

1.1命令模式
常见快捷键

删除当前行:dd
删除当前和以下的所有行:dG
删除当前行和以下的n行:ndd
跳转到第一行的第一个字母:gg
跳转到最后一行:G
跳转到当前行的行尾:shift+$

1.1.1
案例场景: 从另外一个文本拷贝内容去覆盖这个文件,注意覆盖前一定要用cp命令进行备份一下

先使用gg+dG清除全部内容或者使用cat /dev/null > xxx.log 将该文件置空,然后i进行编辑模式,进行内容复制

1.2编辑模式
1.2.1粘贴内容

在vi编辑文件时,如需要粘贴内容进来,需要**先按i进入编辑模式**,然后再进行粘贴

1.3尾行模式
按:进入尾行模式
1.3.1找error

进入尾行模式后,输入 /关键字 进行匹配,然后按N键找下一个关键字

1.3.2设置行号

设置行号:进入尾行模式,输入 set nu
去除行号:进入尾行模式,输入 set nonu

系统命令

2.1查看磁盘信息

[root@JD tmp]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G  3.1G   37G   8% / #系统盘
/dev/vdb4        1T   10G    XXX   X% /data04 数据盘,有规律
/dev/vdb5        1T   10G    XXX   X% /data05 数据盘,有规律
devtmpfs        3.9G     0  3.9G   0% /dev 
tmpfs           3.9G   16K  3.9G   1% /dev/shm
tmpfs           3.9G  115M  3.8G   3% /run
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           783M     0  783M   0% /run/user/0

2.2查看内存信息

[root@JD tmp]# free -m #该命令展示字节信息
total        used        free      shared  buff/cache   available
Mem:      	 7823         191        6385         114        1246        7289
Swap:         0           0           0
[root@JD tmp]# free -g #该命令会展示内存信息
total        used        free      shared  buff/cache   available
Mem:         7           0           6           0           1           7
Swap:        0           0           0

2.3查看系统负载信息
分析系统信息
load average: 0.00, 0.01, 0.05
0.00, 0.01, 0.05:这三个值,根据经验,不要超过10,否则会有问题

查看系统负载信息时,如果看到cpu或内存占得比例很大,需要去查看下该进程的对应程序的原因,也有可能是硬件坏了,比如内存条坏了
例如:

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
177 root      20   0       0      0      0 S   50%  70%     0:34.13 xxxx   去看看xxx这个进程是做什么
1777 root      20   0       0      0     0 S  3908% 80%     0:34.13 hbase regionserver  夯住 有问题 代码级别 硬件级别 内存条坏了

查看负载命令

[root@JD tmp]# top
top - 15:09:47 up 5 days,  5:39,  1 user,  load average: 0.00, 0.01, 0.05
Tasks:  92 total,   1 running,  91 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.2 us,  0.3 sy,  0.0 ni, 99.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  8011076 total,  6537620 free,   197100 used,  1276356 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  7463344 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                         
  557 root      20   0  161844   2196   1552 R   0.3  0.0   0:00.01 top                                                                                             
    1 root      20   0  190944   3740   2484 S   0.0  0.0   1:09.90 systemd                                                                                         
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kthreadd                                                                                        
    3 root      20   0       0      0      0 S   0.0  0.0   0:00.02 ksoftirqd/0                                                                                     
    5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H                                                                                    
    6 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kworker/u4:0                                                                                    
    7 root      rt   0       0      0      0 S   0.0  0.0   0:00.68 migration/0                                                                                     
    8 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcu_bh                                                                                          
    9 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/0                                                                                         
   10 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/1   

进程端口号

3.1查看进程

[root@JD ~]# ps -ef |grep ssh
root       732     1  0 Nov14 ?        00:00:08 /usr/sbin/sshd -D
root      7703   732  0 16:15 ?        00:00:00 sshd: root@pts/1
root      7729  7706  0 16:15 pts/1    00:00:00 grep --color=auto ssh
root     29339   732  0 14:35 ?        00:00:00 sshd: root@pts/0
[root@JD ~]# ps -ef |grep ssh | grep -v grep
root       732     1  0 Nov14 ?        00:00:08 /usr/sbin/sshd -D
root      7703   732  0 16:15 ?        00:00:00 sshd: root@pts/1
root     29339   732  0 14:35 ?        00:00:00 sshd: root@pts/0
进程用户 进程pid 父id                                     进程用户的内容(进程所属的目录 log -Xmx -Xms)
[root@JD ~]# 

3.2查看端口号
一个服务有可能没有端口号
最好根据进程号查询端口号,因为如果要使用服务名的话,有可能找不到

[root@JD ~]# netstat -nlp | grep 732 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      732/sshd            
tcp6       0      0 :::22                   :::*                    LISTEN      732/sshd            
[root@JD ~]# 

3.3安装http服务,打开web
service httpd start :centos6.x 7.x都可以使用该命令
systemctl start httpd:centos7.x使用该命令(建议使用该命令),因为该命令可以启动多个服务
http协议 80
https协议 443

[root@JD ~]# yum install httpd
启动http服务
[root@JD ~]# systemctl start httpd 
查看状态
[root@JD ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-11-19 16:42:54 CST; 14s ago
  。。。。。。。
 查看进程
[root@JD ~]# ps -ef |grep http
root     10597     1  0 16:42 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   10598 10597  0 16:42 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   10599 10597  0 16:42 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   10600 10597  0 16:42 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   10601 10597  0 16:42 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   10602 10597  0 16:42 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
root     11160  7706  0 16:47 pts/1    00:00:00 grep --color=auto http
根据进程号查看端口
[root@JD ~]# netstat -nlp |grep 10597
tcp6       0      0 :::80                   :::*                    LISTEN      10597/httpd    

3.4 场景
在centos部署大数据组件,发现一个错误 Connection refused,一般连接错误先使用ping跟telnet查看一下通不通,然后再看防火墙
ping ip
telnet ip port
3.4.1 不是telnet
windows部署:
在这里插入图片描述
linux部署

[root@JD ~]# yum install -y telnet #安装
[root@JD ~]# which telnet
/usr/bin/telnet
[root@JD ~]# telent 114.67.225.210 80
-bash: telent: command not found
[root@JD ~]# telnet 114.67.225.210 80  #能通
Trying 114.67.225.210...
Connected to 114.67.225.210.
Escape character is '^]'.	 		  

3.4.2面试题: 老板说去A服务器login,打开xxx软件的web界面?

	查看ip
	windows:ipconfig
	linux:ifconfig
	查看端口号
	ps -ef |grep xxx
	netstat -nlp |grep pid

3.4.3关于本地ip
配置前三种,自己跟其他服务器都可以用,后面的两种只能自己访问自己

0.0.0.0:22 当前的ip
:::22      当前的ip
192.168.0.3:22 当前的ip
----------------------------
127.0.0.1:22 本地自己访问自己  window和其他服务器无法进行访问
localhost:22

高危命令(kill rm -rf /)

rm -rf /命令要慎用,删除前可以先备份
kill -9 xxx:杀掉某一服务进程,慎用,要搞清楚该进程有没有用,再删除
ps 进程 xxx,top命令查询夯住的 / 删除xxx进程
kill -9 进程pid
kill -9 进程pid 进程pid 进程pid
kill -9 $(pgrep -f 匹配关键词)

[root@JD ~]# echo $(pgrep -f http)             
10597 10598 10599 10600 10601 10602 11876
批量删除进程
[root@JD ~]# kill -9  $(pgrep -f http)

安装yum软件

yum search xxx:查找yum命令安装的xxx软件
yum install -y xxx:下载并安装xxx
yum remove xxx:删除yum安装的软件

[root@JD ~]# rpm -qa | grep http
httpd-tools-2.4.6-90.el7.centos.x86_64
httpd-2.4.6-90.el7.centos.x86_6
删除rpm包失败,因为删除的rpm包有依赖,所以先删除依赖包
[root@JD ~]# rpm -e httpd-tools-2.4.6-90.el7.centos.x86_64
error: Failed dependencies:
httpd-tools = 2.4.6-90.el7.centos is needed by (installed) httpd-2.4.6-90.el7.centos.x86_64
加上--nodeps,就不会,直接删除
[root@JD ~]# rpm -e --nodeps httpd-tools-2.4.6-90.el7.centos.x86_64

wget下载安装包

wget xxx

压缩解压

7.1zip

压缩
zip -r xxx.zip ./*  将在文件夹里面的内容压缩,不包括文件夹
zip -r xxx.zip xxx/* 将文件夹包括里面的内容压缩,包括文件夹
解压缩
unzip xxx.zip

7.2tar
解压tar包

解压到当前目录
tar -zxvf xxx.tar.gz
解压到指定文件夹
tar -zxvf xxx.tar.ge xxx/*
压缩文件
将文件abcd打包为test.tar并gzip压缩
tar -zcvf test.tar.gz a b c d
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值