月份:2019年3月

一看必会系列:k8s 练习2 使用k8s部署php&redis组成的留言系统

No Comments Kubernetes

k8s-master 192.168.10.68
k8s-node1  192.168.10.71

本文将演示使用kubernetes系统基于 kubeguide相关的镜像文件创建基于php和redis的留言板系统
容器功能实现

前端 frontend 是php  从后端读取数据并展示
后端是 redis (一主 2从)提供数据

在线下载相关的镜像文件,并纳入本地仓库统一管理

# docker pull kubeguide/redis-master
# docker pull kubeguide/guestbook-php-frontend
# docker pull kubeguide/guestbook-redis-slave
# docker tag kubeguide/redis-master reg.jdccie.com/redis-master
# docker tag kubeguide/guestbook-php-frontend reg.jdccie.com/guestbook-php-frontend
# docker tag kubeguide/guestbook-redis-slave reg.jdccie.com/guestbook-redis-slave

#要称登陆 registry仓库
docker login -u 用户 -p密码 reg.jdccie.wang
# docker push reg.jdccie.com/redis-master
# docker push reg.jdccie.com/guestbook-php-frontend
# docker push reg.jdccie.com/guestbook-redis-slave

文件结构
[root@k8s-master yaml]# tree redis_web/
redis_web/
├── frontend-rc.yaml
├── frontend-svc.yaml
├── redis-master-rc.yaml
├── redis-master-svc.yaml
├── redis-slave-rc.yaml
└── redis-slave-svc.yaml

[root@k8s-master yaml]# vim /root/login.sh
[root@k8s-master yaml]# cat redis_web/*

├── frontend-rc.yaml 配置

apiVersion: v1
kind: ReplicationController
metadata:
  name: frontend-rc
  labels:
    name: frontend-pod-lb
spec:
  replicas: 3
  selector:
    name: frontend-pod-lb
  template:
    metadata:
      labels:
        name: frontend-pod-lb
    spec:
     containers:
     – name: frontend-name
       image: reg.ccie.wang/test/guestbook-php-frontend:latest
       ports:
       – containerPort: 80
       env:
       – name: GET_HOSTS_FROM
         value: "env"
        
├── frontend-svc.yaml配置
apiVersion: v1                                                                             
kind: Service
metadata:                                                                                  
  name: frontend-svc                                                                              
  labels:
    name: frontend-pod-lb
spec:                                                                                      
  type: NodePort
  ports:
    – port: 80
      nodePort: 30011
  selector:
    name: frontend-pod-lb

├── redis-master-rc.yaml配置

apiVersion: v1
kind: ReplicationController
metadata:
  name: redis-master-rc
  labels:
    names: redis-master-lb
spec:
  replicas: 1
  selector:
    name: redis-master-lb
  template:
    metadata:
      labels:
        name: redis-master-lb
    spec:
     containers:
     – name: master
       image: kubeguide/redis-master
       ports:
       – containerPort: 6379
      
├── redis-master-svc.yaml 配置
apiVersion: v1                                                                             
kind: Service
metadata:                                                                                  
  name: redis-master                                                                              
  labels:
    name: redis-master-lb
spec:                                                                                      
  ports:
    – port: 6379
      targetPort: 6379
  selector:
    name: redis-master-lb
   
├── redis-slave-rc.yaml 配置
apiVersion: v1
kind: ReplicationController
metadata:
  name: redis-slave-rc
  labels:
    names: redis-slave-lb
spec:
  replicas: 2
  selector:
    name: redis-slave-lb
  template:
    metadata:
      labels:
        name: redis-slave-lb
    spec:
     containers:
     – name: slave
       image: reg.ccie.wang/test/guestbook-redis-slave:latest
       env:
       – name: GET_HOSTS_FROM
         value: env
       ports:
       – containerPort: 6379
      
└── redis-slave-svc.yaml 配置

apiVersion: v1                                                                             
kind: Service
metadata:                                                                                  
  name: redis-slave                                                                              
  labels:
    name: redis-slave-lb
spec:                                                                                      
  ports:
    – port: 6379
  selector:
    name: redis-slave-lb

创建相应容器
redis-master
  940  kubectl create -f redis-master-rc.yaml
  941  kubectl create -f redis-master-svc.yaml
redis-slave
  948  kubectl create -f redis-slave-rc.yaml
  958  kubectl create -f redis-slave-svc.yaml
frontend
1011  kubectl create -f frontend-rc.yaml
1030  kubectl create -f frontend-svc.yaml

删除容器
kubectl delete -f 对应配置
记得验证 kubectl get rc,pod,svc

验证rc,pod,svc启动是否正常
[root@k8s-master yaml]# kubectl get rc,pod,svc

#DESIRED/CURRENT/READY 三者数量一至并与配置文件一样即为正常

------中间广告---------

NAME                                    DESIRED   CURRENT   READY   AGE
replicationcontroller/frontend-rc       3         3         3       81m
replicationcontroller/redis-master-rc   1         1         1       17h
replicationcontroller/redis-slave-rc    2         2         2       17h

#所有 Running 即正常

NAME                        READY   STATUS    RESTARTS   AGE
pod/frontend-rc-2h62f       1/1     Running   0          81m
pod/frontend-rc-5dwk2       1/1     Running   0          81m
pod/frontend-rc-dmxp8       1/1     Running   0          81m
pod/redis-master-rc-jrrgx   1/1     Running   0          17h
pod/redis-slave-rc-f9svq    1/1     Running   0          6h12m
pod/redis-slave-rc-p6kbq    1/1     Running   0          17h

#确认type port是否与配置一致
NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
service/frontend-svc   NodePort    10.100.151.156   <none>        80:30011/TCP   81m
service/redis-master   ClusterIP   10.100.215.236   <none>        6379/TCP       17h
service/redis-slave    ClusterIP   10.100.178.103   <none>        6379/TCP       17h

查看redis-master是同步是否正常
grep -A 5 "关键字" #显示关键字后的5行

[root@k8s-master yaml]# kubectl exec redis-master-rc-jrrgx redis-cli info |grep -A 5 "Replication"
# Replication
role:master
connected_slaves:2   #说明有两个slave且正常
slave0:ip=10.244.1.108,port=6379,state=online,offset=82615,lag=0
slave1:ip=10.244.1.110,port=6379,state=online,offset=82615,lag=0
master_repl_offset:82615

查看slave的环境变量是否拿到 MASTER信息
[root@k8s-master yaml]# kubectl exec redis-slave-rc-f9svq env |grep MASTER
REDIS_MASTER_PORT_6379_TCP=tcp://10.100.215.236:6379
REDIS_MASTER_PORT_6379_TCP_ADDR=10.100.215.236
REDIS_MASTER_PORT=tcp://10.100.215.236:6379
REDIS_MASTER_SERVICE_PORT=6379
REDIS_MASTER_PORT_6379_TCP_PROTO=tcp
REDIS_MASTER_SERVICE_HOST=10.100.215.236
REDIS_MASTER_PORT_6379_TCP_PORT=6379
[root@k8s-master yaml]#

 

查看frontend 运行在哪个node
[root@k8s-master yaml]# kubectl get pod -o wide
NAME                    READY   STATUS    RESTARTS   AGE     IP             NODE        NOMINATED NODE   READINESS GATES
frontend-rc-px989       1/1     Running   0          145m    10.244.1.114   k8s-node1   <none>           <none>
frontend-rc-q5mk4       1/1     Running   0          145m    10.244.1.115   k8s-node1   <none>           <none>
frontend-rc-qh466       1/1     Running   0          145m    10.244.1.116   k8s-node1   <none>           <none>
redis-master-rc-jrrgx   1/1     Running   0          16h     10.244.1.107   k8s-node1   <none>           <none>
redis-slave-rc-f9svq    1/1     Running   0          4h44m   10.244.1.110   k8s-node1   <none>           <none>
redis-slave-rc-p6kbq    1/1     Running   0          16h     10.244.1.108   k8s-node1   <none>           <none>
[root@k8s-master yaml]#

验证服务,使用刚查看的 node1及IP进行测试,能访问,能提交数据进行测试即可
[root@k8s-node1 ~]# curl 192.168.10.69:30011
<html ng-app="redis">
  <head>
    <title>Guestbook</title>
    <link rel="stylesheet" href="bootstrap.min.css">
    <script src="angular.min.js"></script>
    <script src="controllers.js"></script>
    <script src="ui-bootstrap-tpls.js"></script>
  </head>

最后可以进redis进行数据验证和 http界面上是否一致

1.进入redis-master容器内
[root@k8s-master yaml]#  kubectl exec -it redis-master-rc-jrrgx /bin/bash
2.进入redis
[ root@redis-master-rc-jrrgx:/data ]$ redis-cli    
3 查看所有keys
127.0.0.1:6379> keys *
1) "messages"
4. 获取key  "messages" 对应的值
127.0.0.1:6379> get messages
"Hello World!,hhh,gegrgr"
127.0.0.1:6379> get messages
"Hello World!,hhh,gegrgr,frr"  #增加为正常
127.0.0.1:6379>

 

———-报错

[root@k8s-master yaml]# kubectl logs frontend-rc-2h62f
AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 10.244.1.118. Set the ‘ServerName’ directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 10.244.1.118. Set the ‘ServerName’ directive globally to suppress this message
[Tue Mar 26 08:34:03.926249 2019] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.12 configured — resuming normal operations
[Tue Mar 26 08:34:03.926296 2019] [core:notice] [pid 1] AH00094: Command line: ‘apache2 -D FOREGROUND’

解决进服务器
[root@k8s-master yaml]# kubectl exec -it frontend-rc-2h62f /bin/bash
root@frontend-rc-2h62f:/var/www/html#
root@frontend-rc-2h62f:/var/www/html#
root@frontend-rc-2h62f:/var/www/html# find / -name httpd.conf
root@frontend-rc-2h62f:/var/www/html#

不管他没有影响,想解决加个Servername IP 就行了

Jenkins插件下载失败两种处理办法

No Comments IT小技巧

 

 

第一种:更换源的问题
jenkins->系统管理->管理插件->高级

 

 

把:http://updates.jenkins-ci.org/update-center.json
换成:http://mirror.esuni.jp/jenkins/updates/update-center.json
镜像地址查询:
http://mirrors.jenkins-ci.org/status.html

第二种:手动下载
到https://wiki.jenkins-ci.org/display/JENKINS/Plugins 以安装SSH plugin插件为例,具体的步骤如下

 

系统管理–>管理插件–>可选插件–>输入插件名–>勾选相应插件–>点击直接安装。

 

在系统管理–管理插件–高级–上传插件即可,如下图

Jenkins插件下载失败两种处理办法

No Comments IT小技巧

 

 

第一种:更换源的问题
jenkins->系统管理->管理插件->高级

 

 

把:http://updates.jenkins-ci.org/update-center.json
换成:http://mirror.esuni.jp/jenkins/updates/update-center.json
镜像地址查询:
http://mirrors.jenkins-ci.org/status.html

第二种:手动下载
到https://wiki.jenkins-ci.org/display/JENKINS/Plugins 以安装SSH plugin插件为例,具体的步骤如下

 

在系统管理–管理插件–高级–上传插件即可,如下图

一看必会系列:docker 实战 12 docker部署jenkins及jenkins迁移方法

No Comments Docker

 

迁移

进jenkins服务器目录
/var/lib/jenkins/
打包jobs文件目录
tar -cvzf jenkins01.job.tar.gz jobs

#迁移的时候可以直接将jenkins主目录数据整个拷贝过去,
#也可以单独拷贝jenkins主目录下的config.xml文件以及jobs、users、workspace、plugins四个目录
#(这是主要的迁移数据)。一般来说,手动设置好jenkins主目录路径,启动jenkins后就会自动生成
#(但要确保jenkins用户有权限创建这个主目录,最好是提前手动创建并赋予jenkins启动用户的权限)

传到目的服务器
scp -i AZURE-OPS-PRIVATE /var/lib/jenkins/jenkins01.job.tar.gz  ops@10.21.2.8:/tmp/

在容器服务器
1.创建目录
mkdir -p /data/service/jenkins02
2.授权。不然会报错
chown 1000:1000 -R /data/service/jenkins02
3.创建容器
docker run -itd -p 8082:8080 -p 50000:50000 \
–name jenkins02 \
–restart always \
-v /data/service/jenkins02:/var/jenkins_home \
-v /data/service/jenkins02/opt/script:/opt/script \
jenkins:2.19.2  #版本尽量相同不然会有问题
4.
验证并登陆
http://主机IP:8082

获取初始密码,可以进主机的对应目录
进容器内目录
/var/jenkins_home/secrets/initialAdminPassword

5.进入系统后点
异常状态:系统管理–>读取配置–>重启 没出现刚还原的jobs
正常状态:系统管理–>读取配置–>重启 出现刚还原的jobs

———-报错
[root@jdccie.com-001 service]# docker run -p 8082:8080 -p 50000:50000 -v /data/service/jenkins02:/var/jenkins_home jenkins
touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?

解决
chown 1000:1000 -R /data/service/jenkins02

如果装了这个插件是没法迁移的。
Manage and Assign Roles

一看必会系列:docker 练习 11 docker部署gitlab及gitlab迁移方法

No Comments Docker

gitlab docker安装

前提
关闭selinux:
# sed -i ‘s/enforcing/disabled/’ /etc/selinux/config
# setenforce 0
关闭swap:
# swapoff -a  # 临时
# vim /etc/fstab  # 永久
同步时间:
# yum install ntpdate -y
# ntpdate  ntp.api.bz

# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager –add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装 Docker-CE
sudo yum makecache fast
yum install docker-ce-17.03.3.ce -y
如果提示container-selinux依赖问题,先安装ce-17.03匹配版本:
# yum localinstall https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.3.ce-1.el7.noarch.rpm
# Step 4: 开启Docker服务
# systemctl enable docker && systemctl start docker

# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 17.03.3-ce   #版本信息

部署容器
sudo docker run –detach \
  –hostname git03.jdccie.com \
  –publish 4430:443 –publish 803:80 –publish 223:22 \
  –name gitlab03 \
  –restart always \
  –volume /data/service/gitlab/config:/etc/gitlab \
  –volume /data/service/gitlab/logs:/var/log/gitlab \
  –volume /data/service/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest
 
–restart 标志会检查容器的退出代码,并据此来决定是否要重启容器,默认是不会重启。
–restart的参数说明
always:无论容器的退出代码是什么,Docker都会自动重启该容器。
on-failure:只有当容器的退出代码为非0值的时候才会自动重启。另外,该参数还接受一个可选的重启次数参数,
–restart=on-fialure:5`表示当容器退出代码为非0时,Docker会尝试自动重启该容器,最多5次。

 
验证
root@docker01:~# docker ps
CONTAINER ID        IMAGE                                    COMMAND                                 
PORTS                                                             NAMES
b4a6652f3a4d        gitlab/gitlab-ce:latest                  "/assets/wrapper"         
0.0.0.0:223->22/tcp, 0.0.0.0:803->80/tcp, 0.0.0.0:4430->443/tcp   gitlab03

目录说明
Local location    Container location    Usage
/srv/gitlab/data    /var/opt/gitlab    For storing application data
/srv/gitlab/logs    /var/log/gitlab    For storing logs
/srv/gitlab/config    /etc/gitlab    For storing the GitLab configuration files

 

#gitlab 迁移及恢复数据
1.容器外复制备份文件到 logs目录
cp ../15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar logs/
2.
docker exec -it a622702ec855 /bin/bash
root@git03:/#
3. 容器内
root@git03:/var/log/gitlab# cp 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar /var/opt/gitlab/backups
4. 修改权限
chmod 666 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar
5  恢复数据
gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=15531jdccie.com_2019_03_21_10.7.3
其中有两处需要 输入yes,注意一下
Do you want to continue (yes/no)? yes

5 。修改 project的域名信息
修改前http://1.1.1.1/root/git03.git
修改后
http://git03.jdccie.com:803/root/git03.git

修改方法
1.进容器
2.在容器里修改
vim /var/opt/gitlab/gitlab-rails/etc/gitlab.yml

修改内容
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: git03.jdccie.com:803   #这时取巧了。因为容器对外的端口是803但容器内的端口是80所以改成这样
    port: 80                     #这个不要动,会启不动,当然也有另外的方法看最后
    https: false

3.在容器里重启
gitlab-ctl restart

访问验证即可

———-其它信息

如果在selinux环境用以下命令
sudo docker run –detach \
  –hostname gitlab.example.com \
  –publish 443:443 –publish 80:80 –publish 22:22 \
  –name gitlab \
  –restart always \
  –volume /srv/gitlab/config:/etc/gitlab:Z \
  –volume /srv/gitlab/logs:/var/log/gitlab:Z \
  –volume /srv/gitlab/data:/var/opt/gitlab:Z \
  gitlab/gitlab-ce:latest
 
 
sudo docker exec -it gitlab /bin/bash

You can also just edit /etc/gitlab/gitlab.rb:

sudo docker exec -it gitlab vi /etc/gitlab/gitlab.rb

Once you open /etc/gitlab/gitlab.rb make sure to set the external_url to point to a valid URL.

To receive e-mails from GitLab you have to configure the SMTP settings because the GitLab Docker image doesn’t have an SMTP server installed.

You may also be interested in Enabling HTTPS.

After you make all the changes you want, you will need to restart the container in order to reconfigure GitLab:

sudo docker restart gitlab

升级新版本

1 sudo docker stop gitlab
2 sudo docker rm gitlab
3 sudo docker pull gitlab/gitlab-ce:latest
4 sudo docker run –detach \
–hostname gitlab.example.com \
–publish 443:443 –publish 80:80 –publish 22:22 \
–name gitlab \
–restart always \
–volume /srv/gitlab/config:/etc/gitlab \
–volume /srv/gitlab/logs:/var/log/gitlab \
–volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
 
 
这里可以直接改域名信息
Create a docker-compose.yml file (or download an example):

web:
   image: ‘gitlab/gitlab-ce:latest’
   restart: always
   hostname: ‘gitlab.example.com’
   environment:
     GITLAB_OMNIBUS_CONFIG: |
       external_url ‘https://gitlab.example.com’
       # Add any other gitlab.rb configuration here, each on its own line
   ports:
     – ’80:80′
     – ‘443:443’
     – ’22:22′
   volumes:
     – ‘/srv/gitlab/config:/etc/gitlab’
     – ‘/srv/gitlab/logs:/var/log/gitlab’
     – ‘/srv/gitlab/data:/var/opt/gitlab’
 
 
———-报错

"couldn’t deduce an advertise address: no private IP found, explicit advertise addr not provided"

#恢复报错
Unpacking backup … tar: 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar: Cannot open: Permission denied

处理方式 修改权限
root@git03:/var/opt/gitlab/backups# ll
total 430188
drwx——.  2 git  root      4096 Mar 21 06:03 ./
drwxr-xr-x. 19 root root      4096 Mar 21 04:52 ../
-rw——- #原来的权限.  1 root root 440504320 Mar 21 06:03 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar
root@git03:/var/opt/gitlab/backups# chmod 666 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar
root@git03:/var/opt/gitlab/backups# ll
total 430188
drwx——.  2 git  root      4096 Mar 21 06:03 ./
drwxr-xr-x. 19 root root      4096 Mar 21 04:52 ../
-rw-rw-rw-#修改后的.  1 root root 440504320 Mar 21 06:03 15531jdccie.com_2019_03_21_10.7.3_gitlab_backup.tar

root@git03:/var/opt/gitlab/backups# gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=15531jdccie.com_2019_03_21_10.7.3                                                                              
Unpacking backup … done
GitLab version mismatch:
  Your current GitLab version (11.8.3) differs from the GitLab version in the backup!
  Please switch to the following version and try again:
  version: 10.7.3

[root@jdccie.comgitlab-001 logs]# docker pull gitlab/gitlab-ce:10.7.3-ce.0

删除原容器后,创建新容器报错
Error response from daemon: service endpoint with name gitlab03 already exists

原因,是容器被删了。但网络占用仍在占用
解决
1.确认删除容器  docker rm -f 容器ID
2.确认容器使用的网络也被删除
docker network inspect 网络模式
3.强制断开该网络 docker network disconnect –force 网络模式 xxx
docker network disconnect –force bridge gitlab03
4.验证 不出现gitlab03即可
[root@jdccie.comgitlab-001 ~]# docker network inspect bridge
5.重建容器即可

这是之前的信息
[root@jdccie.comgitlab-001 ~]# docker network inspect bridge
        "Name": "bridge",
                "Name": "gitlab03",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",

https://docs.gitlab.com/omnibus/docker/README.html

#
[root@jdccie.comgitlab-001 ops]# docker ps
CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS                         PORTS                                                             NAMES
0ce0e6599588        gitlab/gitlab-ce:10.7.3-ce.0   "/assets/wrapper"   About an hour ago   Up About an hour (unhealthy)   0.0.0.0:223->22/tcp, 0.0.0.0:803->80/tcp, 0.0.0.0:4430->443/tcp   gitlab03
[root@jdccie.comgitlab-001 ops]#

docker inspect 0ce0e6599588

                    {
                        "Start": "2019-03-21T09:14:29.322227599Z",
                        "End": "2019-03-21T09:14:59.322409713Z",
                        "ExitCode": -1,
                        "Output": "Health check exceeded timeout (30s)"
                    }

查看日志是nginx配置文件改的有问题

==> /var/log/gitlab/unicorn/unicorn_stderr.log <==
I, [2019-03-21T09:15:22.477559 #945]  INFO — : reaped #<Process::Status: pid 1177 exit 0> worker=0
I, [2019-03-21T09:15:22.477894 #945]  INFO — : reaped #<Process::Status: pid 1180 exit 0> worker=1
I, [2019-03-21T09:15:22.477985 #945]  INFO — : reaped #<Process::Status: pid 1183 exit 0> worker=2
I, [2019-03-21T09:15:22.478067 #945]  INFO — : reaped #<Process::Status: pid 1189 exit 0> worker=4
I, [2019-03-21T09:15:22.478318 #945]  INFO — : reaped #<Process::Status: pid 3199 exit 0> worker=3
I, [2019-03-21T09:15:22.478480 #945]  INFO — : master complete
ok: down: unicorn: 0s, normally up

从容器里把有问题的配置文件搞出来
docker cp 0ce0e6599588:/var/opt/gitlab/nginx/conf/gitlab-http.conf .
[root@jdccie.comgitlab-001 ops]# ls
gitlab-http.conf
修改
[root@jdccie.comgitlab-001 ops]# vim gitlab-http.conf
再搞回去
[root@jdccie.comgitlab-001 ops]# docker cp gitlab-http.conf 0ce0e6599588:/var/opt/gitlab/nginx/conf/gitlab-http.conf
重新启动服务器

Error response from daemon: service endpoint with name already exists

No Comments Docker

删除原容器后,创建新容器报错
Error response from daemon: service endpoint with name gitlab03 already exists

原因,是容器被删了。但网络占用仍在占用
解决
1.确认删除容器  docker rm -f 容器ID
2.确认容器使用的网络也被删除
docker network inspect 网络模式
3.强制断开该网络 docker network disconnect –force 网络模式 xxx
docker network disconnect –force bridge gitlab03
4.验证 不出现gitlab03即可
[root@hk-ops-ser-gitlab-001 ~]# docker network inspect bridge
5.重建容器即可

这是之前的信息
[root@hk-ops-ser-gitlab-001 ~]# docker network inspect bridge
        "Name": "bridge",
                "Name": "gitlab03",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",

linux 程序被Killed,如何精准查看日志

No Comments Linux

1.网上查经常是,查看日志,需要达到文件夹 log 找messages

cd /var/log/

发现massage是按天储存的,且当天的文件不显示,小白很无奈

2.在日志文件找kill

vi maillog-20180701 以编辑方法或者 可以通过cat 或tail 命令来查看

发现也看不懂什么

3.直接寻找错误,发现一个好方法:

dmesg | egrep -i -B100 ‘killed process’

## 或:
egrep -i ‘killed process’ /var/log/messages
egrep -i -r ‘killed process’ /var/log

## 或:
journalctl -xb | egrep -i ‘killed process’

把最近的killed process信息都输出了。感谢博客https://blog.csdn.net/green1893/article/details/78192017

4.参数说明

total-vm:31354724kB, anon-rss:30636060kB, file-rss:476kB, shmem-rss:0kB
1
我这个报错信息
百度说 RSS:指明了当前实际占用了多少内存
内存是30的,anon-rss值为30636060kBkB.RSS代表“驻留集大小”,即当前在进程中为RAM分配的内存量。file-rss是交换文件中对于该系统中所有进程为0KB的内存量。

明显的内存不够用了,接下来调代码啦
———————
作者:水…琥珀
来源:CSDN
原文:https://blog.csdn.net/shuihupo/article/details/80905641
版权声明:本文为博主原创文章,转载请附上博文链接!

docker 练习 10 docker容器nginx &mysql& wordpress实战lnmp

No Comments Docker

 

先运行一个测试容器,做准备脚本等东西

1新建容器
root@docker01:~# docker run -it –volumes-from /dbata  reg.ccie.wang/library/nginx:1.15.9 /bin/bash
2.将nginx 配置文件copy到 主机的目录
root@0ceda43a72e8:/# cp -a /etc/nginx/* /dbdata/
3.验证是否正确
root@0ceda43a72e8:/# ls /dbdata/
conf.d        koi-utf  mime.types  nginx.conf   uwsgi_params
fastcgi_params    koi-win  modules     scgi_params  win-utf

4.查看主机目录,并进入查看
root@docker01:~# docker inspect dbata |grep volumes
                "Source": "/var/lib/docker/volumes/59955b706aca5c81e18e30375d5f2993fb3119dfd9702fbb201b9cad4c09fab3/_data",

5.查看目录内容是否存在
root@docker01:~# ll /var/lib/docker/volumes/59955b706aca5c81e18e30375d5f2993fb3119dfd9702fbb201b9cad4c09fab3/_data
total 48
drwxr-xr-x 3 root root 4096 3月  19 18:23 ./
drwxr-xr-x 3 root root 4096 3月  19 18:16 ../
drwxr-xr-x 2 root root 4096 3月   5 12:34 conf.d/
-rw-r–r– 1 root root 1007 2月  26 22:13 fastcgi_params
-rw-r–r– 1 root root 2837 2月  26 22:13 koi-utf
-rw-r–r– 1 root root 2223 2月  26 22:13 koi-win
-rw-r–r– 1 root root 5231 2月  26 22:13 mime.types
lrwxrwxrwx 1 root root   22 2月  26 22:13 modules -> /usr/lib/nginx/modules
-rw-r–r– 1 root root  643 2月  26 22:13 nginx.conf
-rw-r–r– 1 root root  636 2月  26 22:13 scgi_params
-rw-r–r– 1 root root  664 2月  26 22:13 uwsgi_params
-rw-r–r– 1 root root 3610 2月  26 22:13 win-utf
root@docker01:~#

6.并文件copy到将要挂载的目录/opt/dockerfile/nginx_wordpress/etc/nginx
cp -a /var/lib/docker/volumes/59955b706aca5c81e18e30375d5f2993fb3119dfd9702fbb201b9cad4c09fab3/_data/* .
root@docker01:/opt/dockerfile/nginx_wordpress/etc/nginx# ll
total 48
drwxr-xr-x 3 root root 4096 3月  19 18:29 ./
drwxr-xr-x 3 root root 4096 3月  19 18:29 ../
drwxr-xr-x 2 root root 4096 3月   5 12:34 conf.d/
-rw-r–r– 1 root root 1007 2月  26 22:13 fastcgi_params
-rw-r–r– 1 root root 2837 2月  26 22:13 koi-utf
-rw-r–r– 1 root root 2223 2月  26 22:13 koi-win
-rw-r–r– 1 root root 5231 2月  26 22:13 mime.types
lrwxrwxrwx 1 root root   22 2月  26 22:13 modules -> /usr/lib/nginx/modules
-rw-r–r– 1 root root  643 2月  26 22:13 nginx.conf
-rw-r–r– 1 root root  636 2月  26 22:13 scgi_params
-rw-r–r– 1 root root  664 2月  26 22:13 uwsgi_params
-rw-r–r– 1 root root 3610 2月  26 22:13 win-utf
root@docker01:/opt/dockerfile/nginx_wordpress/etc/nginx#

正是开始

创建数据卷容器
docker run -it -v /dbdata –name dbata alpine

忘了数据库

1.先建数据库容器 并设置帐号等因为Wordpress要进行指定
docker run -itd -m 500M \
–volumes-from /dbata -v /opt/dockerfile/nginx_wordpress/mysql_data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-e MYSQL_DATABASE=wp \
-e MYSQL_USER=wpuser \
-e MYSQL_PASSWORD=111111 \
–name mysql_wp  reg.ccie.wang/library/mysql:5.7

2.创建 docker  wordpress 指定name 为–name wp001 ,
docker run -itd -m 500M -p 8080:80  \
–link  mysql_wp:mysql_wp \
–volumes-from /dbata -v /opt/dockerfile/nginx_wordpress/data:/data \
-e WORDPRESS_DB_HOST=mysql_wp:3306 \     #这时host就是上面的mysql名
-e WORDPRESS_DB_USER=wpuser \
-e WORDPRESS_DB_NAME=wp \
-e WORDPRESS_DB_PASSWORD=111111\
–name wp001  reg.ccie.wang/library/wordpress:latest
 
3.再创建 nginx 进行关联
docker run -itd -m 500M -p 80:80 \
–volumes-from /dbata -v /opt/dockerfile/nginx_wordpress/etc/nginx:/etc/nginx \
–name nginx_wp –link wp001:wp001 reg.ccie.wang/library/nginx:1.15.9

一定要按上面的顺序

验证
root@docker01:/opt/dockerfile/nginx_wordpress# docker stats 628b3cc50f10

CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
628b3cc50f10        nginx_wp            0.00%               2.668MiB / 500MiB   0.53%               3.69kB / 1.27kB     8.19kB / 0B         2

nginx容器增加配置文件

root@docker01:/opt/dockerfile/nginx_wordpress/etc/nginx/conf.d# cat jeff.conf
upstream wp {
   server  wp001:80;
}

server {
    listen 80;
    server_name 192.168.10.67;
  location / {
           client_max_body_size   3m;
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_pass http://wp;
}}

进入容器刷新配置

root@docker01:/opt/dockerfile/nginx_wordpress/etc/nginx/conf.d# cd
root@docker01:~# docker ps
CONTAINER ID        IMAGE                                    COMMAND                  CREATED             STATUS              PORTS                      NAMES
628b3cc50f10        reg.ccie.wang/library/nginx:1.15.9       "nginx -g ‘daemon of…"   9 minutes ago       Up 9 minutes        0.0.0.0:80->80/tcp         nginx_wp
c553107a4ec0        reg.ccie.wang/library/wordpress:latest   "docker-entrypoint.s…"   12 minutes ago      Up 12 minutes       0.0.0.0:8080->80/tcp       wp001
root@docker01:~# docker exec -it 628b3cc50f10 /bin/bash
root@628b3cc50f10:/# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@628b3cc50f10:/# nginx -s reload
2019/03/19 10:44:16 [notice] 14#14: signal process started
root@628b3cc50f10:/#

出来到其它机器上进行验证

[root@docker02 ~]# curl http://192.168.10.67/wp-admin/setup-config.php
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="robots" content="noindex,nofollow" />
    <title>WordPress &rsaquo; Setup Configuration File</title>
    <link rel=’stylesheet’ id=’buttons-css’  href=’http://192.168.10.67/wp-includes/css/buttons.min.css?ver=5.1′ type=’text/css’ media=’all’ />

出现以上信息即为成功

一看必会系列:docker 练习 9 docker容器间快捷互相访问

No Comments Docker

容器间互相访问需要知道IP
需要
1.进入容器或使用 inspect
root@docker:~# docker inspect 0bce7f78880f |grep IPA
            "SecondaryIPAddresses": null,
            "IPAddress": "192.169.110.4",
                    "IPAMConfig": null,
                    "IPAddress": "192.169.110.4",
root@docker:~#

换种方式使用  –link 会更方便
原理就是 创建容器时 会将 name与ip自动 写入容器的/etc/hosts列表

测试如下

1.创建一个叫 b11的容器
root@docker01:~# docker run -itd –name b11  busybox
5625fade077f39aae85049781b30e6eb9dd3c34a68cb61a2f451bb7fb0a746af
root@docker01:~# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                      NAMES
5625fade077f        busybox             "sh"                4 seconds ago       Up 2 seconds                                   b11
63a1c53f7504        cf00c586f612        "/bin/bash"         2 hours ago         Up 2 hours          0.0.0.0:32810->10091/tcp   blissful_hypatia

2.创建别一个容器 b12 并使用
–link 容器名:别名 
写入hosts

root@docker01:~# docker run -it –name b12 –link b11:b11  busybox
/ # cat /etc/hosts  #查看hosts内容
192.169.110.3    b11 5625fade077f   #将b11 和IP自动写入容器中
192.169.110.4    0bce7f78880f
/ # ping b11
PING b11 (192.169.110.3): 56 data bytes
64 bytes from 192.169.110.3: seq=0 ttl=64 time=0.132 ms
64 bytes from 192.169.110.3: seq=1 ttl=64 time=0.074 ms