在新购买服务器后,安装应用程序之前,一般会初始化服务器各项配置。如更换源、更新包、修改服务器名称等,这里记录下常用的初始化命令

Hippopx.jpg

这里以Centos7.x为例,以下命令请在root用户下执行

查看系统版本

cat /etc/redhat-release

查看系统磁盘情况

df -h

修改服务器名称

hostnamectl set-hostname 新名称

修改服务器密码

passwd

输入2次新密码即可

更改ssh端口

vi /etc/ssh/sshd_config

修改#Port 22行为Port 指定端口,保存后重启机器即可

关闭默认防火墙

systemctl stop firewalld.service && systemctl disable firewalld.service

关闭seLinux

sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

更换源

更换国内源可以加快软件包的安装
阿里云源:https://developer.aliyun.com/mirror/centos
腾讯云源:https://mirrors.tencent.com/help/centos.html
华为云源:https://mirrors.huaweicloud.com/home

更新软件包

yum update -y

安装第三方软件源

yum install epel-release -y

安装必要软件包

yum install htop wget yum-utils device-mapper-persistent-data lvm2 -y

一键自动分区、格式化、挂载脚本

https://linuxeye.com/433.html

wget http://mirrors.linuxeye.com/scripts/auto_fdisk.sh
chmod +x auto_fdisk.sh
./auto_fdisk.sh

一键设置SWAP虚拟内存

https://github.com/nix18/Linux-SWAP

wget https://4xx.me/swap.sh
chmod +x swap.sh
./swap.sh

https://raw.githubusercontent.com网址被墙,我将脚本放到了博客上

服务器测试脚本

wget -N --no-check-certificate https://4xx.me/test_91yun.sh && bash test_91yun.sh s
wget -qO- https://4xx.me/superbench.sh | bash -s info

网络加速器(BBR、BBRplus、锐速、XANMOD等)

https://github.com/ylx2016/Linux-NetSpeed

wget -O tcpx.sh "https://git.io/JYxKU" && chmod +x tcpx.sh && ./tcpx.sh

一般国外服务器才需要安装

安装Docker-CE

使用腾讯脚本安装
https://mirrors.tencent.com/help/docker-ce.html

# CentOS/RHEL
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
# 把软件仓库地址替换为:
sudo sed -i 's+download.docker.com+mirrors.cloud.tencent.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# 安装
sudo yum makecache fast
sudo yum install docker-ce
# 设置开机启动
sudo systemctl enable docker

Docker配置加速源:Linux/Centos7.x安装Docker-CE及优化配置

重启

初始化完服务器建议重启一下

reboot