Docker集群
发布于:2019-1-30 15:28 作者:admin 浏览:2368 分类:系统架构[root@localhost docker]# docker swarm init Swarm initialized: current node (vgc6172h94lo7vktpxs9hnb1y) is now a manager. To add a worker to this swarm, run the following command: docker swarm join \ --token SWMTKN-1-0dpoajwlnlig2pvbujiqzogodwilx6fezg7rgpjfsvob49vnzl-1lq8jjz0hqvcmd2ay91ornac6 \ 192.168.100.136:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions. [root@localhost docker]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS vgc6172h94lo7vktpxs9hnb1y * localhost.localdomain Ready Active Leader [root@localhost docker]# docker service create --name nginx --publish 80:80 --replicas 3 docker.io/idiswy/lnmp td9afve2mqcs4l6t0w4dro8ve [root@localhost docker]# docker service ls ID NAME MODE REPLICAS IMAGE td9afve2mqcs nginx replicated 3/3 docker.io/idiswy/lnmp:latest [root@localhost docker]# docker service ps nginx ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS tnwlid5v447j nginx.1 docker.io/idiswy/lnmp:latest localhost.localdomain Running Running about a minute ago f1h4cenjlj06 nginx.2 docker.io/idiswy/lnmp:latest localhost.localdomain Running Running about a minute ago k6m7nqosffna nginx.3 docker.io/idiswy/lnmp:latest localhost.localdomain Running Running about a minute ago [root@localhost docker]# docker service scale nginx=6 nginx scaled to 6 [root@localhost docker]# docker service ps nginx ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS tnwlid5v447j nginx.1 docker.io/idiswy/lnmp:latest localhost.localdomain Running Running 2 minutes ago f1h4cenjlj06 nginx.2 docker.io/idiswy/lnmp:latest localhost.localdomain Running Running 2 minutes ago k6m7nqosffna nginx.3 docker.io/idiswy/lnmp:latest localhost.localdomain Running Running 2 minutes ago mxx8konbil7u nginx.4 docker.io/idiswy/lnmp:latest localhost.localdomain Running Running 20 seconds ago v6hw4wkm1mf5 nginx.5 docker.io/idiswy/lnmp:latest localhost.localdomain Running Running 20 seconds ago 7mjvtqhxdiqm nginx.6 docker.io/idiswy/lnmp:latest localhost.localdomain Running Running 20 seconds ago [root@localhost docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 25eb9d5a1a49 docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656 "/sbin/my_init" About a minute ago Up About a minute 80/tcp, 443/tcp nginx.5.v6hw4wkm1mf5cjvf82vet2f4w 0a1654460e59 docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656 "/sbin/my_init" About a minute ago Up About a minute 80/tcp, 443/tcp nginx.6.7mjvtqhxdiqm3bxwqmeepo0sh ecba5be3df16 docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656 "/sbin/my_init" About a minute ago Up About a minute 80/tcp, 443/tcp nginx.4.mxx8konbil7uq0c9kydos5hei 148735b9e91b docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656 "/sbin/my_init" 3 minutes ago Up 3 minutes 80/tcp, 443/tcp nginx.2.f1h4cenjlj064nfmkyddufze0 dafd4c20c955 docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656 "/sbin/my_init" 3 minutes ago Up 3 minutes 80/tcp, 443/tcp nginx.3.k6m7nqosffnayodp1qjph7o02 020f1099d809 docker.io/idiswy/lnmp@sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656 "/sbin/my_init" 3 minutes ago Up 3 minutes 80/tcp, 443/tcp nginx.1.tnwlid5v447jl61kh8ukg8eob
CentOS构建Docker2
发布于:2019-1-30 9:03 作者:admin 浏览:2184 分类:系统架构查看版本 [root@localhost ~]# docker version Client: Version: 1.13.1 API version: 1.26 Package version: docker-1.13.1-88.git07f3374.el7.centos.x86_64 Go version: go1.9.4 Git commit: 07f3374/1.13.1 Built: Fri Dec 7 16:13:51 2018 OS/Arch: linux/amd64 Server: Version: 1.13.1 API version: 1.26 (minimum version 1.12) Package version: docker-1.13.1-88.git07f3374.el7.centos.x86_64 Go version: go1.9.4 Git commit: 07f3374/1.13.1 Built: Fri Dec 7 16:13:51 2018 OS/Arch: linux/amd64 Experimental: false 搜索容器镜像 [root@localhost ~]# docker search centos INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/centos The official build of CentOS. 5147 [OK] docker.io docker.io/ansible/centos7-ansible Ansible on Centos7 119 [OK] docker.io docker.io/jdeathe/centos-ssh CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x... 106 [OK] docker.io docker.io/consol/centos-xfce-vnc Centos container with "headless" VNC sessi... 78 [OK] docker.io docker.io/imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 50 [OK] docker.io docker.io/centos/mysql-57-centos7 MySQL 5.7 SQL database server 45 docker.io docker.io/tutum/centos Simple CentOS docker image with SSH access 43 docker.io docker.io/openshift/base-centos7 A Centos7 derived base image for Source-To... 39 docker.io docker.io/gluster/gluster-centos Official GlusterFS Image [ CentOS-7 + Glu... 38 [OK] docker.io docker.io/centos/postgresql-96-centos7 PostgreSQL is an advanced Object-Relationa... 37 docker.io docker.io/centos/python-35-centos7 Platform for building and running Python 3... 33 docker.io docker.io/kinogmt/centos-ssh CentOS with SSH 25 [OK] docker.io docker.io/openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use... 20 docker.io docker.io/centos/php-56-centos7 Platform for building and running PHP 5.6 ... 19 docker.io docker.io/pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag nam... 10 docker.io docker.io/openshift/wildfly-101-centos7 A Centos7 based WildFly v10.1 image for us... 6 docker.io docker.io/openshift/jenkins-1-centos7 DEPRECATED: A Centos7 based Jenkins v1.x i... 4 docker.io docker.io/darksheer/centos Base Centos Image -- Updated hourly 3 [OK] docker.io docker.io/pivotaldata/centos Base centos, freshened up a little with a ... 2 docker.io docker.io/pivotaldata/centos-mingw Using the mingw toolchain to cross-compile... 2 docker.io docker.io/blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK] docker.io docker.io/pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated ... 1 docker.io docker.io/pivotaldata/centos7-build CentosOS 7 image for GPDB compilation 0 docker.io docker.io/pivotaldata/centos7-test CentosOS 7 image for GPDB testing 0 docker.io docker.io/smartentry/centos centos with smartentry 0 [OK] 下载容器镜像 [root@localhost ~]# docker pull docker.io/centos Using default tag: latest Trying to pull repository docker.io/library/centos ... latest: Pulling from docker.io/library/centos 5e6ec7f28fb7: Pull complete 566e675a8212: Pull complete ef5a8026039b: Pull complete 22ecb0106557: Pull complete 91cc511c603e: Pull complete Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426 Status: Downloaded newer image for docker.io/centos:latest 查看容器镜像 [root@localhost ~]# docker images centos REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/centos latest 1e1148e4cc2c 7 weeks ago 202 MB 运行容器镜像 [root@localhost ~]# docker run centos echo "Hello Centos" Hello Centos 命令行运行容器镜像 [root@localhost ~]# docker run -t -i centos /bin/bash [root@4bf88ec1e25e /]# echo "Hello Centos" Hello Centos 保存对容器的修改 [root@localhost ~]# docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4bf88ec1e25e centos "/bin/bash" About a minute ago Exited (0) 5 seconds ago mystifying_kilby [root@localhost ~]# docker commit -m="Hello Centos" 4bf88ec1e25e hellocentos sha256:05c7c5c8c6f1ef66736cd1c6256cdd94629263ff67375e78e040e34dce2fb548 检查运行中的镜像 [root@localhost ~]# docker run hellocentos echo "Hello Centos" WARNING: IPv4 forwarding is disabled. Networking will not work. Hello Centos [root@localhost ~]# docker inspect hellocentos [ { "Id": "sha256:05c7c5c8c6f1ef66736cd1c6256cdd94629263ff67375e78e040e34dce2fb548", "RepoTags": [ "hellocentos:latest" ], "RepoDigests": [], "Parent": "sha256:1e1148e4cc2c148c6890a18e3b2d2dde41a6745ceb4e5fe94a923d811bf82ddb", "Comment": "Hello Centos", "Created": "2019-01-29T02:15:06.601658579Z", "Container": "4bf88ec1e25ebb0b91dd80fce5e26138c8f955f4edeb6c778422af65a66c7b6d", "ContainerConfig": { "Hostname": "4bf88ec1e25e", "Domainname": "", "User": "", "AttachStdin": true, "AttachStdout": true, "AttachStderr": true, "Tty": true, "OpenStdin": true, "StdinOnce": true, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/bash" ], "Image": "centos", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.label-schema.build-date": "20181205", "org.label-schema.license": "GPLv2", "org.label-schema.name": "CentOS Base Image", "org.label-schema.schema-version": "1.0", "org.label-schema.vendor": "CentOS" } }, "DockerVersion": "1.13.1", "Author": "", "Config": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "Cmd": [ "/bin/bash" ], "Image": "", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.label-schema.build-date": "20181205", "org.label-schema.license": "GPLv2", "org.label-schema.name": "CentOS Base Image", "org.label-schema.schema-version": "1.0", "org.label-schema.vendor": "CentOS" } }, "Architecture": "amd64", "Os": "linux", "Size": 201779629, "VirtualSize": 201779629, "GraphDriver": { "Name": "overlay2", "Data": { "LowerDir": "/var/lib/docker/overlay2/2e17ffe2a2acae3ca7b05851e5b2a8f4858bdec98b9ffeddaff1416851167d83/diff", "MergedDir": "/var/lib/docker/overlay2/6cbdbc6d1560ec1fe0b608e1dc80dcb4088cebbbbe77d7e269ac13732c711a00/merged", "UpperDir": "/var/lib/docker/overlay2/6cbdbc6d1560ec1fe0b608e1dc80dcb4088cebbbbe77d7e269ac13732c711a00/diff", "WorkDir": "/var/lib/docker/overlay2/6cbdbc6d1560ec1fe0b608e1dc80dcb4088cebbbbe77d7e269ac13732c711a00/work" } }, "RootFS": { "Type": "layers", "Layers": [ "sha256:071d8bd765171080d01682844524be57ac9883e53079b6ac66707e192ea25956", "sha256:e0a311bc74f5b5421dc5c135921dece63824e1cce9e5f5717d07878315d3728a" ] } } ] 发布自己的镜像 [root@localhost ~]# docker commit -m "my centos" 4bf88ec1e25e wangcnc2005/centos sha256:4a3a837b38d77a5024b22cf0265f69eef7a3b3ccb32c2f2c7ca3c5d52edb2320 [root@localhost ~]# docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: wangcnc2005 Password: Login Succeeded [root@localhost ~]# docker push wangcnc2005/centos:latest The push refers to a repository [docker.io/wangcnc2005/centos] e0a311bc74f5: Pushed 071d8bd76517: Pushed latest: digest: sha256:704978e57bd5486f145467a3ab314434bc02041a0f1aae137f43a5c81aea2506 size: 736 [root@localhost ~]# docker search wangcnc2005 INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/wangcnc2005/centos my centos 0 容器的删除 [root@localhost ~]# docker commit -m="Hello Centos" 4bf88ec1e25e hello_centos sha256:3e99e17de7d4de201482f97635780ad7872cea5a8ce5a1a70312ce4cd330cf40 [root@localhost ~]# docker images|grep centos hello_centos latest 3e99e17de7d4 5 seconds ago 202 MB hellocentos latest 05c7c5c8c6f1 21 hours ago 202 MB docker.io/centos latest 1e1148e4cc2c 7 weeks ago 202 MB [root@localhost ~]# docker rmi hello_centos Untagged: hello_centos:latest Deleted: sha256:3e99e17de7d4de201482f97635780ad7872cea5a8ce5a1a70312ce4cd330cf40 [root@localhost ~]# docker images|grep centos REPOSITORY TAG IMAGE ID CREATED SIZE hellocentos latest 05c7c5c8c6f1 21 hours ago 202 MB docker.io/centos latest 1e1148e4cc2c 7 weeks ago 202 MB
CentOS构建Docker
发布于:2019-1-25 10:08 作者:admin 浏览:2403 分类:系统架构1.安装 [root@localhost test]# yum install docker 2.启动docker [root@localhost test]# systemctl start docker 3.运行hello-world [root@localhost test]# docker run hello-world Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/ 4.Docker 以 ubuntu15.10 镜像创建一个新容器,然后在容器里执行 bin/echo "Hello world",然后输出结果 [root@localhost test]#docker run ubuntu:15.10 /bin/echo "Hello world" Hello world 5.通过docker的两个参数 -i -t,让docker运行的容器实现"对话"的能力 [root@localhost test]# docker run -i -t ubuntu:15.10 /bin/bash root@8b6cdcd4f1bb:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var 6.后台模式运行命令 [root@localhost test]# docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done" 1472118a21aa6d4931b108f75f2d4b3fadefe6bd2e89317245f3a9b1f286930e [root@localhost test]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1472118a21aa ubuntu:15.10 "/bin/sh -c 'while..." 2 minutes ago Up 2 minutes loving_montalcini [root@localhost test]# docker logs 1472118a21aa hello world hello world hello world hello world [root@localhost test]# docker stop 1472118a21aa 1472118a21aa [root@localhost test]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7.列出镜像列表 [root@localhost test]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/hello-world latest fce289e99eb9 3 weeks ago 1.84 kB docker.io/ubuntu 15.10 9b9cb95443b5 2 years ago 137 MB 8.搜索镜像 [root@localhost test]# docker search lnmp INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 50 [OK] docker.io docker.io/twang2218/lnmp-nginx 这是 LNMP 示例中的 nginx 镜像 16 [OK] docker.io docker.io/winstonpro/lnmp based on ubuntu 14.04 14 docker.io docker.io/maxwhale/ubuntu14-lnmp1.2 Ubuntu14.04 lnmp1.2 9 [OK] docker.io docker.io/dzer/lnmp lnmp环境 8 docker.io docker.io/domainer/centos-lnmp 5 [OK] docker.io docker.io/duckll/lnmp webservice 4 [OK] docker.io docker.io/maxwhale/lnmp-docker LNMP Docker 4 [OK] docker.io docker.io/evagle/lnmp ubuntu14.04 + nginx + mysql + php + redis 3 docker.io docker.io/idiswy/lnmp Ubuntu 16.04 + nginx 1.8.x + php7 + MySQL ... 3 docker.io docker.io/c21xdx/lnmp13_cen6 php5.4 1 [OK] docker.io docker.io/erguotou/docker-centos6-lnmp lnmp environment in centos6 1 [OK] docker.io docker.io/fbraz3/lnmp An easy-to-use LNMP/LEMP image, with Ubunt... 1 docker.io docker.io/gatherchou/docker-lnmp docker-lnmp 1 [OK] docker.io docker.io/inteye/lnmp LNMP1.2 (Linux, Nginx, Mysql, PHP). For de... 1 docker.io docker.io/turtlell/lnmp first lnmp demo 1 docker.io docker.io/twang2218/lnmp-php 这是 LNMP Docker 容器互联示例的 php 镜像 1 [OK] docker.io docker.io/zhaojianhui/lnmp LNMP环境 1 docker.io docker.io/dahaitech/lnmp-douyou douyou test lnmp 0 [OK] docker.io docker.io/huangguoji/lnmp lnmp.org的包 0 docker.io docker.io/jamesatwork/docker-lnmpwp A docker of LNMP & WordPress 0 [OK] docker.io docker.io/sixian67/lnmp this is my lnmp 0 docker.io docker.io/thinksvip/lnmp LNMP docker production environment 0 [OK] docker.io docker.io/twang2218/lnmp-mysql This is the MySQL image of the LNMP docker... 0 [OK] docker.io docker.io/zshtom/lnmp lnmp in centos 7 0 9.下载镜像 [root@localhost test]# docker pull docker.io/idiswy/lnmp Using default tag: latest Trying to pull repository docker.io/idiswy/lnmp ... latest: Pulling from docker.io/idiswy/lnmp f069f1d21059: Pull complete ecbeec5633cf: Pull complete ea6f18256d63: Pull complete 54bde7b02897: Pull complete a3ed95caeb02: Pull complete ce9e695a6234: Pull complete 346026b9659b: Pull complete 929099c3258a: Pull complete 064503d36445: Pull complete 4c1032a6f902: Pull complete 882f4453d31b: Pull complete Digest: sha256:ddb256e6834e5bd0dbaa0d9130ff94312ecdb1ae19669cc747e99620c4edd656 Status: Downloaded newer image for docker.io/idiswy/lnmp:latest [root@localhost test]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/hello-world latest fce289e99eb9 3 weeks ago 1.84 kB docker.io/idiswy/lnmp latest fbd7b7c5428e 2 years ago 335 MB docker.io/ubuntu 15.10 9b9cb95443b5 2 years ago 137 MB 10.从已经创建的容器中更新镜像,并且提交这个镜像 [root@localhost test]# docker run -t -i fbd7b7c5428e /bin/bash [root@e594c6c84c47:/sbin# apt-get update Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB] Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB] Get:3 http://archive.ubuntu.com/ubuntu xenial-security InRelease [109 kB] Get:4 http://archive.ubuntu.com/ubuntu xenial/main Sources [1103 kB] Get:5 http://archive.ubuntu.com/ubuntu xenial/restricted Sources [5179 B] Get:6 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB] Get:7 http://nginx.org/packages/ubuntu xenial InRelease [4339 B] Get:8 http://nginx.org/packages/ubuntu xenial/nginx Sources [14.1 kB] Get:9 http://nginx.org/packages/ubuntu xenial/nginx amd64 Packages [20.1 kB] Get:10 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB] Get:11 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB] Get:12 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB] Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/main Sources [415 kB] Get:14 http://archive.ubuntu.com/ubuntu xenial-updates/restricted Sources [2684 B] Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [303 kB] Get:16 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1166 kB] Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB] Get:18 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [929 kB] Get:19 http://archive.ubuntu.com/ubuntu xenial-security/main Sources [175 kB] Get:20 http://archive.ubuntu.com/ubuntu xenial-security/restricted Sources [2243 B] Get:21 http://archive.ubuntu.com/ubuntu xenial-security/universe Sources [116 kB] Get:22 http://archive.ubuntu.com/ubuntu xenial-security/multiverse Sources [3513 B] Get:23 http://archive.ubuntu.com/ubuntu xenial-security/main amd64 Packages [767 kB] Get:24 http://archive.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB] Get:25 http://archive.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [527 kB] Get:26 http://archive.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [6119 B] Fetched 27.3 MB in 4min 1s (113 kB/s) Reading package lists... Done 11.通过命令 docker commit来提交容器副本,创建的目标镜像名 //-m:提交的描述信息,-a:指定镜像作者,d11aaceba824:容器ID,test/lnmp:v1 :指定要创建的目标镜像名 [root@localhost test]# docker commit -m="LNMP" -a="test" d11aaceba824 test/lnmp:v1 sha256:30a7c473b0ca8e02c1d1ac0ef3188e09d12649faf60cede37e2d7ccb877331e6 [root@localhost test]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE test/lnmp v1 30a7c473b0ca 3 minutes ago 335 MB docker.io/hello-world latest fce289e99eb9 3 weeks ago 1.84 kB docker.io/idiswy/lnmp latest fbd7b7c5428e 2 years ago 335 MB docker.io/ubuntu 15.10 9b9cb95443b5 2 years ago 137 MB 12.设置镜像标签 docker tag 镜像ID,这里是 860c279d2fec ,用户名称、镜像源名(repository name)和新的标签名(tag)。 使用 docker images 命令可以看到,ID为860c279d2fec的镜像多一个标签。 [root@localhost test]# docker tag 30a7c473b0ca test/lnmp:tagv1 [root@localhost test]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE test/lnmp tagv1 30a7c473b0ca 15 minutes ago 335 MB test/lnmp v1 30a7c473b0ca 15 minutes ago 335 MB docker.io/hello-world latest fce289e99eb9 3 weeks ago 1.84 kB docker.io/idiswy/lnmp latest fbd7b7c5428e 2 years ago 335 MB docker.io/ubuntu 15.10 9b9cb95443b5 2 years ago 137 MB 13:通过 Dockerfile 构建 hellodocker [root@localhost test]# cat Dockerfile FROM centos LABEL maintainer="Hello Docker" RUN /bin/bash CMD ["echo","Hello Docker"] [root@localhost test]# docker build -t hellodocker . Sending build context to Docker daemon 2.048 kB Step 1/4 : FROM centos Trying to pull repository docker.io/library/centos ... latest: Pulling from docker.io/library/centos a02a4930cb5d: Pull complete Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426 Status: Downloaded newer image for docker.io/centos:latest ---> 1e1148e4cc2c Step 2/4 : LABEL maintainer "Hello Docker" ---> Running in 20e2be20052b ---> f255f97c4984 Removing intermediate container 20e2be20052b Step 3/4 : RUN /bin/bash ---> Running in a195ff956608 ---> ec18faa97f10 Removing intermediate container a195ff956608 Step 4/4 : CMD echo Hello Docker ---> Running in fcd177b109d9 ---> 075486018a06 Removing intermediate container fcd177b109d9 Successfully built 075486018a06 [root@localhost test]# docker images hellodocker REPOSITORY TAG IMAGE ID CREATED SIZE hellodocker latest 075486018a06 About a minute ago 202 MB [root@localhost test]# docker run -i -t hellodocker Hello Docker
samba的使用
发布于:2018-6-19 16:53 作者:admin 浏览:1626 分类:Linuxsamba的使用 1.samba的安装 #yum install samba samba-common smbclient 2.新建共享用户和路径 #mkdir /usr/local/sambashare #groupadd sambasharegroup #useradd -g sambasharegroup sambashareuser #smbpasswd -a sambashareuser #chown -R sambashareuser:sambasharegroup /usr/local/sambashare 3.配置samba。 #vi /etc/samba/smb.conf #共享IP:192.168.1.101, 共享名:share, 共享路径:/usr/local/sambashare, #共享用户需要输入的用户sambashareuser 和 刚才设置sambashareuser密码. [share] comment = share path = /usr/local/sambashare browseable = yes writable = yes available = yes valid users = sambashareuser4.windows使用计算机->映射网络驱动器->文件夹:输入 \\liunx的IP地址\共享名 [共享地址]。即可使用。当做本地一个磁盘,用本地的编辑器操作linux的文件
hive安装
发布于:2018-6-11 14:41 作者:admin 浏览:2235 分类:系统架构环境要求
Java jdk1.8.0_17 Hadoop 2.9.1 Hive-2.3.3 Mysql 5.5.56 MySQL驱动:mysql-connector-java.jar
#wget http://mirror.bit.edu.cn/apache/hive/hive-2.2.0/apache-hive-2.2.0-bin.tar.gz #tar -xzvf apache-hive-2.2.0-bin.tar.gz #mv apache-hive-2.3.3-bin /usr/local/soft/hive #cp mysql-connector-java.jar /usr/local/soft/hive/lib/
#vi /etc/profile export HIVE_HOME=/usr/local/soft/hive export PATH=${HIVE_HOME}/bin:$PATH export CLASSPATH=.:${HIVE_HOME}/lib:$CLASSPATH
MYSQL数据库设置(元数据库)
#CREATE DATABASE hive DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; #GRANT ALL PRIVILEGES ON hive.* TO 'hive'@'%' IDENTIFIED BY 'hive' WITH GRANT OPTION; #FLUSH PRIVILEGES;
Hive配置文件
#cp hive-default.xml.template hive-site.xml #vi hive-site.xml <configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>hive</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>hive</value> </property> </configuration>
初始化HIVE数据库
#/usr/local/soft/hive/bin/schematool -dbType mysql -initSchema
启动Hive
#/usr/local/soft/hive/bin/hive #hive> show databases; #hive> create database wordcount; #hive> use wordcount; #hive> create table words(name string,num int); #hive> insert into words(name,num) values('hello',2); #hive> insert into words(name,num) values('world',1); #hive> insert into words(name,num) values('hello',1); #hive> select * from words; #hive> select name,sum(num) from words group by name;
查看Hive文件和Mysql数据的元数据库hive.
mysql>select * from hive.DBS;
Hadoop实战-PHP-MapReduce
发布于:2018-6-8 8:51 作者:admin 浏览:2188 分类:系统架构1. 编写Mapper的代码
#vi WordMap.php
#!/usr/bin/php <?php while (($line = fgets(STDIN)) !== false) { $words = preg_split('/(\s+)/', $line); foreach ($words as $word) { echo $word."\t"."1".PHP_EOL; } } ?>
2.编写Reducer的代码
#vi WordReduce.php
#!/usr/bin/php <?php $result=array(); while (($line = fgets(STDIN)) !== false) { $line = trim($line); list($k, $v) = explode("\t", $line); $result[$k] += $v; } ksort($result); foreach($result as $word => $count) { echo $word."\t".$count.PHP_EOL; } ?>
3.运行WordMapReduce
#chmod 0777 WordMap.php #chmod 0777 WordReduce.php #bin/hadoop jar share/hadoop/tools/lib/hadoop-streaming-2.9.1.jar -mapper WordMap.php -reducer WordReduce.php -input HdfsInput/* -output HdfsOutput
4.查看运行结果
#hadoop fs -ls HdfsOutput #hadoop fs -cat HdfsOutput/* #hadoop fs -get HdfsOutput LocalOutput #cat LocalOutput/*
Hadoop实战-MapReduce
发布于:2018-6-7 12:41 作者:admin 浏览:1889 分类:系统架构
Hadoop实战-环境搭建
http://www.wangfeilong.cn/server/114.html
Hadoop实战-MapReduce
1. 编写Mapper的代码
#vi WordMap.java
import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
//实现Mapper
public class WordMap extends Mapper<LongWritable, Text, Text, LongWritable>{
@Override
protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context)
throws IOException, InterruptedException {
//读取到的一行字符串,按照空格分割单词
String line = value.toString();
String[] words = line.split(" ");
for (String word : words) {
//将分割的单词word输出为key,次数输出为value,次数为1,这行数据会输到reduce中,
context.write(new Text(word), new LongWritable(1));
}
}
}
2.编写Reducer的代码
#vi WordReduce.java
import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
//实现Reducer
public class WordReduce extends Reducer<Text, LongWritable, Text, LongWritable> {
@Override
/**
* 第一个Text: 是传入的单词名称,是Mapper中传入的
* 第二个:LongWritable 是该单词出现了多少次,这个是mapreduce计算出来的
* 第三个Text: 是输出单词的名称 ,这里是要输出到文本中的内容
* 第四个LongWritable: 是输出时显示出现了多少次,这里也是要输出到文本中的内容
*/
protected void reduce(Text key, Iterable<LongWritable> values,
Reducer<Text, LongWritable, Text, LongWritable>.Context context) throws IOException, InterruptedException {
//累加统计
long count = 0;
for (LongWritable num : values) {
count += num.get();
}
context.write(key, new LongWritable(count));
}
}
3.编写main方法执行这个MapReduce
#vi WordMapReduce.java
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
//实现MapReduce
public class WordMapReduce{
public static void main(String[] args) throws IOException {
Configuration conf = new Configuration();
//如果是打包在linux上运行,则不需要写这两行代码
/*
//指定运行在yarn中
conf.set("mapreduce.framework.name", "yarn");
//指定resourcemanager的主机名
conf.set("yarn.resourcemanager.hostname", "localhost");
*/
Job job = Job.getInstance(conf);
//使得hadoop可以根据类包,找到jar包在哪里
job.setJarByClass(WordMapReduce.class);
//指定Mapper的类
job.setMapperClass(WordMap.class);
//指定reduce的类
job.setReducerClass(WordReduce.class);
//设置Mapper输出的类型
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(LongWritable.class);
//设置最终输出的类型
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class);
//指定输入文件的位置,这里为了灵活,接收外部参数
FileInputFormat.setInputPaths(job, new Path(args[0]));
//指定输入文件的位置,这里接收启动参数
FileOutputFormat.setOutputPath(job, new Path(args[1]));
//将job中的参数,提交到yarn中运行
//job.submit();
try {
job.waitForCompletion(true);
//这里的为true,会打印执行结果
} catch (ClassNotFoundException | InterruptedException e) {
e.printStackTrace();
}
}
}
4. 编译WordMapReduce
注意环境变量
#export CLASSPATH=.:/usr/local/soft/jdk1.8.0_171/lib:/usr/local/soft/jdk1.8.0_171/jre/lib:$(/usr/local/soft/hadoop/bin/hadoop classpath):$CLASSPATH
编译
#javac WordMap.java
#javac WordReduce.java
#javac WordMapReduce.java
5.打包 WordMap、WordReduce、WordMapReduce的class打包
#jar cvf WordMapReduce.jar Word*.class
6.运行WordMapReduce
#hadoop jar WordMapReduce.jar WordMapReduce HdfsInput HdfsOutput
7.查看运行结果
#hadoop fs -ls HdfsOutput
#hadoop fs -cat HdfsOutput/*
#hadoop fs -get HdfsOutput LocalOutput
#cat LocalOutput/*
Hadoop实战-环境搭建
发布于:2018-6-7 10:55 作者:admin 浏览:2154 分类:系统架构Hadoop实战(1)-环境搭建
1.准备的软件
centos7
SSH
Java 1.8.0_171
Hadoop 2.9.1
2.安装SSH
#yum install openssh-server openssh-clients
3.新建软件安装目录
#mdkir -p /usr/local/soft/
#cd /usr/local/soft/
3.安装Java Java 1.8.0_171
3.1. 下载
#wget http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.tar.gz?AuthParam=1528334282_eed030b012c430a6a5d6cebcfd2ff96f
3.2. 解压
#tar –zvxf jdk-8u171-linux-x64.tar.gz
3.3. 设置环境变量
#vi /etc/profile
export JAVA_HOME=/usr/local/soft/jdk1.8.0_171
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
3.4.环境变量生效
#source /etc/profile
4. 安装 Hadoop 2.9.1
4.1. 下载
#wget https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/hadoop-2.9.1/hadoop-2.9.1.tar.gz
4.2 解压
#tar –zvxf hadoop-2.9.1.tar.gz
4.3 更改文件名为hadoop
#mv hadoop-2.9.1 hadoop
4.4. 设置环境变量
#vi /etc/profile
export Hadoop_HOME=/usr/local/soft/hadoop
export PATH=${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin:$PATH
export CLASSPATH=$($HADOOP_HOME/bin/hadoop classpath):$CLASSPATH
4.5.环境变量生效
#source /etc/profile
5. Hadoop单机模式
5.1 Hadoop单机模式配置
#cd /usr/local/soft/hadoop/
#vi etc/hadoop/hadoop-env.sh
export JAVA_HOME=/usr/local/soft/jdk1.8.0_171
5.2 Hadoop单机模式实战
#mkdir LocalInput
#cp etc/hadoop/*.xml LocalInput
#bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.9.1.jar grep LocalInput LocalOutput 'dfs[a-z.]+'
#cat LocalOutput/*
6. SSH免登录设置
# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# chmod 0600 ~/.ssh/authorized_keys
# ssh localhost
7 Hadoop伪分布模式
7.1 Hadoop伪分布模式配置
7.1.1 #vi etc/hadoop/core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
7.1.2 #vi etc/hadoop/hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
7.1.3 #vi etc/hadoop/mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
7.1.4 #vi etc/hadoop/yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
7.2 Hadoop伪分布模式启动和查看
7.2.1 格式化文件系统
# bin/hdfs namenode -format
7.2.2 启动 NameNode 、DataNode 、ResourceManager 、NodeManager
#sbin/start-all.sh
7.2.3 查看监控页面
http://localhost:50070/ (查看NameNode)
http://localhost:8088/ (查看ResourceManager)
7.3 Hadoop伪分布模式文件上传和下载
7.3.1新建执行 MapReduce jobs 需要的目录
#bin/hdfs dfs -mkdir /user
#bin/hdfs dfs -mkdir /user/root
7.3.2 本地文件上传到HDFS和从HDFS下载本地
新建本地文件
#cd LocalInput
#vi F1.txt
Hello World
Hello Hadoop
#vi F2.txt
Hello JAVA
JAVA 是 一门 面向对象 编程 语言
把本地文件上传到HDFS
#bin/hdfs dfs -put LocalInput/*.txt HdfsInput
查看HDFS文件
#bin/hdfs dfs -ls HdfsInput
把HDFS文件下载到本地LocalOutput
#bin/hdfs dfs -get HdfsInput LocalOutput
查看已经下载到本地的文件
#ls -l LocalOutput
7.4 Hadoop伪分布模式停止
#sbin/stop-all.sh
Hadoop实战(2)-MapReduce
http://www.wangfeilong.cn/server/115.html
Hadoop实战(3)-PHP-MapReduce
http://www.wangfeilong.cn/server/116.html
为什么centos7的service命令无法启动服务
发布于:2017-3-15 16:41 作者:admin 浏览:1702 分类:LinuxCentOS 7.0中一个最主要的改变,就是切换到了systemd。它用于替代红帽企业版Linux前任版本中的SysV和Upstart,对系统和服务进行管理。systemd兼容SysV和Linux标准组的启动脚本。 Systemd是一个Linux操作系统下的系统和服务管理器。它被设计成向后兼容SysV启动脚本,并提供了大量的特性,如开机时平行启动系统服务,按需启动守护进程,支持系统状态快照,或者基于依赖的服务控制逻辑。 先前的使用SysV初始化或Upstart的红帽企业版Linux版本中,使用位于/etc/rc.d/init.d/目录中的bash初始化脚本进行管理。而在RHEL 7/CentOS 7中,这些启动脚本被服务单元取代了。服务单元以.service文件扩展结束,提供了与初始化脚本同样的用途。要查看、启动、停止、重启、启用或者禁用系统服务,你要使用systemctl来代替旧的service命令。 注:为了向后兼容,旧的service命令在CentOS 7中仍然可用,它会重定向所有命令到新的systemctl工具。 使用systemctl来启动/停止/重启服务 要启动一个服务,你需要使用如下命令: # systemctl start httpd.service 这会启动httpd服务,就我们而言,Apache HTTP服务器。 要停掉它,需要以root身份使用该命令: # systemctl stop httpd.service 要重启,你可以使用restart选项,如果服务在运行中,它将重启服务;如果服务不在运行中,它将会启动。你也可以使用try-start选项,它只会在服务已经在运行中的时候重启服务。同时,reload选项你也可以有,它会重新加载配置文件。 # systemctl restart httpd.service # systemctl try-restart httpd.service # systemctl reload httpd.service 我们例子中的命令看起来会像下面这样: 检查服务状态 要检查服务状态,你可以使用status选项,看这里: # systemctl status httpd.service 输出结果就像这样: 它会告诉你运行中的服务的方方面面。 使用启用/禁用服务来控制开机启动 你也可以使用enable/disable选项来控制一个服务是否开机启动,命令如下: # systemctl enable httpd.service # systemctl disable httpd.service
CentOS上yum安装Nginx服务
发布于:2017-3-15 16:34 作者:admin 浏览:2182 分类:系统架构原因:由于centos没有默认的nginx软件包,需要启用REHL的附件包
rpm -Uvh http://download.Fedora.RedHat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum -y install nginx
设置开机启动
chkconfig nginx on
安装spawn-fcgi来运行php-cgi
yum install spawn-fcgi
下载spawn-fcgi 的启动脚本
wget http://bash.cyberciti.biz/dl/419.sh.zip
unzip 419.sh.zip
mv 419.sh /etc/init.d/php_cgi
chmod +x /etc/init.d/php_cgi
启动php_cgi
/etc/init.d/php_cgi start
查看进程
netstat -tulpn | grep :9000
若出现如下代表一切正常
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4352/php-cgi
配置nginx(详细配置见nginx.conf详细说明)
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
查看phpinfo
phpinfo();
安装phpmyadmin
修改/var/lib/php/session的权限和nginx和php_cgi一致
chown -R www.www /var/lib/php/session