最全centos7安装docker镜像、mysql等工具

linux工具安装

1、固定IP

1、编辑enp0s3网卡,vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

2、

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
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="enp0s3"
UUID="79db9144-b845-4efc-89e8-efbd8784498b"
DEVICE="enp0s3"
ONBOOT="yes"
IPADDR=192.168.1.31
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=114.114.114.114
DNS2=8.8.8.8

3、service network restart 重启网络服务

2、git安装 

#yum install git
配置git命令
[root@localhost ~]# git config --global user.name "zhao"
[root@localhost ~]# git config --global user.email "[email protected]"
[root@localhost ~]# git config --global --list
user.name=zhao
[email protected]

3、docker安装

1、yum install -y yum-utils
2、设置镜像的仓库
#推荐使用国内的
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3、更新yum软件包索引
yum makecache fast
4、安装docker相关的 docker-ce 社区版 而ee是企业版
yum install docker-ce docker-ce-cli containerd.io # 这里我们使用社区版即可
5、开机启动
systemctl enable docker
6、启动docker
systemctl start docker
[root@localhost ~]# docker ps -a #查看docker进程
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@localhost ~]# ps -ef|grep docker#查看docker是否启动
root      1774     1  0 20:01 ?        00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root      1949  1546  0 20:16 pts/0    00:00:00 grep --color=auto docker
7、配置阿里云镜像:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://wbc9txqx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker 
8、测试docker安装成功
sudo docker run hello-world
9、移除
docker ps -a
docker rm "contaner id" 
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
90d1f0f6ae32   hello-world   "/hello"   7 seconds ago   Exited (0) 6 seconds ago             elastic_yonath
[root@localhost ~]# docker rm 90d1f0f6ae32
90d1f0f6ae32
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
10、安装docker-compose多个容器要启动
[root@localhost ~]#  curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m`> /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   423  100   423    0     0    207      0  0:00:02  0:00:02 --:--:--   207
100 16.2M  100 16.2M    0     0  57049      0  0:04:58  0:04:58 --:--:-- 3886k
[root@localhost ~]# sudo chmod +x /usr/local/bin/docker-compose #加可执行权限
[root@localhost ~]# docker-compose -v
docker-compose version 1.25.0, build 0a186604

 11、设置容器的自启动
 docker update --restart=always 容器名或者ID
 12、查看本地images
 [root@localhost ~]# docker images

4、安装mysql

下载镜像
docker pull mysql:5.7
查看镜像
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
mysql         5.7       c20987f18b13   3 months ago   448MB
hello-world   latest    feb5d9fea6a5   6 months ago   13.3kB
安装启动
[root@localhost ~]# docker run -p 3306:3306 --name mymysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
f4b5460fc1b258f161506fad3587ee7a7e08cfe10220c3cd916512df4ca720b6
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
f4b5460fc1b2   mysql:5.7   "docker-entrypoint.s…"   44 seconds ago   Up 42 seconds   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mymysql

[root@localhost ~]# docker logs f4b5460fc1b2 #查看报错日志
进入mysql容器
[root@localhost ~]# docker exec -it f4b5460fc1b2 /bin/bash
root@f4b5460fc1b2:/# mysql -uroot -p123456   #进入容器
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; #授权
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY 'root' WITH GRANT OPTION;  #授权
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'root' WITH GRANT OPTION; #授权
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit #退出mysql
Bye
root@f4b5460fc1b2:/# exit #退出容器
exit
[root@localhost ~]# 

5、安装python

1、安装依赖包
[root@localhost ~]# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel splite-devel gcc gcc-c++ openssl-devel libffi-devel python-devel mariadb-devel
2、拉取python镜像
docker pull python
3. 下载完成之后查看镜像
docker images
4. 运行python镜像
docker run -itd python:latest bash
5. 进入容器
docker exec -it 6a55 bash # 6a55是docker ps查看python镜像启动后获得的容器id,可以取完整的容器id
6. 查看python的版本
python -V

6、安装python虚拟环境

win10 
pip install virtualvwrapper-win
linux
1、yum install python-setuptools python-devel
2、curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py
3、pip3 install virtualenverapper
[root@localhost ~]# pip3 install virtualenverapper -i https://pypi.douban.com/simple

7、安装go

win10设置环境变量
C:\Users\90760>go env -w GOPROXY=https://goproxy.io,direct

C:\Users\90760>go env -w GO111MODULE=on
linux安装go
wget https://dl.google.com/go/go1.18.linux-amd64.tar.gz
减压:
tar -xvf go1.18.linux-amd64.tar.gz
[root@localhost ~]# cd go
[root@localhost go]# pwd
/root/go
[root@localhost go]# vim ~/.bashrc
增加如下环境变量配置
export GOROOT=/root/go
export GOPATH=/root/projects/go
export PATH=$PATH:$GOROOT/bin:$GPPATH/bin
[root@localhost go]# source ~/.bashrc #更新文件
修复命令失效:ls not command found
[root@localhost ~]# export PATH=/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
设置加速代理:
[root@localhost go]# go env -w GOPROXY=https://goproxy.io,direct
[root@localhost go]# go env -w GO111MODULE=on
[root@localhost go]# go env

8、node.js安装

win10
使用淘宝镜像cnpm替代npm(解决npm慢)
npm install -g cnpm --registry=https://registry.npm.taobao.org
liunx安装
wget https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-x64.tar.xz
减压:[root@localhost go]# tar -xvf node-v16.14.2-linux-x64.tar.xz
配置软连接
[root@localhost node-v16.14.2-linux-x64]# cd ..
[root@localhost go]# ln -s /root/node-v16.14.2-linux-x64/bin/node /usr/bin/node
[root@localhost go]# ln -s /root/node-v16.14.2-linux-x64/bin/bin/npm /usr/bin/npm

9、安装YApi

文档:https://github.com/Ryan-Miao/docker-yapi
1、初始化db, 开启自定义配置
    git clone https://github.com/Ryan-Miao/docker-yapi.git
    cd docker-yapi
    docker-compose up
    
报错解决方案:Error: Cannot find module '/my-yapi/vendors/server/app.js’
 问题已解决,处理步骤如下:
1.路径:vim  root/dokcer-yapi/docker-compose.yml 
2. 去掉#号 command: "yapi server",
3.给命令 command: "node /my-yapi/vendors/server/app.js" 这个前面加#号
3.再去执行:docker-compose up
4.访问IP:9090
5.设置完成后页面信息后,再按照老师的教程继续

访问:http://192.168.1.25:9090/
配置:数据库地址mongo
数据库认证:数据库用户名:yapi
           数据库密码:yapi123456

10、安装redis

命令:[root@localhost ~]# docker run -p 6379:6379 -d redis:latest redis-server
开机自启:[root@localhost ~]# docker update --restart=always 7da11a612255
文档地址:github.com/go-redis/redis 

11、安装consul

安装:[root@localhost ~]# docker run -d -p 8500:8500 -p 8300:8300 -p 8301:8301 -p 8302:8302 -p 8600:8600/udp consul consul agent -dev -client=0.0.0.0
开机自启:[root@localhost ~]# docker update --restart=always 34426980fbb4
注册服务文档:https://www.consul.io/api-docs/agent/service#register-service
删除服务文档:https://www.consul.io/api-docs/agent/service#deregister-service
检查服务文档:https://www.consul.io/api-docs/agent/check
获取多个服务实例:https://www.consul.io/api-docs/agent/check#list-checks

12、nacos配置中心

文档:https://nacos.io/zh-cn/docs/quick-start-docker.html
安装:docker run --name nacos-standalone -e MODE=standalone -e JVM_XMS=512m -e JVM_XMX=512m -e JVM_XMN=256m -p 8848:8848 -d nacos/nacos-server:latest
开机自启:[root@localhost ~]# docker update --restart=always 8bff09fa5f10
启动访问地址:http://192.168.1.26:8848/nacos/index.html#/login  用户:nacos 密码nacos
报错:docker: write /var/lib/docker/tmp/GetImageBlob094890934: no space left on device. 空间不足

[root@localhost ~]# docker system df #查看剩余空间
[root@localhost ~]# docker images   #查看镜像
[root@localhost ~]# docker rmi feb5d9fea6a5 #移除

13、安装jenkins

安装java
yum install java-1.8.0-openjdk* -y
下载jenkins
wget https://mxshop-files.oss-cn-hangzhou.aliyuncs.com/jenkins-2.284-1.1.noarch.rpm

14、kong安装

安装postgresql
docker run -d --name kong-database \
-p 5432:5432 \
-e "POSTGRES_USER=kong" \
-e "POSTGRES_DB=kong" \
-e "POSTGRES_PASSWORD=kong" \
-e "POSTGRES_DB=kong" postgres:12

初始化表
docker run --rm --network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HSOT=192.168.1.31" \
-e "KONG_PG_PASSWORD=kong" \
-e "POSTGRES_USER=kong" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
 kong:latest kong migrations bootstrap

 安装kong 
yum install -y https://bintray.com/kong/kong-rpm/download_file?file_path=centos/7/kong-2.1.0.el7.amd64.rpm
yum install -y https://jfrog.com/distribution/?bintrayRD=1&file_path=centos/7/kong-2.1.0.el7.amd64.rpm


docker run --rm --network=kong-net \
  -e "KONG_DATABASE=postgres" \
  -e "KONG_PG_HOST=kong-database" \
  -e "KONG_PG_PASSWORD=kong" \
  -e "KONG_PASSWORD=kong" \
 kong/kong-gateway:2.8.1.1-alpine kong migrations bootstrap

15、关闭centos7 防火墙

1、一定要关闭防火墙!
    systemctl stop firewalld.service
2、重启docker
    systemctl restart docker

16、docker安装rocketMQ

#1. cd到目录之下
docker-compose up
docker update --restart=always 760fec5cb382 #开机自启
http://192.168.1.31:8080/#/  访问地址
配置外网地址:
^CGracefully stopping... (press Ctrl+C again to force)
Stopping rmqconsole ... done
Stopping rmqbroker  ... done
Stopping rmqnamesrv ... done
[root@localhost install]# ls
conf  docker-compose.yml  logs  README.md  store
[root@localhost install]# cd conf
[root@localhost conf]# ls
broker.conf
[root@localhost conf]# vim broker.conf          #192.168.1.31
[root@localhost conf]#

17、kubernetes相关配置

[root@localhost ~]# cat /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=
gpgcheck=
repo_gpgcheck=
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

yum install -y kubectl-1.14. kubelet-1.14. kubernetes-cni-1.14. kubeadm-1.14.0
systemctl enable kubelet #开机启动

设置docker Cgroup Driver为systemd,达到与kubelet相一致的要求
cat > /etc/docker/daemon.json <

你可能感兴趣的:(docker,docker,linux,运维)