一、Linux常用命令
1、查看日志
滚动查看日志
tail -f systemLog.log
查看日志 关键词 后10行
cat -n mobile-api_2021-09-30.log |grep "每次重启" -A 10
vim编辑器打开日志文件
/xx 输入关键字就会查询语法高亮
n 下一个
:set nu 显示行号
1、shift+G 到达最后一行
2、gg 到达第一行
3、ctrl+b 向下
4、ctrl+f 向上
2、history
查看命令历史
history 20
!+历史记录id 即可直接执行 这条命令
!3000
3、查询文件夹及其下面所占空间
du -sh /app/
4、压缩
tar -czvf beifen nginx/
5、解压
tar -xzvf beifen
tar文件 需要用tar xf mysql.tar 解压出gz
tar 命令 tar xzvf mysql.gz
6、删除文件夹及其下所有文件
rm -rf nginx
7、复制文件夹及其下文件
cp -r dist dist2
复制文件
cp beifen.txt 1.txt
8、查看服务器基本信息
uname -a
Linux panda02 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
9、查看服务器操作系统
cat /etc/redhat-release
10、查看服务器运行内存大小的命令
cat /proc/meminfo | grep MemTotal
11、top命令
当前时间 up 开机时间 1个用户 load average 判断负载 指数不能多于cup个数 否则需要考虑服务器性能
蓝色代表文件夹 白色代表文件
14、创建文件夹
mkdir
递归创建文件夹
mkdir -p huang/games/lol
16、查看linux运行内存和磁盘空间
查看内存
free -h
查看磁盘空间
df -h
17、查看linux指定端口号330
netstat -lnp|grep 330
18、强制中断文件有临时文件
删掉
19、判断端口号通不通
Linux测试ip
ping 106.54.220.184
Mac测试ip
ping 106.54.220.184
Linux和Mac测试 ip+端口
sudo yum install nc -y (如果没有nc命令使用yum安装)
nc -zv 106.54.220.184 3306
win
telnet 192.168.1.245 3306
wget 139.196.205.30:6379
测试nacos
curl http://192.168.31.92:8848/nacos/
测试mysql
curl http://localhost:3306
5.7.36-log|#.8< ÿÿ-ÿᅰm@j5,*'='mysql_native_password!ÿ#08S01Got packets out of order
测试redis
curl http://localhost:6379
20、部署Java应用
ps -ef|grep java
kill -9 31395
nohup java -jar admin.jar &
21、服务器重启
shutdown -r now
22、赋予读写权限
给文件夹下所有文件 可读可写 最高权限
chmod -R 777 jenkins/
23、换源
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
yum repolist
24、查看cpu
cpu 个数 4
grep 'physical id' /proc/cpuinfo
核心数
grep 'core id' /proc/cpuinfo |wc -l
二、firewall防火墙关闭
开启防火墙
firewall-cmd --state
查看防火墙状态
firewall-cmd --state
查看防火墙端口是否放行
firewall-cmd --query-port=3306/tcp
设置端口放行
firewall-cmd --permanent --add-port=3306/tcp
重启防火墙(修改配置文件、需要重启)
firewall-cmd --reload
设置端口拦击不放行
firewall-cmd --permanent --remove-port=3306/tcp
参考
二、firewall防火墙
1、查看firewall服务状态
systemctl status firewalld
出现Active: active (running)切高亮显示则表示是启动状态。
出现 Active: inactive (dead)灰色表示停止,看单词也行。
2、查看firewall的状态
firewall-cmd --state
3、开启、重启、关闭、firewalld.service服务
# 开启
service firewalld start
# 重启
service firewalld restart
# 关闭
service firewalld stop
4、查看防火墙规则
firewall-cmd --list-all
5、查询、开放、关闭端口
# 查询端口是否开放
firewall-cmd --query-port=8080/tcp
# 开放80端口
firewall-cmd --permanent --add-port=80/tcp
# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload
# 参数解释
1、firwall-cmd:是Linux提供的操作firewall的一个工具;
2、--permanent:表示设置为持久;
3、--add-port:标识添加的端口