CentOS-7服务器基础环境搭建

一、更换阿里云yum镜像

yum install -y wget
  • 1.备份本地yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak

2 获取阿里yum源配置文件

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  • 更新cache
yum makecache
  • 查看
yum -y update

二、基础工具安装

  • 安装netstat
yum install -y net-tools  lrzsz vim wget lsof

三、修改静态IP地址

vi /etc/sysconfig/network-scripts/ifcfg-eth0
  • 添加/修改如下配置
ONBOOT=yes
BOOTPROTO=static
NETMASK=255.255.255.0
IPADDR=192.168.0.163
GATEWAY=192.168.0.1
DNS1=114.114.114.114 
DNS2=8.8.8.8
  • 重启网卡服务
/etc/init.d/network restart
或使用命令:
service network restart

关闭防火墙

临时关闭防火墙命令。重启电脑后,无效
systemctl stop firewalld
永久关闭防火墙命令。重启后,有效。
systemctl disable firewalld
查看防火墙状态
systemctl status firewalld

修改主机名

hostnamectl set-hostname node01

设置主机间免密登录

ssh-keygen
ssh-copy-id [email protected]

yum安装nginx

  • 安装nginx的yum源
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
  • 安装Nginx
yum install -y nginx

安装Docker

  • 卸载旧版本
sudo yum remove docker \
                  docker-common \
                  docker-selinux \
                  docker-engine
  • 安装依赖的工具包
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
  • 安装Docker CE
sudo yum makecache fast

安装最新版本的Docker CE
sudo yum install docker-ce

安装指定版本,列出可用版本
yum list docker-ce.x86_64  --showduplicates | sort -r
安装
sudo yum install docker-ce-

  • 启动Docker
sudo systemctl start docker
sudo systemctl enable docker
  • 配置阿里云加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://n0st2wzy.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
  • 安装docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

自动补全工具:
 sudo curl -L https://raw.githubusercontent.com/docker/compose/1.26.2/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose

docker-compose文档
补全工具文档

你可能感兴趣的:(CentOS-7服务器基础环境搭建)