记录一些平时遇到的 Linux 问题及解决方法!

# 骚操作 1:查杀僵尸进程

# 通过 top 命令发现了僵尸进程

发现僵尸进程

这里的 aragorn 和 prodigal 为僵尸进程。

# 寻找僵尸进程的父进程

ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]'

寻找父进程ppid

aragorn 和 prodigal 的父进程的 ppid 为 133619。

# 杀死父进程

kill -9 133619

僵尸进程已被杀死

之所以选择杀死父进程是因为僵尸进程本身很难被杀掉!

# 骚操作 2:使用 sudo 或 nohup 运行 bash 报错

# 错误

在终端里使用 sudo 或 nohup 运行 bash 的时候经常报错:-bash: syntax error near unexpected token 'do'。

# 解决方案

将要运行的命令加到如下语句中:

#用超级用户运行时
sudo bash -c 'your commands'
#服务器投后台运行
nohup bash -c 'your commands' &

# 骚操作 3:CentOS 升级 GCC

# 安装 SCL(第三方软件选集)

使用下面命令安装 SCL
SCL 可以在不覆盖原有软件包的情况下与其共存,缺点就是仅支持 64 位
SCL 仅支持安装 devtoolset-4(gcc 5.2)(不含)之后的 gcc 版本

yum install -y centos-release-scl

# 安装 gcc

使用以下命令安装 gcc,其中的 9 表示大版本号,默认安装大版本下的最新稳定版本

yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

# 将 gcc 加入环境变量

echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
source /etc/profile

# 骚操作 4:CentOS 7 防火墙

# 启动防火墙

启动: systemctl start firewalld

# 开启端口

firewall-cmd --zone=public --add-port=80/tcp --permanent 

# 重新载入

firewall-cmd --reload

# 查看防火墙状态

systemctl status firewalld.service
firewall-cmd --state

# 查看当前开了哪些端口

firewall-cmd --list-services

# 查看所有打开的端口

firewall-cmd --zone=public --list-ports

# 骚操作 5:Linux 基本指令丢失修复办法

如输入 ls、cd、cat 等基本指令提示找不到命令,可以通过以下命令修复:

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
Edited on Views times

Give me a cup of [coffee]~( ̄▽ ̄)~*

Hualin Liu WeChat Pay

WeChat Pay

Hualin Liu Alipay

Alipay