Basic environment installation configuration, dockerfile configuration and use of k8s series (1)

1. Based on the fact that most of the current production environments are centos systems, all cases in this article use centos7.6 and above as the basic environment. For server systems, please refer to: Or directly use cloud hosts. Microservice architecture (1) Simple server virtual framework selection Type and installation_Non-biological linguist’s blog-CSDN blog 1. Simple server virtual framework selection 1.esxi virtual framework: does not support too old server network cards, you need to download the official VMware-PowerCLI-xxx and ESXi-Customizer- PS and related network card driver packages encapsulate iso by themselves. 2. Use Proxmox VE as the underlying system. The specific operations are as follows: Connect to the Internet https://www.proxmox.com/en/downloads to download the relevant iso, make a boot installation system, upload the iso file of centos to the local data center, and configure it according to actual needs. Virtual machine (can only... https://blog.csdn.net/qq_29653373/article/details/115406632?spm=1001.2014.3001.5502

2. Docker environment setup

1. Static IP configuration

# 进入网卡配置目录查看你所有的网卡
[root@VM-12-6-centos ~]# cd /etc/sysconfig/network-scripts/
# 编辑你的网卡配置 我的是 ifcfg-eth0 
[root@VM-12-6-centos network-scripts]# vi ifcfg-eth0
#将配置信息改为如下配置(红色部分根据实际情况更改,改完之后重启网卡:service network restart)

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=
static
IPADDR=192.168.1.22
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.1
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
DEVICE=ens33
ONBOOT=yes

2. Basic configuration

# 关闭selinux
[root@VM-12-6-centos ~]# setenforce 0
[root@VM-12-6-centos ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 注意:修改 selinux 配置文件之后,重启机器,selinux才能永久生效看到 Disabled说明selinux成功关闭
[root@VM-12-6-centos ~]# getenforce
# 配置主机名:
[root@VM-12-6-centos ~]# hostnamectl set-hostname morik22
[root@VM-12-6-centos ~]# bash
# 关闭防火墙
[root@VM-12-6-centos ~]# systemctl stop firewalld && systemctl disable firewalld
# 配置时间同步
[root@VM-12-6-centos ~]# yum install -y ntp ntpdate
[root@VM-12-6-centos ~]# ntpdate cn.pool.ntp.org
# 编写计划任务(加入计划配置:* */1 * * * /usr/sbin/ntpdate cn.pool.ntp.org)
[root@VM-12-6-centos ~]# crontab -e
# 重启 crond 服务使配置生效:
[root@VM-12-6-centos ~]# systemctl restart crond

 3. Docker installation and configuration

# 配置 docker-ce 国内 yum 源(阿里云)
[r[root@VM-12-6-centos ~]# yum -y install yum-utils
[root@VM-12-6-centos ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 基础工具包安装
[root@VM-12-6-centos ~]# yum install -y wget net-tools nfs-utils lrzsz gcc gcc-c++ make cmake libxml2-devel openssl-devel curl curl-devel unzip sudo ntp libaio-devel wget vim ncurses-devel autoconf automake zlib-devel python-devel epel-release openssh-server socat ipvsadm conntrack
# 安装启动查看docker状态
[root@VM-12-6-centos ~]# yum install docker-ce-20.10.17 -y
[root@VM-12-6-centos ~]# systemctl start docker && systemctl enable docker
[root@VM-12-6-centos ~]# docker version
[root@VM-12-6-centos ~]# systemctl status docker
# 开启br_netfilter内核参数需要转发,br_netfilter模块用于将桥接流量转发至iptables
[root@VM-12-6-centos ~]# modprobe br_netfilter
[root@VM-12-6-centos ~]# cat > /etc/sysctl.d/docker.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
[root@VM-12-6-centos ~]# sysctl -p /etc/sysctl.d/docker.conf
# 配置镜像加速器
[root@VM-12-6-centos ~]# tee /etc/docker/daemon.json << 'EOF'
{"registry-mirrors":["https://rsbud4vc.mirror.aliyuncs.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn","https://dockerhub.azk8s.cn","http://hub-mirror.c.163.com","http://qtid6917.mirror.aliyuncs.com","https://e9yneuy4.mirror.aliyuncs.com","https://rncxm540.mirror.aliyuncs.com"]}
EOF
[root@VM-12-6-centos ~]# sudo systemctl daemon-reload && sudo systemctl restart docker


3. Basic configuration and use of DockerFile

1. Create the dockerfile configuration file of nginx. The file name is usually called dockerfile.

# Nginx基础依赖
FROM centos     
# 作者信息 不必要
MAINTAINER umf-morik
# 执行删除yum源配置命令
RUN rm -rf /etc/yum.repos.d/*
# 执行物理机文件拷贝到docker容器命令
COPY Centos-vault-8.5.2111.repo /etc/yum.repos.d/
# 执行安装wget下载工具命令
RUN yum install wget -y
# 执行安装Nginx命令
RUN yum install nginx -y
# 拷贝物理机首页到容器的nginx根映射目录下
COPY index.html /usr/share/nginx/html/
# 容器暴露向外交互的端口
EXPOSE 80
# nginx启动组合命令
RUN echo "daemon off;">>/usr/local/nginx/conf/nginx.conf  # 配置追加deamon,官网要求,不然启动异常
ENTRYPOINT ["/usr/sbin/nginx", "-c"]                      # 定参
CMD ["/etc/nginx/nginx.conf"]                             # 变参

2. Build, start and other image operations

# -f 可以指定dockerfile的文件名默认为dockerfile可以省略。morik/nginx镜像名,v1 tag标记,后边的.不可省略
[root@VM-12-6-centos ~]# docker build -t morik/nginx:v1 .
# 查看镜像
[root@VM-12-6-centos ~]# docker images | grep nginx
# 启动容器
[root@VM-12-6-centos ~]# docker run -dit -p 30180:80 --name mynginx morik/nginx:v1
# 进入容器内部
[root@VM-12-6-centos ~]# docker exec -it mynginx /bin/bash
# 查看容器运行情况
[root@VM-12-6-centos ~]# docker ps | grep mynginx 

3. Tomcat’s dockerfile configuration reference

FROM centos
MAINTAINER umf-morik
RUN rm -rf /etc/yum.repos.d/*
COPY Centos-vault-8.5.2111.repo /etc/yum.repos.d/
RUN yum install wget -y
# 解压并拷贝rpm文件
ADD jdk-8u45-linux-x64.rpm /usr/local/
ADD apache-tomcat-8.0.26.tar.gz /usr/local/
RUN cd /usr/local && rpm -ivh jdk-8u45-linux-x64.rpm
RUN mv /usr/local/apache-tomcat-8.0.26 /usr/local/tomcat8
EXPOSE 8080
# 启动命令 tail 循环让容器一直在运行,如果不加,容器就会自动退出
ENTRYPOINT /usr/local/tomcat8/bin/startup.sh && tail -F 
/usr/local/tomcat8/logs/catalina.out

4. Apache dockerfile reference

FROM centos
MAINTAINER xuegod-IT
RUN rm -rf /etc/yum.repos.d/*
COPY Centos-vault-8.5.2111.repo /etc/yum.repos.d/
RUN yum -y install httpd
ADD template /var/www/html/
ADD run.sh /run.sh
RUN chmod 755 /run.sh
EXPOSE 80
CMD ["/run.sh"]

4. Remarks:

Centos-vault-8.5.2111.repo download address required for text: centos8 yum source-Linux document resources-CSDN download

Other required packages can be downloaded from their respective official websites. 

Guess you like

Origin blog.csdn.net/qq_29653373/article/details/125865146