数码之家

 找回密码
 立即注册
搜索
查看: 684|回复: 2

[软件] 服务器优化三步曲

[复制链接]
发表于 2024-12-12 11:22:44 | 显示全部楼层 |阅读模式
1.基础设置
切换到root权限
sudo -i1.1 改主机名


查看当前主机名
hostname

修改主机名为dreamshell,重启后生效 (推荐方法一)
方法一:
hostnamectl set-hostname dreamshell

方法二:直接修改主机名配置文件
vim /etc/hostname

:wq //保存退出1.2 修改源vim /etc/apt/sources.list
debian11的系统,这里替换成阿里云的源。
deb http://mirrors.cloud.aliyuncs.com/debian/ bullseye maindeb-src http://mirrors.cloud.aliyuncs.com/debian/ bullseye maindeb http://mirrors.cloud.aliyuncs.com/debian-security/ bullseye-security maindeb-src http://mirrors.cloud.aliyuncs.com/debian-security/ bullseye-security maindeb http://mirrors.cloud.aliyuncs.com/debian/ bullseye-updates maindeb-src http://mirrors.cloud.aliyuncs.com/debian/ bullseye-updates maindeb http://mirrors.cloud.aliyuncs.com/debian/ bullseye-backports maindeb-src http://mirrors.cloud.aliyuncs.com/debian/ bullseye-backports main

:wq 退出1.3 更新系统安装包apt update && apt upgrade -yapt install wget curl sudo vim git unzip -y  # Debian 系统比较干净,安装常用的软件

1.4 网络加速1.4.1开启bbr
BBR是 Google 提出的一种新型拥塞控制算法,可以使 Linux 服务器显著地提高吞吐量和减少 TCP 连接的延迟 ,可用于KVMXen架构,不兼容OpenVZ(OVZ)。
支持Centos 6+ / Debian 7+ / Ubuntu 14+,BBR魔改版不支持Debian 8,内核≥5.5推荐用自带bbr。
长期稳定推荐采用BBR + FQ,追求性能推荐用BBR2 + FQ_PIE。详细比较内容见《》
在安装BBR时,不卸载内核版本,则执行命令:
wget -O tcpx.sh "https://github.com/tudiedie/Linux-NetSpeed-TuDieDie/raw/master/tcpx.sh" && chmod +x tcpx.sh && ./tcpx.sh

这里直接用自带的内核,选择11即可
如果要替换内核,可以按照提示选择,默认会从高版本内核启动,不会删除原先内核。
选择52,可以删除其他不需要内核。
BBR2的内核集成在XANMOD内核当中。
选择9会跳到另一个内核安装脚本,该脚本会直接删除旧内核,安装新内核。


安装完毕后,重启一下机子
1.4.2 安装fastgithub
国内大部分服务器无法访问github,或者即时能访问也是速度慢,时灵时不灵的。需要给github加速一下。
一般有四种方法,这里用fastgithub。其他方法见《》
一步安装法:
# 合并为一行命令wget -c -O /opt/fastgithub_linux-x64.zip https://gitee.com/chcrazy/FastGi ... ithub_linux-x64.zip &&unzip -d /opt /opt/fastgithub_linux-x64.zip &&rm /opt/fastgithub_linux-x64.zip &&/opt/fastgithub_linux-x64/fastgithub start
分步安装法:
# 下载FastGithub Linux版安装包到opt目录# arm版本需要下载 fastgithub_linux-arm64.zip wget -c -O /opt/fastgithub_linux-x64.zip https://gitee.com/chcrazy/FastGi ... ithub_linux-x64.zip# 解压 unzip -d /opt /opt/fastgithub_linux-x64.zip# 删除FastGithub Linux版安装包rm /opt/fastgithub_linux-x64.zip# 切换目录cd /opt/fastgithub_linux-x64# 以systemd服务安装并启动,即开机自启动sudo /opt/fastgithub_linux-x64/fastgithub start# 卸载服务# sudo /opt/fastgithub_linux-x64/fastgithub stop# 手动启动# sudo /opt/fastgithub_linux-x64/fastgithub
sudo ./fastgithub start
以systemd服务安装并启动,即开机自启动
这样就算成功了:


设置代理
1.4.2.1 手动修改 /etc/profile文件
手动修改代理,在/etc/profile 添加
vim /etc/profile
添加下面代码
export http_proxy=http://127.0.0.1:38457 export https_proxy=http://127.0.0.1:38457
:wq 保存
source /etc/profile #更新shell
/etc/profile 开机重新会自动加载
1.5设置swapwget -O "/root/swap.sh" "https://raw.githubusercontent.com/BlueSkyXN/ChangeSource/master/swap.sh" --no-check-certificate  && chmod +x "/root/swap.sh" && chmod 777 "/root/swap.sh" && bash "/root/swap.sh"
选1,输入大小(MB),一般为物理内存的1.5-2倍。
内存 <= 4g:Swap 至少 4G
内存 4~16G:Swap 至少 8G
内存 16G~64G:Swap 至少 16G
内存 64G~256G:Swap 至少 32G



2.测试服务器性能
SuperBench脚本是一个测试linux服务器性能的脚本,让你快速方便了解一台服务器的综合性能,支持硬件基本信息、流媒体解锁检测、磁盘IO检测、CPU性能测试、以及国内和国外网络测速、网络路由追踪。
使用:
bash <(wget -qO- https://down.vpsaff.net/linux/speedtest/superbench.sh)wget -qO- https://down.vpsaff.net/linux/speedtest/superbench.sh | sudo bash



















3.安装docker docker-compose等常用软件更改镜像源提速
由于 http://hub.docker.com 无法访问,更改国内镜像源。
阿里云镜像需要从阿里云后台看。
登录:cr.console.aliyun.com
点击“创建我的容器镜像”,得到专属加速地址。


容器镜像
配置镜像
mkdir -p /etc/docker vim /etc/docker/daemon.json
填入dcoker配置
{  "log-driver": "json-file","log-opts": { "max-size": "20m", "max-file": "3"},"experimental":true,"registry-mirrors": [ "https://sokdt8pq.mirror.aliyuncs.com","https://v5iuyvw8.mirror.aliyuncs.com","https://dockerproxy.com",  "https://docker.nju.edu.cn",  "http://hub-mirror.c.163.com","https://docker.mirrors.sjtug.sjtu.edu.cn","https://docker.m.daocloud.io","https://docker.1panel.live"          }  systemctl daemon-reload  #重新加载docker配置systemctl restart docker  #重启docker



查看是否成功
docker info

Docker Hub 镜像测速
# 测速前先移除本地的镜像!$ docker rmi nginx:latest# 使用 time 统计所花费的总时间。$ time docker pull nginx:latestPulling repository nginx[...]real   1m14.078suser   0m0.176ssys    0m0.120s安装 Docker(国内服务器)curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyundocker -v  #查看 docker 版本systemctl enable docker  # 设置开机自动启动安装 Docker-compose(国内服务器)curl -L https://github.com/docker/compos ... 9.7/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-composechmod +x /usr/local/bin/docker-composedocker-compose --version  #查看 docker-compose 版本

一键安装# 一键安装命令curl -fsSL https://github.com/tech-shrimp/d ... oad/latest/linux.sh| bash -s docker --mirror Aliyun# 备用(如果Github访问不了,可以使用Gitee的链接)curl -fsSL https://gitee.com/tech-shrimp/do ... oad/latest/linux.sh| bash -s docker --mirror Aliyun# 启动dockerservice docker start安装 Docker(非大陆服务器)wget -qO- get.docker.com | bashdocker -v  #查看 docker 版本systemctl enable docker  # 设置开机自动启动安装 Docker-compose(非大陆服务器)curl -L https://github.com/docker/compos ... 3.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-composesudo chmod +x /usr/local/bin/docker-composedocker-compose --version  #查看 docker-compose 版本


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

打赏

参与人数 1家元 +15 收起 理由
不长叶子的树 + 15

查看全部打赏

发表于 2024-12-28 09:29:37 | 显示全部楼层
不明觉厉,但还是看完了
回复 支持 反对

使用道具 举报

发表于 2025-2-6 08:49:41 | 显示全部楼层
安装个cockpit通过9090端口从Web界面访问,可实现全中文图形化操作,sudo apt install cockpit,
sudo systemctl start cockpit.socket; sudo ufw allow 9090/tcp
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2025-5-1 19:58 , Processed in 0.062400 second(s), 8 queries , Redis On.

Powered by Discuz!

© 2006-2025 MyDigit.Net

快速回复 返回顶部 返回列表