首页 » 云主机教程 » 正文

Linux | 常用服务配置大全

Linux服务中需要配置的东西有很多,这里介绍常用的服务配置
配置系统:CentOS7

yum源

镜像源

阿里镜像源

curl -o /etc/yum.repos.d/base.repo https://mirrors.aliyun.com/repo/Centos-7.repo & \
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo & \
curl -o /etc/yum.repos.d/ius.repo https://mirrors.aliyun.com/ius/ius-7.repo & \
yum  clean all & yum  makecache

腾讯镜像源

curl -o /etc/yum.repos.d/base.repo https://mirrors.cloud.tencent.com/repo/centos7_base.repo & \
curl -o /etc/yum.repos.d/epel.repo https://mirrors.cloud.tencent.com/repo/epel-7.repo & \
curl -o /etc/yum.repos.d/ius.repo https://mirrors.cloud.tencent.com/ius/ius-7.repo & \
yum  clean all & yum  makecache

华为镜像源

curl -o /etc/yum.repos.d/base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo & \
curl -o /etc/yum.repos.d/epel.repo https://repo.huaweicloud.com/repository/conf/epel-7-reg.repo & \
curl -o /etc/yum.repos.d/ius.repo https://repo.ius.io/ius-7.repo & \
yum  clean all & yum  makecache

dnf

yum install -y dnf

最新版

最新版nodejs

curl –silent –location https://rpm.nodesource.com/setup_12.x | bash -

yum install -y nodejs

# nodejs 镜像加速
# cnpm方案:npm install -g cnpm --registry=https://registry.npm.taobao.org
npm config set registry https://registry.npm.taobao.org

# 或者使用腾讯npm镜像
npm config set registry http://mirrors.cloud.tencent.com/npm/

nvm安装

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash

# 安装
# 或者阿里镜像
NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node nvm install 14

# 使用华为镜像地址安装12版本nodejs
NVM_NODEJS_ORG_MIRROR=https://mirrors.huaweicloud.com/nodejs/ nvm install 14

# 或者使用腾讯镜像
# 安装似乎有点问题
NVM_NODEJS_ORG_MIRROR=https://mirrors.cloud.tencent.com/nodejs-release/ nvm install 14

# 卸载
nvm uninstall 14

# 切换版本
nvm use 14

最新版pm2安装:进程管理工具

官网:https://github.com/Unitech/pm2

# 安装或更新
npm install pm2 -g

# 更新或刷新pm2进程
pm2 update

# 独立安装版
wget -qO- https://getpm2.com/install.sh | bash

#--------pm2管理日志(pm2-logrotate)--------
pm2 install pm2-logrotate

# 查看配置
pm2 conf

pm2 set pm2-logrotate:max_size 10M # 单个日志文件的大小
pm2 set pm2-logrotate:retain 30 # 保留的日志文件个数
pm2 set pm2-logrotate:compress false # 是否通过gzip压缩日志
pm2 set pm2-logrotate:dateFormat YYYYMMDD # 日志格式 20210102
pm2 set pm2-logrotate:workerInterval 30
pm2 set pm2-logrotate:rotateInterval '* * 1 * *' # 每月1号进行分割
pm2 set pm2-logrotate:rotateModule true

较新版git

# ius版
yum install -y git224

vim8

curl -o /etc/yum.repos.d/vim8.repo https://copr.fedorainfracloud.org/coprs/lbiaggi/vim80-ligatures/repo/epel-7/lbiaggi-vim80-ligatures-epel-7.repo

yum -y remove vim-minimal vim-common vim-enhanced

yum install -y vim

docker

curl -o /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum install -y docker-ce

较新版redis

# ius版
yum install -y redis5

最新版MongoDB

# 安装mongodb源
echo -e "[mongodb-org]
name=MongoDB Repository
baseurl=https://mirrors.cloud.tencent.com/mongodb/yum/el7/
gpgcheck=0
enabled=1" > /etc/yum.repos.d/mongodb-org.repo

# 安装mongodb
yum install -y mongodb-org

最新版nginx

# 安装nginx源
echo -e "[nginx-stable]
name=nginx stable repo
baseurl=https://nginx.org/packages/centos/7Server/x86_64
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/rhel/7Server/x86_64
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true" > /etc/yum.repos.d/nginx.repo

# 安装nginx
yum install -y nginx

最新版fish

# 安装fish源
curl -o /etc/yum.repos.d/fish.repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/CentOS_8/shells:fish:release:3.repo

# rpm安装
rpm -ivh https://download.opensuse.org/repositories/shells:/fish:/release:/3/RHEL_7/x86_64/fish-3.1.2-1.8.x86_64.rpm

# 安装nginx
yum install -y fish

mysql源

# 注:打开网址找到对应版本 –> https://dev.mysql.com/downloads/repo/yum/
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

oracle-client

echo -e "[oracle-client]
name=oracle-client
baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64
gpgcheck=0" > /etc/yum.repos.d/oracle-client.repo

# 查找可安装版本
yum search oracle | grep plus

# 安装指定版本
yum -y install oracle-instantclient19.9-sqlplus

powershell源

curl -o /etc/yum.repos.d/microsoft.repo https://packages.microsoft.com/config/rhel/7/prod.repo

yum install -y powershell

# Start PowerShell
pwsh

linux-centos-tools

必装软件

yum -y install mlocate htop net-tools NetworkManager-tui vim firewalld axel tmux2

开发工具

yum -y groupinstall "Development Tools"

终端上传/下载文件

official websites: https://www.ohse.de/uwe/software/lrzsz.html
linux received zmodem & send zmodem

linux-centos-tools%2017f54a6705dd4907a0d37a7541e76016/Untitled.png

# 安装
yum install -y lrzsz

# 上传文件
rz

# 下载文件
sz

# zmodem上传速度: 600+KB/s

scp本地上传文件

# 本地上传到服务器
scp -r 目录 root@122.37.218.252:/data/download

# 远程到本地
scp root@122.37.218.252:/data/download C:\Users\Nolan\Documents\文件

安装或升级bash

curl -O http://ftp.gnu.org/gnu/bash/bash-5.1.tar.gz
tar xvf bash-5.1.tar.gz
cd bash-5.1
./configure&&make&&make install

# 重启linux
bash -version

# 虽然通过/bin/bash --version命令可以显示已经更新到最新版了,
# 但是$BASH_VERSION变量依旧还是老版本,我们还需要加入下面的软链接

mv /bin/bash /bin/bash.bak
ln -s /usr/local/bin/bash /bin/bash

多线程下载工具axel

yum -y install axel

# 开启8线程下载
axel -n 8 -a url

man帮助文档高亮

centos–>man–>手册–>高亮显示–配置–颜色–bash

echo -e "export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'" > ~/.bashrc && source .bashrc

查看磁盘剩余空间

df -hl:查看磁盘剩余空间
df -h:查看每个根路径的分区大小
du -sh [目录名]:返回该目录的大小
du -sm [文件夹]:返回该文件夹总M数
du -h [目录名]:查看指定文件夹下的所有文件大小(包含子文件夹)

重启网卡

systemctl restart network

不断更新中...

发表评论