知了小站 - IT人的小站 - Linux系统 https://www.ydyno.com/tag/linux/ zh-CN Mon, 05 Jun 2023 14:16:00 +0800 Mon, 05 Jun 2023 14:16:00 +0800 Debian 10/11 安装最新版 Nginx https://www.ydyno.com/archives/1740.html https://www.ydyno.com/archives/1740.html Mon, 05 Jun 2023 14:16:00 +0800 知了小站 Debian 10 安装最新版的Nginx

要在Debian 10 上安装最新版的Nginx,可以使用以下步骤

1、更新系统

sudo apt update
sudo apt upgrade

2、添加 Nginx 的存储库密钥

wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key

3、添加 Nginx 的存储库到apt源列表中

echo "deb http://nginx.org/packages/mainline/debian/ $(lsb_release -cs) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list

4、更新存储库并安装 Nginx

sudo apt update
sudo apt install nginx

# 启动 nginx
sudo systemctl start nginx
# 设置自启
sudo systemctl enable nginx

Debian 11 安装最新版的Nginx

在Debian 11 上安装最新版的Nginx,可以使用以下步骤

1、更新系统

sudo apt update
sudo apt upgrade
# 安装 Nginx 的依赖项
sudo apt install curl gnupg2 ca-certificates lsb-release

2、添加 Nginx 的存储库密钥

curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor -o /usr/share/keyrings/nginx-archive-keyring.gpg

3、添加 Nginx 的存储库到apt源列表中

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/debian $(lsb_release -cs) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list

4、更新存储库并安装 Nginx

sudo apt update
sudo apt install nginx
# 启动 nginx
sudo systemctl start nginx
# 设置自启
sudo systemctl enable nginx
]]>
0 https://www.ydyno.com/archives/1740.html#comments https://www.ydyno.com/feed/tag/linux/
debian11 系统增加开机自启脚本 https://www.ydyno.com/archives/1736.html https://www.ydyno.com/archives/1736.html Fri, 21 Apr 2023 10:30:00 +0800 知了小站 在 debian11 系统增加开机自启脚本时发现 /etc 目录里面没有 rc.local 文件,导致无法添加自启动脚本,这里记录下 debian11 增加开机自启脚本的全过程。

修改 rc-local.service 文件

cd /lib/systemd/system

添加下面内容到 rc-local.service 文件最后

[Install]  
WantedBy=multi-user.target

创建 /etc/rc.local 文件

创建 /etc/rc.local 文件,并写入下面内容

#!/bin/sh -e

# 在这里输入需要自启的脚本
exit 0

创建完成后需要给其赋予运行权限

sudo chmod +x /etc/rc.local

启动 rc-local 服务即可

sudo systemctl enable rc-local  # 启用
sudo systemctl start rc-local.service # 开始运行
sudo systemctl status rc-local.service  # 查看状态
]]>
0 https://www.ydyno.com/archives/1736.html#comments https://www.ydyno.com/feed/tag/linux/
记 Debian 11 机器安装 python3 和 pip 的过程 https://www.ydyno.com/archives/1426.html https://www.ydyno.com/archives/1426.html Sat, 09 Apr 2022 16:44:00 +0800 知了小站 由于搭建 gh-proxy Github加速工具需要用到 python 环境,因此记录下在 Debian10/11 机器安装 python3 和 pip 的过程

准备工作

apt update

开始安装

## 安装 python
apt install python3.9
apt install python3.9-dev
apt install python3.9-venv
# 安装 pip
wget https://bootstrap.pypa.io/get-pip.py
python3.9 get-pip.py
# 建立连接
ln -s /usr/bin/python3.9 /usr/local/bin/python3
ln -s /usr/local/bin/pip /usr/local/bin/pip3

成品 Github 加速站点:https://proxy.zyun.vip/

]]>
3 https://www.ydyno.com/archives/1426.html#comments https://www.ydyno.com/feed/tag/linux/
Linux 系统中查看 crontab 运行产生的日志 https://www.ydyno.com/archives/1412.html https://www.ydyno.com/archives/1412.html Wed, 19 Jan 2022 16:14:00 +0800 知了小站 在 Linux 中查看 crontab 运行的日志,只需要编辑系统日志配置文件 rsyslog.conf,取消相关注释即可,命令如下:

vi /etc/rsyslog.conf

切换英文模式,输入 /cron.* 定位到日志 log 配置

kyl9mcew.png

将前面的#注释去掉,后面就是是日志文件的路径。

保存退出,输入下面命令重启日志服务

service rsyslog restart 
或者 
systemctl restart rsyslog

配置完成后,crontab 执行的日志文件就输出到 /var/log/cron.log 了

]]>
2 https://www.ydyno.com/archives/1412.html#comments https://www.ydyno.com/feed/tag/linux/
Linux 使用脚本一键 DD 脚本(重装)Centos 6/7 系统 https://www.ydyno.com/archives/1374.html https://www.ydyno.com/archives/1374.html Wed, 04 Aug 2021 16:48:00 +0800 知了小站 Linux一键DD脚本,脚本支持一键 DD(重置)为 CentOS 7、CentOS 6、Debian 9、Debian 10、ubuntu 18.10 等系统,有时候需要手动指定 IP地址、网关地址、子网掩码信息,如果填错就会导致 DD 失败。

krx917bp.png

安装网络工具包

# Ubuntu、Debian
apt-get install net-tools

# CentOS
yum install net-tools

获取本机IP地址

这里获取到的可能是内网地址,也有可能是外网地址,例如:谷歌云机器,获取的就是内网地址

输入命令 ifconfig -a 获取

krx8rx0p.png

获取网关与掩码

输入命令 route -n

krx8u92p.png

DD成Centos系统

输入命令:

wget --no-check-certificate -qO AutoDD.sh 'https://raw.githubusercontent.com/hiCasper/Shell/master/AutoReinstall.sh' && bash AutoDD.sh

填入获取到的IP,网关、子网掩码信息

krx8y2ia.png

选择需要重置的系统后,会出现默认密码,复制默认密码保存下来,等待重置结束即可

]]>
0 https://www.ydyno.com/archives/1374.html#comments https://www.ydyno.com/feed/tag/linux/
使用宝塔搭建网站,Nginx 如何禁止 IP 直接访问,防止恶意解析 https://www.ydyno.com/archives/1333.html https://www.ydyno.com/archives/1333.html Sun, 27 Jun 2021 22:05:00 +0800 知了小站 为什么要禁用

Nginx 禁用 IP 访问的目的是为了防止恶意解析,比如他人将未备案的域名解析到自己的服务器IP,而导致一些不可预估的问题。这个时候就需要配置 Nginx 来禁用 IP 访问,预防此类事情的发生。

宝塔具体配置

这里是默认认为你是通过宝塔面板来搭建的网站,首先进入文件夹 /www/server/panel/vhost/nginx,打开 0.default.conf

kqf99jh7.png

第一种方式

直接将下面配置复制粘贴进去,覆盖原配置

server
{
    listen 80;
    server_name _;
    return 403;
}

第二种方式

把这些流量收集起来,导入到自己的网站,只要做以下跳转设置:

server
{
    listen 80;    
    server_name _;
    rewrite ^(.*) http://自己的网址 permanent; 
}

https流量也拦截

这里的证书,可以使用你要跳转的网站的证书,或者其他证书都行

server
{
    listen 80;
    listen 443 ssl http2;

    # 这里的证书,可以使用你要跳转的网站的证书,或者其他证书都行
    ssl_certificate    /www/server/panel/vhost/cert/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    
    server_name _;
    rewrite ^(.*) http://www.ydyno.com permanent; 
}

未使用宝塔

找到 nginx 的默认配置文件 nginx.conf, 找到 默认的 80 server,配置方式同上方

如果找不到默认的 80 server 那直接将上面的复制进去就可以了

]]>
1 https://www.ydyno.com/archives/1333.html#comments https://www.ydyno.com/feed/tag/linux/
通过命令将 Debian 9 升级 Debian 10 的步骤 https://www.ydyno.com/archives/1300.html https://www.ydyno.com/archives/1300.html Tue, 22 Jun 2021 22:18:00 +0800 知了小站 更新已有软件
apt-get update && apt-get upgrade

更改 apt source list 配置

sed -i 's/stretch/buster/g' /etc/apt/sources.list

再次更新升级

apt-get update && apt-get upgrade && apt-get dist-upgrade

kq8570jj.png

出现这个界面,选择 Yes 然后继续更新

完成后重启

reboot

查看 Debian 版本

cat /etc/os-release

kq856l99.png

]]>
0 https://www.ydyno.com/archives/1300.html#comments https://www.ydyno.com/feed/tag/linux/
Centos 7 彻底卸载清除 Docker 环境 https://www.ydyno.com/archives/1278.html https://www.ydyno.com/archives/1278.html Mon, 08 Mar 2021 21:30:00 +0800 知了小站 CentOS 7 彻底卸载 Docker 环境流程如下

杀死所有运行容器
docker kill $(docker ps -a -q)
删除所有Docker容器
docker rm $(docker ps -a -q)
删除所有Docker镜像
docker rmi $(docker images -q)
停止 docker 服务
systemctl stop docker
删除存储目录
rm -rf /etc/docker
rm -rf /run/docker
rm -rf /var/lib/dockershim
rm -rf /var/lib/docker

如果发现删除不掉,需要先 umount,如

umount /var/lib/docker/devicemapper
卸载 docker

查看已安装的 docker 包

yum list installed | grep docker

卸载相关包

l1nn4gdy.png

yum remove docker-ce*
yum remove containerd.io.x86_64

原文地址:https://www.omicsclass.com/article/1184

]]>
0 https://www.ydyno.com/archives/1278.html#comments https://www.ydyno.com/feed/tag/linux/
彻底卸载阿里云服务器上的阿里云盾,以及其他监控服务 https://www.ydyno.com/archives/1277.html https://www.ydyno.com/archives/1277.html Mon, 08 Mar 2021 13:54:00 +0800 知了小站 用过阿里云服务器(ECS、轻量应用服务器)的人应该都知道,阿里云提供的系统镜像里预装了它的各种监控服务。

如:阿里云盾(安骑士)、云监控(Cloudmonitor)

这些监控服务的存在使得人们可以直接在控制台看到当前系统的状态,某种程度上来说确实方便了服务器的管理。但是对于我们这种“爱折腾党”,基本没有用到这些服务的时候,而且天天被这些监控盯着还总有种被偷窥的感觉。

卸载云盾(安骑士)

官方文档 页面只介绍了怎么在控制台去卸载,手动卸载的操作步骤需要提交工单获取,不是很方便。

在这里介绍一种用脚本手动卸载的方法(其实用的也是官方提供的两个脚本),执行以下命令即可。

wget http://update.aegis.aliyun.com/download/uninstall.sh && chmod +x uninstall.sh &&./uninstall.sh
wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh && chmod +x quartz_uninstall.sh && ./quartz_uninstall.sh

测试发现上面的脚本运行完之后可能还会有一些服务/文件/文件夹残留,所以我们手动清理一下,顺便把刚刚下下来的两个脚本文件也删了(如果提示文件不存在就不用管了)。

sudo rm -r /usr/local/aegis
sudo systemctl disable aliyun.service
sudo rm /usr/sbin/aliyun-service
sudo rm /usr/sbin/aliyun-service.backup
sudo rm /usr/sbin/aliyun_installer
sudo rm /etc/systemd/system/aliyun.service
sudo rm /lib/systemd/system/aliyun.service
rm uninstall.sh quartz_uninstall.sh

卸载云监控(Cloudmonitor)

云监控有 Java 版本和 Go 语言版本两种(Java 版本已经不再提供升级了,现在新开的服务器应该都是 Go 语言版本的),可以根据其安装目录 /usr/local/cloudmonitor/ 下的文件名判断你的服务器上装的具体是哪一种。下面分别介绍两个版本的卸载方法。

卸载云监控 Go 语言版

云监控 Go 语言版的可执行文件名为 CmsGoAgent.linux-${ARCH} ,其中的 ARCH 根据 Linux 架构的不同,分为 amd64386 ,可以在其安装目录 /usr/local/cloudmonitor/ 下找到具体的文件名。

为了方便表述,下面的命令中也使用 ${ARCH} 替代文件名中的系统架构部分。要能够直接复制下面的命令行去执行的话,可以先设置一下临时环境变量(相当于后面输入命令中的 ${ARCH} 会被自动替换成我们在这里设置的值)

# 64 位系统
export ARCH=amd64

# 32 位系统
export ARCH=386

或者的话你也可以在找到具体的文件名后自行替换。下面是卸载相关的一些命令:

# 从系统服务中移除
/usr/local/cloudmonitor/CmsGoAgent.linux-${ARCH} uninstall

# 停止
/usr/local/cloudmonitor/CmsGoAgent.linux-${ARCH} stop

# 卸载
/usr/local/cloudmonitor/CmsGoAgent.linux-${ARCH} stop && \
/usr/local/cloudmonitor/CmsGoAgent.linux-${ARCH} uninstall && \
rm -rf /usr/local/cloudmonitor

附上官方文档页面链接:https://help.aliyun.com/document_detail/97929.html

卸载云监控 Java 版
# 停止
/usr/local/cloudmonitor/wrapper/bin/cloudmonitor.sh stop

# 卸载
/usr/local/cloudmonitor/wrapper/bin/cloudmonitor.sh remove && \
rm -rf /usr/local/cloudmonitor

附上官方文档页面链接:https://help.aliyun.com/knowledge_detail/38859.html

原文地址:https://xirikm.net/2019/331-1

]]>
2 https://www.ydyno.com/archives/1277.html#comments https://www.ydyno.com/feed/tag/linux/
Linux 使用脚本一键 DD(重装) 成纯净的 Linux 系统 https://www.ydyno.com/archives/1245.html https://www.ydyno.com/archives/1245.html Fri, 05 Feb 2021 22:34:00 +0800 知了小站 基本所有的VPS商家,都会提供免费的Linux系统供安装,如CentOS、Debian、Ubuntu等。那为什么还要使用一键DD脚本重装/更换系统呢?

  1. 商家提供的系统版本有限,可能没有自己需要的版本;
  2. 商家提供的系统大多都是改装过的,不纯净,可能存在软件兼容行问题;
  3. 商家提供的系统大多带有监控,虽说可以卸载,但是心里总是有疙瘩;

以上几种情况,就需要Linux一键DD脚本,一键DD脚本可以为服务器更换一个纯净的系统,帮你解决问题。

一键安装Linux系统

下列脚本支持系统重置为 CentOS 7、CentOS 6、Debian 9、Debian 10、ubuntu 18.10。注意有些脚本需要获取 IP、网关、子网掩码等信息,需要填写正确才行安装成功。

注意重装有风险,可能导致无法开机,谨慎操作!

使用脚本前最好先安装如下软件

# CentOS 与 RedHat
yum install -y xz openssl gawk file wget

# Debian 与 Ubuntu
apt-get install -y xz-utils openssl gawk file
安装 CentOS
wget --no-check-certificate -qO AutoDD.sh 'http://git.io/autodd.sh' && bash AutoDD.sh

krx917bp.png

安装 Debian
wget --no-check-certificate -qO InstallNET.sh 'https://moeclub.org/attachment/LinuxShell/InstallNET.sh' && chmod a+x InstallNET.sh

# 安装 debian 9 64位
bash InstallNET.sh -d 9 -v 64 -a --mirror 'http://mirrors.ustc.edu.cn/debian/'

# 安装 debian 10 64位
bash InstallNET.sh -d 10 -v 64 -a --mirror 'http://mirrors.ustc.edu.cn/debian/'
安装 Ubuntu
wget --no-check-certificate -qO InstallNET.sh 'https://moeclub.org/attachment/LinuxShell/InstallNET.sh' && chmod a+x InstallNET.sh

# 安装ubuntu 18.10 64位
bash InstallNET.sh -u 18.10 -v 64 -a --mirror 'http://archive.ubuntu.com/ubuntu/'
国内可使用
wget --no-check-certificate -qO InstallNET.sh 'https://moeclub.org/attachment/LinuxShell/InstallNET.sh' && chmod a+x InstallNET.sh

bash InstallNET.sh -d 9 -v 64 -a --mirror 'https://mirrors.huaweicloud.com/debian/'

bash InstallNET.sh -d 9 -v 64 -a --mirror 'https://mirrors.aliyun.com/debian/'

bash InstallNET.sh -d 9 -v 64 -a --mirror 'https://mirrors.cloud.tencent.com/debian/'
安装时指定密码
# 所有脚本都可以加入参数 -p 来设置默认密码,如:

bash InstallNET.sh -d 9 -v 64 -p 123456 -a --mirror 'https://mirrors.cloud.tencent.com/debian/'

安装后默认端口: 22
安装后默认用户名: root
安装后默认密码: MoeClub.org

]]>
5 https://www.ydyno.com/archives/1245.html#comments https://www.ydyno.com/feed/tag/linux/