linux-基础环境安装

171 阅读2分钟

1.基础环境

1.1、yum源配置

使用阿里云安装源

cd /etc/yum.repos.d
rename .repo .repo.bak *.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

curl -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all 
yum makecache 
yum repolist
yum update

安装基本工具

############ 安装基础工具 ############
yum -y install wget telnet bind-utils vim net-tools lrzs

1.2、修改系统设置

修改主机名

注意hostname不能是localhost,且不包含下划线、小数点、大写字母,命令语法为:

sudo hostnamectl set-hostname test

修改系统参数

############ limits 相关 ############
# 扩大句柄数
sed -i 's/4096/1000000/g' /etc/security/limits.d/20-nproc.conf
cat <<EOF>> /etc/security/limits.d/20-all-users.conf
*               soft    nproc          1000000
*               hard    nproc          1000000
*               soft    nofile         1000000
*               hard    nofile         1000000
EOF


############ 内核参数 ############
cat <<'EOF'> /etc/sysctl.d/50-custom.conf 
# 禁用IPV6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
# 最大进程数量
kernel.pid_max = 1048576
# 进程可以拥有的VMA(虚拟内存区域)的数量
vm.max_map_count = 262144
#关闭tcp的连接传输的慢启动,即先休止一段时间,再初始化拥塞窗口。
net.ipv4.tcp_slow_start_after_idle = 0
# 哈希表项最大值,解决 'nf_conntrack: table full, dropping packet.' 问题
net.netfilter.nf_conntrack_max = 2097152
# 在指定之间(秒)内,已经建立的连接如果没有活动,则通过iptables进行清除。
net.netfilter.nf_conntrack_tcp_timeout_established = 1200
EOF


############ 关闭selinux ############
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
setenforce 0


############ 关闭防火墙 ############
systemctl disable firewalld
systemctl stop firewalld


########## 设置时间同步服务器 ##########
查看我的其他文章

systemctl enable chronyd.service
systemctl restart chronyd.service
systemctl status chronyd.service
#查看时间同步源:
chronyc sources -v

1.3、docker安装

1.Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。

通过 uname -r 命令查看你当前的内核版本

$ uname -r

2.使用 root 权限登录 Centos。确保 yum 包更新到最新。

$ sudo yum update

3.检查系统中是否已经安装了docker

$ ps -ef |grep docker

4.如果显示已安装docker的需要先卸载

$ yum remove docker-*

5.安装yum仓库管理工具

$ yum install -y yum-utils  (该工具包含yum-config-manager)

6.下载阿里的docker-ce仓库

$ cd /etc/yum.repos.d/
$ yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

7.查看选择docker-ce各版本

$ yum list docker-ce --showduplicates | sort -r

8.安装指定版本的docker-ce、docker-ce-cli、containerd.io

$ yum install docker-ce-19.03.5-3.el7 docker-ce-cli-19.03.5-3.el7 containerd.io-1.2.10-3.2.el7 -y

9.关闭防火墙
 
$ systemctl status firewalld 查看防火墙状态   systemctl disable firwalld  关闭防火墙

10.启动docker

$ systemctl start docker

11.设置docker开机启动

$ systemctl enable docker

1.4、docker-compose 安装

第一种直接安装

curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
其中版本号可以修改

第二种,离线安装

去github手动下载文件:https://github.com/docker/compose/releases/tag/1.25.0-rc4

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NK6Uyb0M-1627004817264)(http://docs.software.dc/images/markdown/mp-data/mp-data-deploy-doc/https:/img-blog.csdnimg.cn/20200313213255537.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FsZW5feGlhb3hpbg==,size_16,color_FFFFFF,t_70)]

将文件上传到/usr/local/bin/ 目录下,重命名为docker-compose,修改文件权限:

$ chmod +x /usr/local/bin/docker-compose
$ docker-compose -v 

1.5、docker配置

配置镜像仓库

在/etc/docker/daemon.json文件(没有请自行创建)

#配置阿里云相关的

$ sudo mkdir -p /etc/docker

$ touch /etc/docker/daemon.json  添加如下内容


sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://39kjotb7.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker