dev/root 100% 占用解决记录
通过下面的命令查看各文件夹 大小
sudo du --max-depth=1 -h # 统计当前文件夹下各个文件夹的大小显示为M
最终发现Var/log 占用很大空间
发现下面两个 log 占用空间很大,直接 rm-rf 即可
Linux 系统 /var/log/journal/ 垃圾日志清理-CSDN博客
查看垃圾文件的方法
未清理前发现硬盘根分区空间告急,用
du -t 100M /var
或
journalctl --disk-usage
命令查看,发现/var/log/journal日志文件占用了近3G空间,每个日志文件体积高达8-128M,这些日志文件记录了很长时间以来的systemd情况,毫无价值,用
journalctl --vacuum-size=10M
命令将其清理之后,腾出了2.7G的空间。用df命令一查,/根分区果然宽敞了很多。
HI NAS python3 记录
# 安装pip3
sudo apt update
sudo apt install python3-pip
pip3 --version
whereis python3
python3 -version
pip install *.whl
开机自动挂载硬盘
https://www.cnblogs.com/fieldtianye/p/9295986.html
sudo blkid
mount命令重启后会失效,将分区信息写入 /etc/fstab 文件启动自动挂载:
sudo vim /etc/fstab
在文件内插入下面代码
UUID=6ec1ccd7-38da-412b-a65e-4c136666e292 /home ext4 defaults 0 1
sudo mount -a
标记的是要开机挂载的 内存卡
开机自动运行程序
Linux中没有rc.local文件的解决方法_linux 没有rc.local_七天啊的博客-CSDN博客
上面的方式有时候不管用
自己写一个shell脚本
将写好的脚本(.sh文件)放到目录 /etc/profile.d/ 下,系统启动后就会自动执行该目录下的所有shell脚本。
查看当前系统中的端口使用情况
# 查看TCP UDP Listen 显示所有已打开的端口
sudo netstat -tuln
#查看TCP Listen
sudo netstat -tln
#查看UDP Listen
sudo netstat -uln
查看运行的服务
// 查看所有服务
$ sudo systemctl list-units --type=service
nginx配置
nginx 用来将端口 绑定到指定地址(或者页面,比如说我通过ip+8080 默认访问nginx默认页,
在server 中编辑了location,在location 使用了代理,那么最终ip+8080 访问的就是你代理的地址)
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name localhost;
location / {
#proxy_pass http://192.168.1.4/zhinan.html;
#proxy_pass http://192.168.1.4:6008;
proxy_pass http://192.168.1.4/blog/;
#alias /home/MCU_BINS/; #指定哪个目录作为Http文件服务器的根目录
}
}
server {
#端口(本机没有使用过的端口)
listen 21081;
server_name "MCU_BIN";
#配置跨域
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
add_header Access-Control-Allow-Headers Content-Type,Authorization;
location / {
#代理的本地文件夹
root /home/MCU_BINS/;
#开启目录浏览功能;
autoindex on;
#关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b;
autoindex_exact_size off;
#开启以服务器本地时区显示文件修改日期!
autoindex_localtime on;
}
}
nginx常用命令
# 检查nginx 是否安装,如果安装就自动卸载
apt-get --purge autoremove nginx
# 检查本机是否还有nginx程序在后台运行,如果有直接kill掉。
ps -ef | grep nginx
# 安装nginx
sudo apt install nginx
apt-get update apt-get install nginx # 默认版本
apt-get update apt-cache show nginx # 选择版本安装
apt-get install nginx=1.18.0-0ubuntu1.4 # 选择指定版本安装
# 查看版本
nginx -v
# nginx 安装好后,配置文件在如下
# /usr/sbin/nginx:主程序
# /etc/nginx:存放配置文件
# /usr/share/nginx:存放静态文件
# /var/log/nginx:存放日志
cd /etc/nginx
# 查看状态
sudo systemctl status nginx.service
# 开启 nginx 服务
sudo systemctl start nginx.service
# 停止 nginx 服务
sudo systemctl stop nginx.service
# 重启服务
sudo systemctl restart nginx.service
# 启动nginx服务后, 访问 http://ip+8080/
http://192.168.1.4:8080/
# 重新加载配置
sudo systemctl reload nginx.service
# 检查nginx.conf 文件是否正确
nginx -t
pass的log 如下
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
frpc教程
systemctl stop frpc #先停止frp客户端的服务,再执行后面的两条命令
vim /etc/frp/frpc.ini
frpc -c /etc/frp/frpc.ini
frpc -c /etc/frp/frpc.toml #frpc 0,52.3 更新后,配置使用了toml文件,不再使用.ini
#https://bbs.histb.com/d/1414-hai-na-si-xi-tong-frpcnei-wang-chuan-tou-shi-yong-jiao-cheng
#https://gofrp.org/zh-cn/docs/examples/ssh/
#https://gofrp.org/zh-cn/docs/examples/vhost-http/
systemctl restart frpc
systemctl start frpc
systemctl enable frpc
systemctl enable frpc # 注意是frpc,如果是frp,会出错(Failed to stop frp.service: Unit frp.service not loaded.) 这时执行systemctl daemon-reload
sudo systemctl status frps
sudo systemctl status frpc
#https://gofrp.org/zh-cn/docs/setup/systemd/
# https://bbs.histb.com/d/1414-hai-na-si-xi-tong-frpcnei-wang-chuan-tou-shi-yong-jiao-cheng
frpc.ini配置里
http 使用通过域名访问,访问代理的本地端口
ssh 是通过 remoteport 访问代理的本地端口
frpc+nginx
内网穿透原理, frps 需要跑在有公网的服务器上, frpc 跑在 需要被访问的内网客户端(frpc.ini 需要手动配置这个文件),
ssh+tcp类型访问
在frpc.ini 里定义了ssh, tcp类型,我通过ssh 终端加remote port 就可以访问内网的客户端
下面的配置表示,可以通过remote port + ip 访问本地的22 端口,22端口一般默认为终端
ssh -p 21080 ip(frps运行的公网服务器ip)
[ssh-21080]
type = tcp
# 链接的类型 这里使用的tcp类型
local_ip = 127.0.0.1
# 本地ip
local_port = 22
# 本地开放的端口
remote_port = 21080
# 映射出去的端口 意思就是本地端口被映射到 服务器上的21080
web+http类型访问
[web-mcubin]
type = http
local_ip = 127.0.0.1
local_port = 21081
#remote_port = 21081
subdomain = nas-mcubin
这时 我可以通过手机(移动4g网络下),访问下面地址去进入 内网客户端的 21081 端口。其中.199.net 是你frps 服务器给你分配的二级域名.
https://nas-mcubin.199.net
如果通过nginx 绑定21081 端口 为内网客户端的 nas 文件夹,上面的网址就可以访问内网客户端的nas文件夹了。
同理如果nginx 绑定这个端口为 其他地址,通过上面的网址也可以访问
ssh
ssh -V
OpenSSH_8.2p1 Ubuntu-4ubuntu0.9, OpenSSL 1.1.1f 31 Mar 2020
首先查看当前Ubuntu安装的SSH服务:
dpkg -l | grep ssh
ii libssh-4:armhf 0.9.3-2ubuntu2.3 armhf tiny C SSH library (OpenSSL flavor)
ii openssh-client 1:8.2p1-4ubuntu0.9 armhf secure shell (SSH) client, for secure access to remote machines
ii openssh-server 1:8.2p1-4ubuntu0.9 armhf secure shell (SSH) server, for secure access from remote machines
ii openssh-sftp-server 1:8.2p1-4ubuntu0.9 armhf secure shell (SSH) sftp server module, for SFTP access from remote machines
ii ssh 1:8.2p1-4ubuntu0.9 all secure shell client and server (metapackage)
ii ssh-import-id 5.10-0ubuntu1 all securely retrieve an SSH public key and install it locally
vsftp
搭建FTP服务 vsftpd应用配置 文件传输 (Ubuntu、树莓派)附vim编辑器教程-CSDN博客
vim /etc/vsftpd.conf
常用的全局配置项:
listen=YES:是否以独立运行的方式监听服务
listen_address=192.168.4.1:设置监听的 IP 地址
listen_port=21:设置监听 FTP 服务的端口号
write_enable=YES:是否启用写入权限
download_enable=YES:是否允许下载文件
userlist_enable=YES:是否启用 user_list 列表文件
userlist_deny=YES:是否禁用 user_list 中的用户
max_clients=0:限制并发客户端连接数
max_per_ip=0:限制同一 IP 地址的并发连接数
常用的匿名 FTP 配置项:
anonymous_enable=YES:启用匿名访问
anon_umask=022:匿名用户所上传文件的权限掩码
anon_root=/var/ftp:匿名用户的 FTP 根目录
anon_upload_enable=YES:允许上传文件
anon_mkdir_write_enable=YES:允许创建目录
anon_other_write_enable=YES:开放其他写入权
anon_max_rate=0:限制最大传输速率(字节/秒)
常用的本地用户 FTP 配置项:
local_enable=YES:是否启用本地系统用户
local_umask=022:本地用户所上传文件的权限掩码
local_root=/var/ftp:设置本地用户的 FTP 根目录
chroot_local_user=YES:是否将用户禁锢在主目录
local_max_rate=0:限制最大传输速率(字节/秒)
以上列出的都是搭建vsftpd服务器时最常用到的配置项,理解并掌握这些配置项的含义,将更有利于快速部署和优化vsftpd服务器
参考配置:
# 禁止匿名用户登录
anonymous_enable=NO
# 允许系统用户登录
local_enable=YES
# 启用可以修改文件的 FTP 命令
write_enable=YES
# 本地用户创建文件的 umask 值
local_umask=022
# 允许为目录配置显示信息,显示每个目录下面的message_file文件的内容
dirmessage_enable=YES
# 开启日记功能
xferlog_enable=YES
# 使用标准的20端口来连接ftp
connect_from_port_20=YES
# 使用标准日志格式
xferlog_std_format=YES
# 如果启动这项功能,则所有列在chroot_list_file之中的使用者不能更改根目录
chroot_list_enable=YES
# 指定限制的用户文件
chroot_list_file=/etc/vsftpd/chroot_list
# ftp服务器将处于独立启动模式
listen=YES
# 设置一个本地用户登录后进入到的目录
local_root=/home/ftp
# 设置PAM认证服务的配置文件名称,该文件保存在“/etc/pam.d/”目录下
pam_service_name=vsftpd
# ftp将检查userlist_file设置文件中指定的用户是否可以访问vsftpd服务器
userlist_enable=YES
# 只允许user_list文件中记录的ftp用户能登录vsftp服务,其他的ftp用户都不可以登录。
userlist_deny=NO
# 定义限制/允许用户登录的文件
userlist_file=/etc/vsftpd/allowed_users
# ftp服务器将使用tcp_wrappers作为主机访问控制模式
tcp_wrappers=YES
# 连接ftp服务费使用的端口
listen_port=21
service vsftpd start
service vsftpd restart
service vsftpd status
外网 访问 ftp 就直接用frpc.ini 里server_addr 地址,外加上22 端口的remote port 填入filezila 就可以访问了 。