Linux基本命令(四)
Linux基本命令
1.vi 命令
1.1 vi 编辑命令过程图

[root@hadoop001 jepson]# vi hadoop.log002
[root@hadoop001 jepson]# cat hadoop.log002
www.baidu.com
[root@hadoop001 jepson]#
1.2 粘贴时必须进入插入模式(i)才能出现不丢失。
1.3 查找error
cat xxx.log | grep -C 10 ERROR > error.log
[root@hadoop001 jepson]# cat error.log | grep -C 10 error > error001.log
[root@hadoop001 jepson]# cat error001.log
11
12
13
14
15
16
17
18
19
20
error
1
2
3
4
5
6
7
8
9
10
[root@hadoop001 jepson]#
也可以通过cat、more和sz命令进行查找error。
进入尾行模式:/关键词 回车自动匹配 ,按N键找寻下一个。
1.4 设置行号
进入尾行模式:
set nu :设置行号
set nonu :取消行号
1.5 清空文件内容
cat /dev/null > xxx.log 最佳的清空方法
echo ‘’ > xxx.log 此方式会存在1个字节
命令行模式常见的快捷键:
dd 删除当前行
dG 删除光标当前及以下的所有行
ndd 删除光标当前及以下的n行
gg 跳转到第一行的第一个字母
G 跳转到最后一行的第一个字母
shift+$ 最后一行行尾
gg + dG 清空:先gg在dG全部清空
场景: 从另外一个文本拷贝内容去覆盖这个文件
大数据的组件都是xml文件
1.官方的默认的配置文件 xxxxxxx 30行
2.window记事本 editplus编辑好对应的参数 300
坑: cp备份(进入插入模式粘贴)
mysql的 my.cnf
2.系统命令
[root@hadoop001 ~]# df -h //查看系统磁盘
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 48G 1.8G 47G 4% / //生产中系统盘200G左右
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 12M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 146M 869M 15% /boot
/dev/mapper/centos-home 24G 716M 23G 3% /home
tmpfs 781M 0 781M 0% /run/user/0
[root@hadoop001 ~]# free -m
total used free shared buff/cache available
Mem: 7802 180 7422 11 200 7361
Swap: 8063 0 8063
[root@hadoop001 ~]# top //查看系统负载
top - 18:06:44 up 1:03, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 106 total, 1 running, 105 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 7990252 total, 7598804 free, 185260 used, 206188 buff/cache
KiB Swap: 8257532 total, 8257532 free, 0 used. 7537052 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12130 root 20 0 0 0 0 S 0.3 0.0 0:01.06 kworker/0:3
13185 root 20 0 161880 2196 1556 R 0.3 0.0 0:00.16 top
1 root 20 0 127960 6536 4136 S 0.0 0.1 0:01.82 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.11 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.13 kworker/u256:0
7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 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.54 rcu_sched
10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain
11 root rt 0 0 0 0 S 0.0 0.0 0:00.02 watchdog/0
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
14 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khungtaskd
16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback
17 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd
18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
//经验值 不要超过10 否则认为此物理服务器 IDC机房
//cpu、men 超过100% 有问题 代码级别 硬件级别(内存条坏了)
3.查看进程 查看端口号
3.1 ps -ef 查看当前进程
[root@hadoop001 ~]# ps -ef|grep ssh
root 9750 1 0 13:19 ? 00:00:00 /usr/sbin/sshd -D
root 10264 9750 0 13:23 ? 00:00:00 sshd: root@pts/0
root 10337 10268 0 14:34 pts/0 00:00:00 grep --color=auto ssh
[root@hadoop001 ~]# ps -ef|grep ssh | grep -v grep // -v 过滤grep
root 9750 1 0 13:19 ? 00:00:00 /usr/sbin/sshd -D
root 10264 9750 0 13:23 ? 00:00:00 sshd: root@pts/0
//进程用户 进程的pid 父id 进程用户的内容(进程所属的目录 log -Xmx -Xms)
[root@hadoop001 ~]#
3.2 查看进程端口号
[root@hadoop001 ~]# netstat -nlp | grep 9750
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 9750/sshd
tcp6 0 0 :::22 :::* LISTEN 9750/sshd
[root@hadoop001 ~]# netstat -nlp | grep ssh
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 9750/sshd
tcp6 0 0 :::22 :::* LISTEN 9750/sshd
[root@hadoop001 ~]#
//通过pid找prot
//1、启动一个进程 ps 必须
//2:、可能启动一个port netstat 不是必须
3.3 安装服务,打开web
[root@hadoop001 ~]# service httpd start
Redirecting to /bin/systemctl start httpd.service
[root@hadoop001 ~]# systemctl start httpd
[root@hadoop001 ~]# 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 2017-11-26 15:04:43 CST; 54s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 10438 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─10438 /usr/sbin/httpd -DFOREGROUND
├─10439 /usr/sbin/httpd -DFOREGROUND
├─10440 /usr/sbin/httpd -DFOREGROUND
├─10441 /usr/sbin/httpd -DFOREGROUND
├─10442 /usr/sbin/httpd -DFOREGROUND
└─10443 /usr/sbin/httpd -DFOREGROUND
Nov 26 15:04:43 hadoop001 systemd[1]: Starting The Apache HTTP Server...
Nov 26 15:04:43 hadoop001 httpd[10438]: AH00558: httpd: Could not reliably determine the server's full...sage
Nov 26 15:04:43 hadoop001 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@hadoop001 ~]# ps -ef|grep http
root 10438 1 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 10439 10438 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 10440 10438 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 10441 10438 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 10442 10438 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 10443 10438 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 10453 10268 0 15:08 pts/0 00:00:00 grep --color=auto http
[root@hadoop001 ~]# netstat -nlp | grep 10438
tcp6 0 0 :::80 :::* LISTEN 10438/httpd
3.4 场景: 在centos部署大数据组件,发现一个错误 Connection refused ,防火墙 web iptables
ping ip 测试ip
telnet ip port 测试ip和端口号
部署telnet命令
window系统 cmd黑窗口 不带 telnet命令 ,需要去安装一下 重启电脑
Linux 系统
[root@hadoop001 ~]# yum install -y telnet
[root@hadoop001 ~]# telnet 192.168.110.141 80
Trying 192.168.110.141...
Connected to 192.168.110.141.
Escape character is '^]'.
4.高危命令
rm -rf / 删除根目录
vi 生产配置文件时,先进行复制一份
ps进程xxx,
kill -9 进程pid
kill -9 进程pid 进程pid 进程pid
kill -9 $(pgrep -f 匹配关键词)
杀进程之前,先ps 找到相关的进程,搞清楚,哪些是你要杀的,不然造成生产事故
[root@hadoop001 ~]# ps -ef |grep http
root 10438 1 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 10439 10438 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 10440 10438 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 10441 10438 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 10442 10438 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 10443 10438 0 15:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 10466 10438 0 15:23 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 10473 10268 0 15:49 pts/0 00:00:00 grep --color=auto http
[root@hadoop001 ~]# kill -9 $(pgrep -f http)
[root@hadoop001 ~]# ps -ef |grep http
root 10480 10268 0 15:50 pts/0 00:00:00 grep --color=auto http
[root@hadoop001 ~]#
5.安装yum软件
yum search xxx 查找
yum install -y xxx-yyy 安装
yum remove xxx-yyy 移除
[root@hadoop001 ~]# 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
[root@hadoop001 ~]# rpm -e httpd-2.4.6-90.el7.centos.x86_64
[root@hadoop001 ~]# rpm -e httpd-tools-2.4.6-90.el7.centos.x86_64
[root@hadoop001 ~]# rpm -qa | grep http
[root@hadoop001 ~]# rpm -e --nodeps httpd-tools-2.4.6-90.el7.centos.x86_64 //不效验删除
[root@hadoop001 ~]#
6.wget下载安装包
[root@hadoop001~]# wget http://archive.cloudera.com/cdh5/
7.压缩与解压
zip压缩与解压
zip -r xxx.zip ./* 在文件夹里面
zip -r ruozedata.zip ruozedata/* 在外面
[root@hadoop001 jepson]# zip -r 100.zip ./error001.log hadoop.log002
adding: error001.log (deflated 32%)
adding: hadoop.log002 (stored 0%)
[root@hadoop001 jepson]# ll
total 16
-rw-r--r--. 1 root root 395 Nov 26 16:19 100.zip
drwxrwxrwx. 2 root root 6 Nov 18 13:06 3
drwxr-xr-x. 2 root root 27 Nov 18 13:24 a
drwxr-xr-x. 3 root root 15 Nov 18 13:01 b
-rw-r--r--. 1 root root 78 Nov 24 17:36 error001.log
-rw-r--r--. 1 root root 147 Nov 18 14:06 error.log
-rw-r--r--. 1 root root 14 Nov 24 17:25 hadoop.log002
[root@hadoop001 jepson]# rm -f error001.log hadoop.log002
[root@hadoop001 jepson]# unzip 100.zip
Archive: 100.zip
inflating: error001.log
extracting: hadoop.log002
[root@hadoop001 jepson]# ll
total 16
-rw-r--r--. 1 root root 395 Nov 26 16:19 100.zip
drwxrwxrwx. 2 root root 6 Nov 18 13:06 3
drwxr-xr-x. 2 root root 27 Nov 18 13:24 a
drwxr-xr-x. 3 root root 15 Nov 18 13:01 b
-rw-r--r--. 1 root root 78 Nov 24 17:36 error001.log
-rw-r--r--. 1 root root 147 Nov 18 14:06 error.log
-rw-r--r--. 1 root root 14 Nov 24 17:25 hadoop.log002
[root@hadoop001 jepson]#
tar的解压与压缩
大数据组件的压缩包几乎都是后缀 tar.gz
tar -xzvf hadoop-2.6.0-cdh5.16.2.tar.gz
tar -czvf hadoop-2.6.0-cdh5.16.2.tar.gz hadoop-2.6.0-cdh5.16.2/*
Examples:
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.
tar -tvf archive.tar # List all files in archive.tar verbosely.
tar -xf archive.tar # Extract all files from archive.tar.
113万+





