vim/vi命令
1.1三种模式
vi三种模式
常用
wq:保存退出
!wq:强制保存退出
!q:强制退出
1.2粘贴的坑
粘贴一定在编辑模式下进行,否则会丢失某些内容
eg:
123
11
115
119
abc
在命令模式下粘贴结果(丢失内容)
[root@pxj31 tmp]# cat test.log
bc
1.3找error信息
[root@pxj31 tmp]# cat hbase-pxj-hadoop53.log |grep -C 10 ERROR >error.log
[root@pxj31 tmp]# more error.log
SZ实现上下翻动内容
搜索
[root@pxj31 tmp]# vi error.log
:/关键词 回车匹配
进入尾行模式:/关键词 回车自动匹配 按N键找寻下一个
1.4 设置行号
进入尾行模式:
set nu
set nonu
[root@pxj31 tmp]# vi error.log
: set nu
1.5 清空内容
cat /dev/null > xxx.log 完美
echo '' > xxx.log 存在1个字节
在不需要再在文件写入内容可以使用cat /dev/null > xxx.log
在需要清空内容在写入内容时:
命令行模式常见的快捷键:
dd 删除当前行
dG 删除光标当前及以下的所有行
ndd 删除光标当前及以下的n行
gg 跳转到第一行的第一个字母
G 跳转到最后一行的第一个字母
shift+$ 行尾
gg+dG
在大数据的应用
场景: 从另外一个文本拷贝内容去覆盖这个文件
大数据的组件都是xml文件
1.官方的默认的配置文件 xxxxxxx 30行
2.window记事本 editplus 编辑好对应的参数 300
坑: cp备份
mysql的 my.cnf
原则上先备份,再覆盖
2.系统命令
2.1磁盘
[root@pxj31 tmp]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 47G 6.0G 41G 13% /
devtmpfs 1.3G 0 1.3G 0% /dev
tmpfs 1.3G 0 1.3G 0% /dev/shm
tmpfs 1.3G 9.0M 1.3G 1% /run
tmpfs 1.3G 0 1.3G 0% /sys/fs/cgroup
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 266M 12K 266M 1% /run/user/42
tmpfs 266M 0 266M 0% /run/user/0
2.2查看内存
[root@pxj31 tmp]# free -m (内存显示的单位是MB)
total used free shared buff/cache available
Mem: 2657 1019 334 9 1303 1433
Swap: 2047 0 2047
[root@pxj31 tmp]# free -g (内存显示的单位是MB)
total used free shared buff/cache available
Mem: 2 0 0 0 1 1
Swap: 1 0 1
2.3负载
[root@pxj31 tmp]# top
top - 00:42:50 up 59 min, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 149 total, 1 running, 148 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.2 si, 0.0 st
KiB Mem : 2721064 total, 340636 free, 1045804 used, 1334624 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 1466900 avail Mem
解释:load average: 0.00, 0.01, 0.05
1min 5min 15min
经验之谈:
经验值 不要超过10 否则认为此物理服务器 IDC机房
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1483 mssql 20 0 3369652 759248 9452 S 0.7 27.9 0:51.26 sqlservr
1 root 20 0 128164 6816 4048 S 0.0 0.3 0:01.57 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
3.查看进程 查看端口号
3.1进程
[root@pxj31 ~]# ps -ef|grep ssh
root 1017 1 0 11月17 ? 00:00:00 /usr/sbin/sshd -D
root 3138 1017 0 00:47 ? 00:00:00 sshd: root@pts/1
root 3192 3146 0 00:47 pts/1 00:00:00 grep --color=auto ssh
[root@pxj31 ~]# ps -ef|grep ssh |grep -v grep
root 1017 1 0 11月17 ? 00:00:00 /usr/sbin/sshd -D
root 3138 1017 0 00:47 ? 00:00:00 sshd: root@pts/1
进程用户 进程的pid 父id 进程用户的内容(进程所属的目录 log -Xmx -Xms)
3.2端口号
[root@pxj31 ~]# netstat -nlp | grep 1017
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1017/sshd
tcp6 0 0 :::22 :::* LISTEN 1017/sshd
[root@pxj31 ~]# netstat -nlp | grep ssh
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1017/sshd
tcp6 0 0 :::22 :::* LISTEN 1017/sshd
通过pid找port
1: 启动一个进程 ps 必须
2: 可能启动一个port netstat 不是必须
3.3安装服务,打开web
[root@pxj31 ~]# yum -y install httpd
启动服务6与7的区别
[root@pxj31 ~]# service httpd start
Redirecting to /bin/systemctl start httpd.service
[root@pxj31 ~]# systemctl start httpd.service
改进后的好处是 systemctl start|restart|stop| httpd.service 可接多个服务
[root@pxj31 ~]# systemctl start httpd.service
[root@pxj31 ~]# ps -ef|grep httpd
root 3403 1 0 00:55 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 3405 3403 0 00:55 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 3406 3403 0 00:55 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 3407 3403 0 00:55 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 3408 3403 0 00:55 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 3409 3403 0 00:55 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 3452 3146 0 00:57 pts/1 00:00:00 grep --color=auto httpd
[root@pxj31 ~]# netstat -lnp |grep 3403
tcp6 0 0 :::80 :::* LISTEN 3403/httpd
[root@pxj31 ~]# curl 192.168.25.31:80
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Apache HTTP Server Test Page powered by CentOS</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
......省略内容
常见的端口
http协议 80
https协议 443
大数据应用场景
场景: 在centos部署大数据组件,发现一个错误 Connection refused 防火墙 web iptables
ping ip 测试ip
telnet ip port 测试ip和端口号
部署telnet命令
window cmd黑窗口 不带 telnet命令 ,需要去安装一下 重启电脑
Linux
[root@pxj31 ~]# yum -y install telnet
[root@pxj31 ~]# which telnet
/usr/bin/telnet
telent具体应用
[root@pxj31 ~]# telnet 192.168.25.31 80
Trying 192.168.25.31...
Connected to 192.168.25.31.
Escape character is '^]'.
Connection closed by foreign host.
面试题:老板说去A服务器login,打开xxx软件的web界面?
解决思路:
ip: window : ipconfig
linux: ifconfig
ps -ef|grep xxx eg:ps -ef|grep ssh
netstat -nlp |grep pid ==》port
引发思考的问题及解决:
eg:
[root@pxj31 ~]# ps -ef |grep ssh
root 1019 1 0 08:24 ? 00:00:00 /usr/sbin/sshd -D
root 1911 1019 0 08:25 ? 00:00:00 sshd: root@pts/0
root 2151 1019 0 08:36 ? 00:00:00 sshd: root@pts/1
root 2464 1920 0 08:50 pts/0 00:00:00 grep --color=auto ssh
0.0.0.0:22 当前的ip
:::22 当前的ip
192.168.25.31:22 当前的ip
注意:
127.0.0.1:22 本地自己访问自己 window和其他服务器无法进行访问
localhost:22
修改
[root@pxj31 conf]# vim /etc/httpd/conf/httpd.conf
Listen 127.0.0.1:80
[root@pxj31 conf]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service
[root@pxj31 conf]# ps -aux|grep httpd
root 13665 0.1 0.1 226220 5148 ? Ss 23:18 0:00 /usr/sbin/httpd -DFOREGROUND
apache 13666 0.0 0.1 228304 3152 ? S 23:18 0:00 /usr/sbin/httpd -DFOREGROUND
apache 13667 0.0 0.1 228304 3152 ? S 23:18 0:00 /usr/sbin/httpd -DFOREGROUND
apache 13668 0.0 0.1 228304 3152 ? S 23:18 0:00 /usr/sbin/httpd -DFOREGROUND
apache 13669 0.0 0.1 228304 3152 ? S 23:18 0:00 /usr/sbin/httpd -DFOREGROUND
apache 13670 0.0 0.1 228304 3152 ? S 23:18 0:00 /usr/sbin/httpd -DFOREGROUND
root 13726 0.0 0.0 112676 984 pts/0 S+ 23:19 0:00 grep --color=auto httpd
[root@pxj31 conf]# netstat -lnp |grep 13665
tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 13665/httpd
[root@pxj31 conf]# telnet 192.168.25.31 80
Trying 192.168.25.31...
telnet: connect to address 192.168.25.31: Connection refused
说明:实验结果是拒绝连接
1.以后遇到此类问题,先ps -ef 再netstat -lnp查看如果遇到127.0.0.1或localhost时说明仅仅是允许自己访问,不允许外部访问
高危命令总结
rm -fr
rm -fr /
高危命令,可能导致系统损坏无法修复
修改生产文件时
首先要复制一份,作为备份
vi 生产配置文件 100行 保存==》 cp xxx.xml xxx.xml20191117
ps 进程 xxx,top命令查询夯住的 / 删除xxx进程
kill -9 进程pid
kill -9 进程pid 进程pid 进程pid
kill -9 $(pgrep -f 匹配关键词)
杀进程之前,先ps 找到相关的进程,搞清楚,哪些是你要杀的,不然造成生产事故
eg:
[root@pxj31 conf]# ps -ef|grep httpd
root 15407 1 0 23:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 15408 15407 0 23:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 15409 15407 0 23:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 15410 15407 0 23:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 15411 15407 0 23:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 15412 15407 0 23:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 15479 13227 0 23:45 pts/0 00:00:00 grep --color=auto httpd
[root@pxj31 conf]# echo $(pgrep httpd)
15407 15408 15409 15410 15411 15412
[root@pxj31 conf]# echo $(pgrep -f httpd)
15407 15408 15409 15410 15411 15412
[root@pxj31 conf]# kill -9 $(pgrep -f httpd)
[root@pxj31 conf]# pgrep -f httpd
5.安装yum软件
yum search xxx
yum install -y xxx-yyy
yum remove xxx-yyy
查看是否安装
[root@pxj31 conf]# rpm -qa|grep httpd
httpd-2.4.6-90.el7.centos.x86_64
httpd-tools-2.4.6-90.el7.centos.x86_64
[root@pxj31 conf]# rpm -qa|grep -i httpd
httpd-2.4.6-90.el7.centos.x86_64
httpd-tools-2.4.6-90.el7.centos.x86_64
说明 -i不区分大小写
[root@pxj31 conf]# rpm -e httpd-tools-2.4.6-90.el7.centos.x86_64
错误:依赖检测失败:
httpd-tools = 2.4.6-90.el7.centos 被 (已安裝) httpd-2.4.6-90.el7.centos.x86_64 需要
说明:需要先卸载依赖
先删除httpd-2.4.6-90.el7.centos.x86_64
httpd-tools-2.4.6-90.el7.centos.x86_64
--nodeps 不校验,直接删除
[root@pxj31 conf]# rpm -e --nodeps httpd-tools-2.4.6-90.el7.centos.x86_64
6.wget下载安装包
wget http://archive.cloudera.com/cdh5/cdh/5/hadoop-2.6.0-cdh5.16.2.tar.gz
wget http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
7.压缩
zip
[root@pxj31 tmp]# zip -r tmp.zip ./* 在文件里
adding: a.log (stored 0%)
adding: error_1.log (deflated 95%)
adding: error.log (deflated 95%)
adding: firefox_root/ (stored 0%)
adding: firefox_root/.parentlock (stored 0%)
adding: hbase-pxj-hadoop53.log (deflated 95%)
adding: hsperfdata_root/ (stored 0%)
adding: messages (deflated 85%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-chronyd.service-a78miS/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-chronyd.service-a78miS/tmp/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-colord.service-25SVw7/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-colord.service-25SVw7/tmp/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-cups.service-Hr2ZZt/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-cups.service-Hr2ZZt/tmp/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-rtkit-daemon.service-TFVNLS/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-rtkit-daemon.service-TFVNLS/tmp/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-vgauthd.service-Q2Boun/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-vgauthd.service-Q2Boun/tmp/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-vmtoolsd.service-yWYxY6/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-vmtoolsd.service-yWYxY6/tmp/ (stored 0%)
adding: systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-vmtoolsd.service-yWYxY6/tmp/vmware-root/ (stored 0%)
adding: test.log (stored 0%)
adding: tracker-extract-files.0/ (stored 0%)
adding: yum_save_tx.2019-11-10.23-38.itmg0I.yumtx (deflated 91%)
在文件夹外
[root@pxj31 /]# zip -r tmp.zip tmp/*
adding: tmp/a.log (stored 0%)
adding: tmp/error_1.log (deflated 95%)
adding: tmp/error.log (deflated 95%)
adding: tmp/firefox_root/ (stored 0%)
adding: tmp/firefox_root/.parentlock (stored 0%)
adding: tmp/hbase-pxj-hadoop53.log (deflated 95%)
adding: tmp/hsperfdata_root/ (stored 0%)
adding: tmp/messages (deflated 85%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-chronyd.service-a78miS/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-chronyd.service-a78miS/tmp/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-colord.service-25SVw7/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-colord.service-25SVw7/tmp/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-cups.service-Hr2ZZt/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-cups.service-Hr2ZZt/tmp/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-rtkit-daemon.service-TFVNLS/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-rtkit-daemon.service-TFVNLS/tmp/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-vgauthd.service-Q2Boun/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-vgauthd.service-Q2Boun/tmp/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-vmtoolsd.service-yWYxY6/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-vmtoolsd.service-yWYxY6/tmp/ (stored 0%)
adding: tmp/systemd-private-8d8a03201f2e4dbc99dbb7f2e0d6d29c-vmtoolsd.service-yWYxY6/tmp/vmware-root/ (stored 0%)
adding: tmp/test.log (stored 0%)
adding: tmp/tmp.zip (stored 0%)
adding: tmp/tracker-extract-files.0/ (stored 0%)
adding: tmp/yum_save_tx.2019-11-10.23-38.itmg0I.yumtx (deflated 91%)
[root@pxj31 /]#unzip tmp.zip
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.
[root@pxj31 opt]# tar -zxvf maxwell-1.23.2.tar.gz