服务器初始化(01)
2023-07-05

centos篇

  1. 关闭防火墙

  2. 关闭selinux

  3. 修改yum源

  4. 增加第三方源(可选)

  5. 安装docker

  6. 安装git

1.关闭防火墙

firewall-cmd --state	    #查看防火墙状态
systemctl stop firewalld.service    	#停止firewall
systemctl disable firewalld.service    	#禁止firewall开机启动

2.关闭selinux

getenforce	#查看selinux状态
setenforce 0	#临时关闭selinux
sed -i 's/^ *SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config	#永久关闭(需重启系统)

3.修改yum源

cd /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo  #默认使用阿里云的yum源
yum makecache
yum update -y

4.增加第三方源(可选)

描述:centos官方推荐第三方源RepoForge,有些软件没有在 官方repo中添加

rpm --import https://mirrors.aliyun.com/repoforge/RPM-GPG-KEY.dag.txt
sudo cat > /etc/yum.repos.d/rpmforge.repo << EOF
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = https://mirrors.aliyun.com/repoforge/redhat/el7/en/$basearch/rpmforge
mirrorlist = http://mirrorlist.repoforge.org/el7/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
[rpmforge-extras]
name = RHEL $releasever - RPMforge.net - extras
baseurl = https://mirrors.aliyun.com/repoforge/redhat/el7/en/$basearch/extras
mirrorlist = http://mirrorlist.repoforge.org/el7/mirrors-rpmforge-extras
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
[rpmforge-testing]
name = RHEL $releasever - RPMforge.net - testing
baseurl = https://mirrors.aliyun.com/repoforge/redhat/el7/en/$basearch/testing
mirrorlist = http://mirrorlist.repoforge.org/el7/mirrors-rpmforge-testing
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
EOF
yum makecache
yum update -y

5.安装docker

相关链接:https://docs.docker.com/engine/install/centos/

curl -fsSL "https://get.docker.com/" | sh
sudo cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": [
    "https://dockerhub.azk8s.cn",
    "https://docker.mirrors.ustc.edu.cn",
    "http://hub-mirror.c.163.com"
  ],
  "max-concurrent-downloads": 10,
  "max-concurrent-uploads": 10,
  "log-driver": "json-file",
  "log-level": "warn",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
    },
  "data-root": "/data/docker"  //docker数据的存储位置
}
EOF
systemctl daemon-reload
systemctl restart docker

安装docker-compose

curl -SL https://ghproxy.com/https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

6.安装git

yum install -y git