新服务器配置-CentOS篇

简介

CentOS系统的版本很稳定(不怎么更新😂),基本市面上安装的都是7.x版本(当前时间2021/04/23最流行的7.6、7.7),所以本文的以7.6为准。

如何察看系统版本

cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

需要安装的内容:

  • zsh及oh-my-zsh 超好用的终端,及超方便的配置
  • Mysql
  • Redis
  • Nginx(系统可能自带?)

linux自带yum做为安装器

yum 基本使用方法

yum install xxxx # 安装 xxx 软件
yum remove xxx # 卸载 xxx 软件

后面可以带参数-y : 全程yes

yum install xxx -y # 一路yes安装

安装

安装zsh及oh-my-zsh

安装基本

  1. 查看Sheel的命令
echo $SHELL #查看默认shell

cat /etc/shells #看有哪些Shell

chsh -s /bin/zsh #切换Shell

  1. 安装zsh
sudo yum install -y zsh

如果慢,切换Yum源到aliyun

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

安装完成切换Shell

chsh -s /bin/zsh #切换Shell
  1. 先安装git
sudo yum install -y git
  1. 安装oh-my-zsh
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh

如果没法连通(connection refused),使用如下

git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

安装常用插件

  • 历史命令提示插件
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
  • 安装高亮插件
git clone git://github.com/zsh-users/zsh-syntax-highlighting $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

修改.zshrc

在文件里找到plugins,修改为

plugins=(
  git
  zsh-autosuggestions
  zsh-syntax-highlighting
)

生效配置

source .zshrc

其他问题

###sh-autosuggestions补全颜色不对

Terminal设置里Terminal没有设置成支持256色。如果没法选择可以把zsh的这个插件设置成其他颜色

重新设置下颜色

.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

修改内容为:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=yellow'

安装Mysql

主要是因为mysql被收购,centOS再使用会有法律纠纷可以知乎CentOS 7为什么放弃了MySQL,而改使用MariaDB?

1. 使用MariaDB替代mysql

yum install mariadb-server -y #如果已安装可以省略
systemctl start mariadb.service #启动服务
systemctl enable mariadb.service #开机启动服务

2. 我就要安装mysql

安装mysql


安装Redis

[引用到其他文件]


安装Nginx

[引用到其他文件]


CentOS7防火墙

# 查看防火墙状态:
systemctl status firewalld.service
#           绿的running表示防火墙开启

# 执行关闭命令:
systemctl stop firewalld.service

# 再次执行查看防火墙命令:
systemctl status firewalld.service

# 执行开机禁用防火墙自启命令:
systemctl disable firewalld.service

# 启动:
systemctl start firewalld.service

# 防火墙随系统开启启动:
systemctl enable firewalld.service

评论