dalaolala / blog

用issue来写博客 和别人学的

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linux常用的命令

dalaolala opened this issue · comments

增加交换分区512M

dd if=/dev/zero of=/root/swap bs=1024 count=512000
mkswap /root/swap
swapon /root/swap
echo "/root/swap swap swap defaults 0 0">> /etc/fstab

挂在磁盘

查看需要挂在的磁盘,这里比如是/dev/vdb
fdesk -l

挂载
mkdir -p /storage
mkfs.ext4 /dev/vdb
mount /dev/vdb /storage

防火墙

systemctl status firewalld.service		查看firewalld状态
systemctl start firewalld.service		开启firewalld
systemctl stop firewalld.service		关闭firewalld
firewall-cmd --zone=public --add-port=80/tcp --permanent	永久添加指定端口
firewall-cmd --zone=public --remove-port=8080/tcp --permanent	永久移除指定端口
firewall-cmd --query-port=3306/tcp		查看端口是否被开放,返回yes/no
firewall-cmd --list-all		查看所有开放的端口
systemctl enable firewalld.service		开启自启
systemctl disable firewalld.service		禁止开机自启
systemctl is-enabled firewalld.service		查看是否开机自启
firewall-cmd --reload		更新防火墙规则(立即生效,永久添加时需要reload)

查看大文件命令

find . -type f -size +800M  -print0 | xargs -0 du -h | sort -nr

查看当前目录文件的大小

du -h --max-depth=1 *

查看日志内容

less catalina.out

#常用命令
j    下一行
k    上一行
f    向下滚动一屏幕
b    向上滚动一屏幕
g    定位到文档头部
G    定位到文档最尾部
q    退出less模式

/keyword  向下查找
n    向下匹配下一处匹配文本
N    向上匹配下一处匹配文本

?keyword  向上查找
n    向上匹配下一处匹配文本
N    向下匹配下一处匹配文本

修改主机名称

hostnamectl set-hostname centos7.com 

修改定时任务

vi /etc/crontab

查看具体占用的端口号信息

netstat -ntulp |grep 5998

结束所有node相关的进程

ps -ef | grep node | grep -v grep | awk '{print "kill -9 "$2}' | sh

在线配置yum源

参考 https://www.cnblogs.com/augustine0654/p/14131035.html

cd /etc/yum.repos.d/
# ls
# rm *
mv CentOS-Base.repo CentOS-Base.repo_bak

下载源文件

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo	# 下载源文件
yum clean all   # 清除缓存
yum makecache	# 生成缓存

修改系统时间为北京时间

删除本地时间并设置时区为上海

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

启动ntpd 服务

service ntpd restart

并使用hwclock -w命令从当前系统时间设置硬件时钟

hwclock -w

对准时间

yum install ntp
ntpdate time.nist.gov

修改NTP服务器方式同步时间

安装并且修改配置文件

yum install ntp
vi /etc/ntp.conf

找到下列内容注释掉

server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
server 3.centos.pool.ntp.org

然后修改为

server ntp.aliyun.com iburst

重启服务然后等时间同步即可

systemctl restart ntpd
systemctl status ntpd

查看时间服务器的同步状态

ntpq -p

时间总是不对的解决方案

查看时间更改日志

grep "date" /var/log/messages

把系统的RTC(硬件实时时钟 Real-Time Clock)设置为本地时间

timedatectl set-local-rtc 1

vmtools导致时间不对解决方案

systemctl stop vmtoolsd 

https://blog.51cto.com/devin223/2711722

查看某个端口TCP的链接数量

netstat -nat|grep -i "80"|wc -l

容量相关

查看当前挂载点容量的大小
df -h | head -n 2 | awk 'FNR == 2 {print $2;}'