linux常用和错误集

SSH工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# FinalShell 
# FinalShell是一体化的的服务器,网络管理软件,不仅是ssh客户端,
# 还是功能强大的开发,运维工具,充分满足开发,运维需求.
#
# 特色功能:
# 免费海外服务器远程桌面加速,ssh加速,本地化命令输入框,支持自动补全,命令历史,自定义命令参数
#
# Windows版下载地址:
# http://www.hostbuf.com/downloads/finalshell_install.exe
#
# macOS版下载地址:
# http://www.hostbuf.com/downloads/finalshell_install.pkg
#
# mac版安装路径
# /Applications/FinalShell.app/Contents/Java/
# 配置文件路径
# /Users/$USER/Library/FinalShell/

# xshell5
# https://f.tiiao.cn/soft/exe/xshell/

Aria2

1
wget https://raw.githubusercontent.com/P3TERX/aria2.sh/master/aria2.sh && bash aria2.sh

lnmp一键安装包

1
2
3
4
wget http://soft.vpser.net/lnmp/lnmp1.7beta.tar.gz -cO lnmp1.7beta.tar.gz && tar zxf lnmp1.7beta.tar.gz && cd lnmp1.7

# 无人值守参数生成 https://lnmp.org/auto.html
wget http://soft.vpser.net/lnmp/lnmp1.6.tar.gz -cO lnmp1.6.tar.gz && tar zxf lnmp1.6.tar.gz && cd lnmp1.6 && LNMP_Auto="y" DBSelect="2" DB_Root_Password="lnmp.org" InstallInnodb="y" PHPSelect="5" SelectMalloc="1" ./install.sh lnmp

Screen

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#https://www.runoob.com/linux/linux-comm-screen.html
#Linux screen命令用于多重视窗管理程序。
#screen为多重视窗管理程序。此处所谓的视窗,是指一个全屏幕的文字模式画面。
#通常只有在使用telnet登入主机或是使用老式的终端机时,才有可能用到screen程序。
#语法
#screen [-AmRvx -ls -wipe][-d <作业名称>][-h <行数>]
#[-r <作业名称>][-s <shell>][-S <作业名称>]
#参数说明:
#
#-A  将所有的视窗都调整为目前终端机的大小。
#-d<作业名称>  将指定的screen作业离线。
#-h<行数>  指定视窗的缓冲区行数。
#-m  即使目前已在作业中的screen作业,仍强制建立新的screen作业。
#-r<作业名称>  恢复离线的screen作业。
#-R  先试图恢复离线的作业。若找不到离线的作业,即建立新的screen作业。
#-s<shell>  指定建立新视窗时,所要执行的shell。
#-S<作业名称>  指定screen作业的名称。
#-v  显示版本信息。
#-x  恢复之前离线的screen作业。
#-ls或--list  显示目前所有的screen作业。
#-wipe  检查目前所有的screen作业,并删除已经无法使用的screen作业。
#
# 如果提示screen: command not found 命令不存在可以执行:
yum install screen
#或 apt-get install
# 创建
screen -S t1
# 挂起,后台运行
ctrl+a d
# 恢复指定窗口,后台到前台
screen -r t1

Rclone

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
yum -y update
# 安装依赖
yum install fuse fuse-devel -y
curl https://rclone.org/install.sh | sudo bash
# 创建配置文件
rclone config
# 查看配置文件路径
rclone config file
# 更多操作或帮助 https://rclone.org/docs/
# 设置开机自启:
systemctl enable rclone
# 重启:
systemctl restart rclone
# 停止:
systemctl stop rclone
# 状态:
systemctl status rclone
# 查看挂载
df -h
# 卸载磁盘
fusermount -qzu LocalFolder
# 挂载网盘,googleDrive 为你配置文件取的名称,/test为要挂载目录,可以整个网盘/
#, /home/00 为本地挂载路径
/usr/bin/rclone mount googleDrive:/test /home/00 \
--umask 0000 \
--default-permissions \
--allow-non-empty \
--allow-other \
--buffer-size 32M \
--dir-cache-time 12h \
--vfs-read-chunk-size 64M \
--vfs-read-chunk-size-limit 1G

# 注意挂载的路径,如/root/test 则某些软件可能无法正确的读取!
# 如果出现挂载后崩溃或是软件退出,可以尝试增加虚拟内存

虚拟内存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# https://www.moerats.com/archives/722/
#Linux VPS一键添加/删除Swap虚拟内存
#脚本不支持OpenVZ架构,安装会自动退出。
#然后根据选项进行操作,记得添加swap的时候填写纯数字,默认单位为M。
wget https://www.moerats.com/usr/shell/swap.sh && bash swap.sh

#———————————————————————————————————————
#Linux VPS一键添加/删除swap脚本
#1、添加swap
#2、删除swap
#———————————————————————————————————————
#请输入数字 [1-2]:1
#请输入需要添加的swap,建议为内存的2倍!
#请输入swap数值:2048
#swapfile未发现,正在为其创建swapfile
#Setting up swapspace version 1, size = 2097148 KiB
#no label, UUID=e556830d-aa98-41cf-b8a5-14dad33a144d
#swap创建成功,并查看信息:
#Filename Type Size Used Priority
#/swapfile file 2097148 0 -1
#SwapCached: 0 kB
#SwapTotal: 2097148 kB
#SwapFree: 2097148 kB

多媒体

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# emby
# https://emby.media/linux-server.html
yum install https://github.com/MediaBrowser/Emby.Releases/releases/download/4.4.0.40/emby-server-rpm_4.4.0.40_x86_64.rpm
# 安装完后打开 http://localhost:8096

# 重启、开启、状态、停止命令
/usr/sbin/service emby-server restart
/usr/sbin/service emby-server start
/usr/sbin/service emby-server status
/usr/sbin/service emby-server stop

# plex
# https://www.plex.tv/zh/media-server-downloads/#plex-media-server
yum install https://downloads.plex.tv/plex-media-server-new/1.18.9.2578-513b381af/redhat/plexmediaserver-1.18.9.2578-513b381af.x86_64.rpm
#设置Plex开机启动
systemctl enable plexmediaserver.service
systemctl start plexmediaserver.service
#检查运行状态。
systemctl status plexmediaserver
# 需要开放的端口
# TCP:32400
# TCP:3005
# TCP:8324
# TCP:32469
# UDP:1900
# UDP:32410
# UDP:32412
# UDP:32413
# UDP:32414
# UDP:5353

# 启动、停止、重启命令
service plexmediaserver start
service plexmediaserver stop
service plexmediaserver restart
# 第一次访问需要内网打开 localhost:32400/web 完成安装的操作
# 可以通过Xshell或putty进行端口映射完成

Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 安装 EPEL
yum install epel-release
# 安装
yum install nginx
# 卸载
yum remove nginx
# 启动服务
sudo systemctl start nginx

# 检查 Nginx 的运行状态:
sudo systemctl status nginx

# 检查 Nginx 配置
nginx -t

# 设置开机启动
sudo systemctl enable nginx
# 关闭开机启动 Nginx
sudo systemctl disable nginx

# 停止服务
sudo systemctl stop nginx
# 重启服务
sudo systemctl restart nginx
# 重新加载
sudo systemctl reload nginx

# 开启目录浏览
autoindex on;
# 默认为on,显示出文件的确切大小,单位是bytes
# 显示出文件的大概大小,单位是kB或者MB或者GB
autoindex_exact_size off;
# 默认为off,显示的文件时间为GMT时间。
# 改为on后,显示的文件时间为文件的服务器时间
autoindex_localtime on;
# 让浏览器不保存临时文件
add_header Cache-Control no-store;
# 避免中文乱码
charset utf-8,gbk;
# 希望请求文件是下载而不是显示内容
add_header Content-Disposition attachment;

# 查看 nginx 服务进程
ps -ef | grep nginx
# 重新加载,因为一般重新配置之后,不希望重启服务,这时可以使用重新加载。
sudo systemctl reload nginx

#Nginx 的配置文件和最佳实践
#所有相关的配置文件都在 /etc/nginx/ 目录中。
#Nginx 的主配置文件是 /etc/nginx/nginx.conf。
#为了使 Nginx 配置更易于维护,建议为每个服务(域名)创建一个单独的配置文件。
#每一个独立的 Nginx 服务配置文件都必须以 .conf 结尾,并存储在 /etc/nginx/conf.d 目录中。
#您可以根据需求,创建任意多个独立的配置文件。
#
#独立的配置文件,建议遵循以下命名约定,比如你的域名是 domain.com,那么你的配置文件的应该是这样的
#/etc/nginx/conf.d/domain.com.conf,如果你在一个服务器中部署多个服务,
#当然你也可以在文件名中加上 Nginx 转发的端口号,比如 domain.com.3000.conf,这样做看起来会更加友好。
#
#如果你的配置中有很多重复的代码,那么建议你创建一个 /etc/nginx/snippets 文件夹,
#在这里面存放所有会被复用的代码块,然后在各个需要用到的 Nginx 的配置文件中引用进去,
#这样可以更方便管理和修改。
#
#Nginx 日志文件(access.log 和 error.log )位于 /var/log/nginx/ 目录中。
#建议为每个独立的服务配置不同的访问权限和错误日志文件,这样查找错误时,会更加方便快捷。
#你可以将要部署的代码文件,存储在任何你想的位置,但是一般推荐存放在下列位置中的其中一个:
#
#/home/<user_name>/<site_name>
#/var/www/<site_name>
#/var/www/html/<site_name>
#/opt/<site_name>
#/usr/share/nginx/html

Nginx配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
server {
listen 10808;
server_name us-nat.tiiao.cn us-nat.tiiao.cn;
location / {
root /var/www/main;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
charset utf-8,gbk;
}
location /d {
root /usr/share/nginx/html/d;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
charset utf-8,gbk;
}

}

Caddy

1
2
3
4
5
6
7
8
9
10
11
12
13
# Caddy 配置文件路径:/etc/caddy/Caddyfile
# 启动
sudo systemctl start caddy.service
# 重启
sudo systemctl restart caddy.service
# 重启
sudo systemctl stop caddy.service
# 查看
sudo systemctl status caddy.service
# 开机启动
sudo systemctl enable caddy.service


Caddy配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# https://caddyserver.com/docs/
# 配置文件路径 /etc/caddy/Caddyfile
# 开启目录浏览,gzip
down.nobige.cn{
root /var/www/main
gzip
browse
}

railgun.moe {
gzip
log /var/log/caddy/railgun_moe.log
tls lengz@lengzzz.com
root /var/www/
header /api {
Access-Control-Allow-Origin *
Access-Control-Allow-Methods "GET, POST, OPTIONS"
-Server
}
fastcgi / 127.0.0.1:9000 php {
index index.php
}
rewrite {
to {path} {path}/ /index.php?{query}
}
}
lengzzz.com {
tls lengz@lengzzz.com
log /var/log/caddy/lengzzz_com.log
redir / https://railgun.moe/{uri} 301
}

yum源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 备份yum源
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo_bak
# 阿里云yum源:
# centos7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# centos6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

# contos5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

# 网易yum源:
# centos7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

# centos6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo

# contos5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS5-Base-163.repo

# 中科大yum源:
# centos7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=3

# centos6
wget -O /etc/yum.repos.d/CentOS-Base.repo https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=2

# contos5
wget -O /etc/yum.repos.d/CentOS-Base.repo https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=1

epel源:
yum -y install epel-release

# 更新元数据,先清除原来的元数据缓存
sudo yum clean all
# 更新新的元数据缓存
sudo yum makecache

神奇的脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# https://github.com/233boy/v2ray/wiki
bash <(curl -s -L https://git.io/v2ray.sh)

# https://github.com/ToyoDAdoubi/doubi
wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ssr.sh && chmod +x ssr.sh && bash ssr.sh

# 安装 4合1 bbr 锐速安装脚本
wget -N --no-check-certificate "https://raw.githubusercontent.com/ylx2016/Linux-NetSpeed/master/tcp.sh" && chmod +x tcp.sh && ./tcp.sh

# https://github.com/wulabing/V2Ray_ws-tls_bash_onekey
wget -N --no-check-certificate -q -O install.sh "https://raw.githubusercontent.com/wulabing/V2Ray_ws-tls_bash_onekey/master/install.sh" && chmod +x install.sh && bash install.sh


# 南琴浪版暴力魔改BBR一键安装脚本
# https://github.com/tcp-nanqinlang/wiki/wiki/general
# Debian版:
wget --no-check-certificate https://github.com/tcp-nanqinlang/general/releases/download/3.4.2.1/tcp_nanqinlang-fool-1.3.0.sh
bash tcp_nanqinlang-fool-1.3.0.sh

# CentOS版:
wget --no-check-certificate https://raw.githubusercontent.com/tcp-nanqinlang/general/master/General/CentOS/bash/tcp_nanqinlang-1.3.2.sh
bash tcp_nanqinlang-1.3.2.sh
#根据步骤走,安装完内核后重启
shutdown -r now
# 南琴浪版暴力魔改BBR一键安装脚本-end

# https://github.com/ellermister/mtproxy
mkdir /home/mtproxy && cd /home/mtproxy
curl -s -o mtproxy.sh https://raw.githubusercontent.com/ellermister/mtproxy/master/mtproxy.sh && chmod +x mtproxy.sh && bash mtproxy.sh

# 网速测试
# https://bench.sh/
# 你可以使用以下命令来查看您的 Linux 系统信息,还可以测试网络带宽及硬盘读写速率
wget -qO- bench.sh | bash
# 或者
curl -Lso- bench.sh | bash

SELinux

1
2
3
setenforce 0 # 临时生效可以直接用setenforce 0 
# 1 启用
# 0 告警 不启用

方法

端口查询

1
2
3
netstat -ntlp   //查看当前所有tcp端口
netstat -ntulp | grep 80 //查看所有80端口使用情况
netstat -ntulp | grep 3306 //查看所有3306端口使用情况

目录浏览

nginx[宝塔]开启目录浏览模式(nginx autoindex)

在网站 设置 伪静态里边设置如下

1
2
3
4
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
charset utf-8,gbk;

端口映射

Xshell

Xshell

putty

putty

mount的基本用法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# https://wangchujiang.com/linux-command/c/mount.html
# mount命令 Linux mount命令是经常会使用到的命令,它用于挂载Linux系统外的文件。
# 格式:mount [-参数] [设备名称] [挂载点]
# 其中常用的参数有:
# -a 安装在/etc/fstab文件中类出的所有文件系统
# -f 伪装mount,作出检查设备和目录的样子,但并不真正挂载文件系统。
# -n 不把安装记录在/etc/mtab 文件中
# -r 讲文件系统安装为只读
# -v 详细显示安装信息
# -w 将文件系统安装为可写,为命令默认情况。
# -t <文件系统类型> 指定设备的文件系统类型
# msdos MS-DOS的fat,就是fat16
# vfat windows98常用的fat32
# nfs 网络文件系统
# iso9660 CD-ROM光盘标准文件系统
# ntfs windows NT/2000/XP的文件系统
# auto 自动检测文件系统

防火墙

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 永久的开放需要的端口

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

# 临时关闭防火墙,重启后会重新自动打开
systemctl restart firewalld

# 检查防火墙状态
firewall-cmd --state
firewall-cmd --list-all

# Disable firewall
systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld

# Enable firewall
systemctl enable firewalld
systemctl start firewalld
systemctl status firewalld

# ————————————————
# 日期:2021-01-15
# 参考链接:https://www.jianshu.com/p/bad33004bb4f

生成测试文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#32M
dd if=/dev/zero of=32M.bin bs=1M count=32 conv=fdatasync
#64M
dd if=/dev/zero of=64M.bin bs=1M count=64 conv=fdatasync
#128M
dd if=/dev/zero of=128M.bin bs=1M count=128 conv=fdatasync
#256M
dd if=/dev/zero of=256M.bin bs=1M count=256 conv=fdatasync
#512M
dd if=/dev/zero of=512M.bin bs=1M count=512 conv=fdatasync
#1GB
dd if=/dev/zero of=1024M.bin bs=1M count=1024 conv=fdatasync
# ————————————————
# 日期:2021-01-18
# 参考链接:https://www.runoob.com/linux/linux-comm-dd.html

错误

-bash: wget: command not found

解决:yum -y install wget

Try ‘chmod –help’ for more information.

解决:chmod +x xx.sh或是bash xx.sh

None of the supported tools for extracting zip archives (unzip 7z busybox) were found. Please install one of them and try agai

解决:yum install -y unzip

The nameserver prefix is invalid.

解决:只填NS Prefix前缀,不填.com域名之类,随意填写一些任意单词字母

umount 时出现的 “Device is busy”

umount, 老是提示:device is busy, 服务又不能停止的。

解决:用”umount -fl”解决

mount error(13): Permission denied

1
2
3
4
# 原
mount.cifs //192.168.123.13/dwonload /home/download/ --verbose -o username=root,password=root,iocharset=utf8,uid=0,gid=0
# 添加sec=ntlmssp
mount.cifs //192.168.123.13/dwonload /home/download/ --verbose -o username=root,password=root,sec=ntlmssp,iocharset=utf8,uid=0,gid=0

-bash: netstat: command not found

1
yum install -y net-tools

No package nginx available.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 1、备份原来的 CentOS-Base.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

# 2、下载新的 CentOS-Base.repo 到 / etc/yum.repos.d/

####centos 6版本
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

####centos 7版本
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

####centos 8版本
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

# 3、运行
yum makecache

# 作用:就是把服务器的包信息下载到本地电脑缓存起来,makecache 建立一个缓存,以后用 install 时就在缓存中搜索,提高了速度。

# 4、安装 epel 源

yum -y install epel-release

# 5、安装 NGINX 服务

yum -y install nginx
# ————————————————
# 日期:2020-12-01
# 参考链接:https://blog.csdn.net/l_liangkk/article/details/105003088

Nginx目录列表 403 无法显示

  1. 权限问题,可以尝试添加权限解决问题,即 chmod -R 755 /var/www/main 修改这个目录或者权限和其他目录
  2. SELinux策略问题,可以通过sestatus查看SELinux是否有开启,用sudo setenforce 0可以临时关闭SELinux模式,用vim /etc/selinux/config将SELINUX=enforcing改为SELINUX=disabled永可以永久关闭,具体详细可以Google一下,你就知道。
  3. 用户权限问题,vim /etc/nginx/nginx.conf 修改user 用户名改为user root

参考