最近来来回回折腾了上百次服务器,每次折腾总要做一些重复的操作,挺麻烦,干脆记录一些常用操作,方便日后复制粘贴。
重装系统组件:apt-get install -y xz-utils openssl gawk file wget screen && screen -S os
一键DD脚本:wget --no-check-certificate -O NewReinstall.sh https://git.io/newbetags && chmod a+x NewReinstall.sh && bash NewReinstall.sh
apt update && apt install -y curl wget sudo gnupg2 htop gcc git cmake
echo 'deb http://deb.xanmod.org releases main' | tee /etc/apt/sources.list.d/xanmod-kernel.list
wget -qO - https://dl.xanmod.org/gpg.key | apt-key --keyring /etc/apt/trusted.gpg.d/xanmod-kernel.gpg add -
apt update && apt install linux-xanmod-rt-edge -y && reboot
修改为 UTC 时区:timedatectl set-timezone UTC
修改为中国时区:timedatectl set-timezone Asia/Shanghai
timedatectl set-timezone Asia/Shanghai # 设置系统时区为上海
timedatectl set-timezone Asia/Tokyo # 设置系统时区为东京
timedatectl set-timezone Asia/Kolkata #【设置印度时区】
timedatectl set-timezone America/New_York #【设置美国纽约的时区】
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)
#开放所有端口
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
Ubuntu镜像默认设置了Iptable规则,防火墙解除(甲骨文云)
apt autoremove netfilter-persistent* -y
reboot
或者强制删除
rm -rf /etc/iptables && reboot
wget -O jcnfbox.sh https://raw.githubusercontent.com/Netflixxp/jcnf-box/main/jcnfbox.sh && chmod +x jcnfbox.sh && clear && ./jcnfbox.sh
wget -N https://cdn.jsdelivr.net/gh/ednovas/vpstoolbox@main/ednovastool.sh && chmod +x ednovastool.sh && ./ednovastool.sh
apt update
apt remove vim-common -y
apt install vim -y
ssh-keygen
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
sudo -i
echo root:123123 |sudo chpasswd root
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
service sshd restart
vi /etc/ssh/sshd_config
ClientAliveInterval 60 # server每隔60秒给客户端发送一次保活信息包给客户端
ClientAliveCountMax 86400 # server端发出的请求客户端没有回应的次数达到86400次的时候就断开连接,正常情况下客户端都会相应
service ssh restart # 重启配置文件
curl -sL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
bash nodesource_setup.sh
apt install nodejs -y
npm install npm -g
查询硬盘:ls /dev/disk/by-id/
格式化:mkfs.ext4 -F /dev/disk/by-id/scsi-0BUYVM_SLAB_VOLUME-0000
挂载:mount -o discard,defaults /dev/disk/by-id/scsi-0BUYVM_SLAB_VOLUME-0000 /data
开机挂载:echo '/dev/disk/by-id/scsi-0BUYVM_SLAB_VOLUME-0000 /data ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab
Apache Maven是主要用于Java项目的开源项目管理和理解工具。Maven使用项目对象模型POM。
POM对象本质上是一个XML文件,其中包含项目配置详细信息,项目的依赖关系等的信息。
使用apt
在Ubuntu 20.04安装Maven是一个简单,直接的过程。首先是更新软件包索引运行命令sudo apt update
。
然后就是运行命令sudo apt install maven
安装Maven。要验证安装,可以运行命令mvn -version
,命令将会打印Maven的版本号。
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.7, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-26-generic", arch: "amd64", family: "unix"
现在,Maven已安装在Ubuntu 20.04系统,您可以开始使用它。
在Ubuntu系统安装JDK的最简单方法是通过APT包管理器进行安装,执行以下步骤即可:
1.更新系统软件包列表:
2.安装JDK 8:
3.验证JDK是否安装成功:
如果JDK成功安装,应该能够看到类似如下输出:
运行所有一键修复脚本前注意看说明,以及保证服务器无重要数据,运行后造成的一切后果作者不负任何责任,自行评判风险!
apt update
不会报错,其他命令报错未修复curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/package.sh -o package.sh && chmod +x package.sh && bash package.sh
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/modify_time.sh -o modify_time.sh && chmod +x modify_time.sh && bash modify_time.sh
sudo: unable to resolve host xxx: Name or service not known
警告(爆错)不要在生产环境上使用该脚本,否则容易造成网络hosts配置错误,配置的host名字不在外网IP上反而在内网IP(127.0.0.1)上
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/check_sudo.sh -o check_sudo.sh && chmod +x check_sudo.sh && bash check_sudo.sh
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/resize_journal.sh -o resize_journal.sh && chmod +x resize_journal.sh && bash resize_journal.sh
该脚本轻易勿要使用,请确保运行时服务器无重要文件或程序,出现运行bug后续可能需要重装系统
一定要在screen中执行该脚本,否则可能导致修改过程中ssh断链接而修改失败卡住最终SSH无法连接!不在screen中执行后果自负!
curl -L https://cdn.spiritlhl.workers.dev/https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/network.sh -o network.sh && chmod +x network.sh && bash network.sh
如果是纯V6的也可以不使用上面脚本的nat64,使用warp添加V4网络
比如:https://gitlab.com/fscarmen/warp
wget -N https://gitlab.com/fscarmen/warp/-/raw/main/menu.sh && bash menu.sh [option] [lisence/url/token]
非纯V6的,带V4切换优先级到IPV4可用以下命令
sudo sed -i 's/.*precedence ::ffff:0:0\/96.*/precedence ::ffff:0:0\/96 100/g' /etc/gai.conf && sudo systemctl restart networking
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/repair_scripts/unlimit.sh -o unlimit.sh && chmod +x unlimit.sh && bash unlimit.sh
只推荐在新服务器上安装,环境不纯净不保证不出bug
运行所有一键环境安装脚本前注意看说明,以及保证服务器无重要数据,运行后造成的一切后果作者不负任何责任,自行评判风险!
原始用途是方便快捷的在按小时计费的超大型服务器上部署python环境进行科学计算,充分利用时间别浪费在构建环境上。
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/jupyter.sh -o jupyter.sh && chmod +x jupyter.sh && bash jupyter.sh
sudo /usr/bin/Xorg
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/R.sh -o R.sh && chmod +x R.sh && bash R.sh
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/rust.sh -o rust.sh && chmod +x rust.sh && bash rust.sh
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/cplusplus.sh -o cplusplus.sh && chmod +x cplusplus.sh && bash cplusplus.sh
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/vnstat.sh -o vnstat.sh && chmod +x vnstat.sh && bash vnstat.sh
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/todebian11.sh -o todebian11.sh && chmod +x todebian11.sh && bash todebian11.sh
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/toubuntu22.sh -o toubuntu22.sh && chmod +x toubuntu22.sh && bash toubuntu22.sh
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/zipline.sh -o zipline.sh && chmod +x zipline.sh && bash zipline.sh
如果需要删除0字节文件,打开/root/zipline
文件夹,执行
docker-compose exec zipline yarn scripts:clear-zero-byte
按照提示操作
lsof -i:3030
查看绑定情况,切换优先级后再安装就正常了curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/filebrowser.sh -o filebrowser.sh && chmod +x filebrowser.sh && bash filebrowser.sh
curl -L https://raw.githubusercontent.com/spiritLHLS/one-click-installation-script/main/install_scripts/dlm.sh -o dlm.sh && chmod +x dlm.sh && bash dlm.sh
bash <(curl -sSL https://raw.githubusercontent.com/fscarmen/tools/main/root.sh) [PASSWORD]
iptables -A INPUT -p tcp --dport 25 -j DROP
iptables -A OUTPUT -p tcp --dport 25 -j DROP
/sbin/iptables-save
sudo apt update
sudo apt install -y locales
sudo locale-gen en_US.UTF-8
echo 'LANG=en_US.UTF-8' | sudo tee /etc/default/locale
echo 'LC_ALL=en_US.UTF-8' | sudo tee -a /etc/default/locale
sudo sed -i '/^#.* en_US.UTF-8 /s/^#//' /etc/locale.gen
sudo locale-gen
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale
重新连接SSH或重启服务器以使得设置生效
sudo rm -rf /var/cache/apt/archives/lock
sudo pkill apt
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
sudo dpkg --configure -a
然后重启系统
apt-get install debian-keyring debian-archive-keyring -y
后续这块有计划整理为一个一键脚本
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 公钥
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
sudo sed -i 's/^mirrorlist=http/mirrorlist=https/' /etc/yum.repos.d/CentOS-Base.repo
安装时使用这里的方法:
https://gitlab.com/packaging/gitea
但不要设置无人值守自动升级版本,容易升级到一个有BUG的新版本
更改默认配置需要更改文件/etc/gitea/app.ini
比如设置文件上传无限制
[repository.upload]
ENABLED = true
ALLOWED_TYPES =
FILE_MAX_SIZE = 1024
MAX_FILES = 100
写在[security]
上面,每个模块[]
的内容之间间隔一个空行
apt install sysv-rc-conf -y && service bt stop && sysv-rc-conf bt off && rm -f /etc/init.d/bt && rm -rf /www/server/panel
find / -type f -size +100M -exec ls -lh {} \;
systemctl stop systemd-resolved
systemctl disable systemd-resolved
安装24版本的docker
curl -sSL https://get.docker.com/ | sh
或安装最新版本的docker(都选官方源即可)
bash <(curl -sSL https://linuxmirrors.cn/docker.sh)
安装docker-compose最新版本
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
卸载所有docker镜像和容器
docker rm -f $(docker ps -aq); docker rmi $(docker images -aq)
删除累积的docker日志
cd /var/lib/docker/containers/ && for container_id in */; do container_path="/var/lib/docker/containers/${container_id}"; log_file="${container_id%/}-json.log"; rm -rf "${container_path}${log_file}" && echo "已删除 ${container_path}${log_file}"; done
安装
mkdir -p ~/.config
docker run --restart=always --name code-server -p 0.0.0.0:8886:8080 \
-v "$HOME/.config:/home/coder/.config" \
-v "$PWD:/home/coder/project" \
-u "$(id -u):$(id -g)" \
-e "DOCKER_USER=$USER" \
codercom/code-server:latest
新窗口
docker exec code-server cat /root/.config/code-server/config.yaml
或
curl -fsSL https://code-server.dev/install.sh | sh -s -- --dry-run
sudo systemctl enable --now code-server@root
sed -i '1s/127.0.0.1:8080/0.0.0.0:8536/' ~/.config/code-server/config.yaml
sudo systemctl restart code-server@root
cat .config/code-server/config.yaml
卸载需要
sudo systemctl stop code-server@root
sudo systemctl disable code-server@root
rm -rf ~/.cache/coder
sudo apt remove coder -y