0扰法、前期準備工作:
查看CentOS版本
[root@VM-8-7-centos ~]# lsb_release -a
CentOS 7安裝docker要求系統(tǒng)為64位裆甩、系統(tǒng)內(nèi)核版本為 3.10 以上
[root@VM-8-7-centos ~]# uname -r
1蔫饰、用yum源安裝docker并啟動(方法一):
查看是否已安裝docker列表
[root@VM-8-7-centos ~]# yum list installed | grep docker
安裝docker
[root@VM-8-7-centos ~]# yum -y install docker
啟動docker
[root@VM-8-7-centos ~]# systemctl start docker
查看docker服務(wù)狀態(tài)铅乡,當看到Active: active (running)時,說明啟動成功
[root@VM-8-7-centos ~]# systemctl status docker
1奏路、用yum源安裝docker并啟動(方法二):
以下命令都是在root賬號權(quán)限下執(zhí)行的
1、安裝相關(guān)依賴
[root@VM-8-7-centos ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@VM-8-7-centos ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
2臊诊、安裝最新版本的Docker CE和containerd
[root@VM-8-7-centos ~]# yum install docker-ce docker-ce-cli containerd.io
3鸽粉、啟動Docker
[root@VM-8-7-centos ~]# systemctl start docker
4、通過運行hello-world 映像驗證是否正確安裝了Docker CE 抓艳。
[root@VM-8-7-centos ~]# docker run hello-world
5触机、ip addr查看docker是否成功安裝,可以看到有三個IP段lo、eth0儡首、docker0片任,最后的docker0就是我們安裝成功的部分
[root@VM-8-7-centos ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:9b:a1:8e brd ff:ff:ff:ff:ff:ff
inet 10.0.8.7/22 brd 10.0.11.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe9b:a18e/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:e0:ca:af:52 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
6、啟動docker命令
[root@VM-8-7-centos ~]# systemctl start docker.service
7蔬胯、設(shè)置開機啟動docker
[root@VM-8-7-centos ~]# systemctl enable docker
8对供、查看版本
[root@VM-8-7-centos ~]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version: docker-1.13.1-203.git0be3e21.el7.centos.x86_64
Go version: go1.10.3
Git commit: 0be3e21/1.13.1
Built: Thu Nov 12 15:11:46 2020
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: docker-1.13.1-203.git0be3e21.el7.centos.x86_64
Go version: go1.10.3
Git commit: 0be3e21/1.13.1
Built: Thu Nov 12 15:11:46 2020
OS/Arch: linux/amd64
Experimental: false
區(qū)別:centos7默認安裝的docker都是免費的社區(qū)版版本
2、查找Docker Hub上的fastdfs鏡像:
查找fastdfs鏡像
[root@VM-8-7-centos ~]# docker search fastdfs
拉取最新版本
[root@VM-8-7-centos ~]# docker pull delron/fastdfs
查看鏡像
[root@VM-8-7-centos ~]# docker images
使用docker鏡像構(gòu)建tracker容器(跟蹤服務(wù)器氛濒,起到調(diào)度的作用)
[root@VM-8-7-centos ~]# docker run -dti --network=host --name tracker -v /var/fdfs/tracker:/var/fdfs -v /etc/localtime:/etc/localtime delron/fastdfs tracker
*** 注意:TRACKER_SERVER=本機的ip地址:22122 本機ip地址不要使用127.0.0.1
使用docker鏡像構(gòu)建storage容器(存儲服務(wù)器产场,提供容量和備份服務(wù))
[root@VM-8-7-centos ~]# docker run -dti --network=host --name storage -e TRACKER_SERVER=192.168.56.1:22122 -v /var/fdfs/storage:/var/fdfs -v /etc/localtime:/etc/localtime delron/fastdfs storage
3、如果ip設(shè)置錯了舞竿,請看下面的步驟
查看當前運行下的鏡像進程
[root@VM-8-7-centos logs]# docker ps -a
停止storage這個鏡像
[root@VM-8-7-centos logs]# docker stop [填寫你的storage的CONTAINER ID]
刪除storage這個鏡像
[root@VM-8-7-centos logs]# docker stop [填寫你的storage的CONTAINER ID]
之后再重新新建
4京景、fastdfs啟動之后的操作
查看可以看到storage、tracker兩個已經(jīng)啟動起來了
[root@VM-8-7-centos logs]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21c94b7f0547 delron/fastdfs "/usr/bin/start1.s..." 8 minutes ago Up 8 minutes storage
bc258c1b3dfd delron/fastdfs "/usr/bin/start1.s..." 8 minutes ago Up 8 minutes tracker
需要重新啟動下
[root@VM-8-7-centos logs]# systemctl restart docker
重新查看下狀態(tài)
[root@VM-8-7-centos logs]# docker status
進入容器查看storage:
[root@VM-8-7-centos logs]# docker exec -it storage /bin/bash
進入到cd /etc/fdfs下的storage.conf
[root@VM-8-7-centos fdfs]# cd /etc/fdfs
[root@VM-8-7-centos fdfs]# pwd
/etc/fdfs
[root@VM-8-7-centos fdfs]# ll
total 88
-rw-rw-r-- 1 root root 1449 Jan 7 03:49 client.conf
-rw-r--r-- 1 root root 1461 Apr 29 2018 client.conf.sample
-rw-r--r-- 1 root root 955 Apr 29 2018 http.conf
-rw-r--r-- 1 root root 31172 Apr 29 2018 mime.types
-rw-r--r-- 1 root root 3677 Jan 7 03:49 mod_fastdfs.conf
-rw-rw-r-- 1 root root 7891 Jan 7 03:49 storage.conf
-rw-r--r-- 1 root root 7927 Apr 29 2018 storage.conf.sample
-rw-rw-r-- 1 root root 105 Apr 29 2018 storage_ids.conf
-rw-r--r-- 1 root root 105 Apr 29 2018 storage_ids.conf.sample
-rw-rw-r-- 1 root root 7307 Apr 29 2018 tracker.conf
-rw-r--r-- 1 root root 7389 Apr 29 2018 tracker.conf.sample
進入storage.conf
[root@VM-8-7-centos fdfs]# vi storage.conf
--------------------------以下是storage.conf文件--------------------------
# is this config file disabled
# false for enabled
# true for disabled
# 這個是要新添加上去的炬灭,其他的不用動
http.server_port=8888
disabled=false
# the name of the group this storage server belongs to
#
# comment or remove this item for fetching from tracker server,
# in this case, use_storage_id must set to true in tracker.conf,
# and storage_ids.conf must be configed correctly.
group_name=group1
# bind an address of this host
# empty for bind all addresses of this host
bind_addr=
# if bind an address of this host when connect to other servers
# (this storage server as a client)
# true for binding the address configed by above parameter: "bind_addr"
# false for binding any address of this host
client_bind=true
......以下省略
--------------------------以上是storage.conf文件--------------------------
5醋粟、配置nginx(進入storage配置),此步驟可以不操作
進入容器查看storage:
[root@VM-8-7-centos logs]# docker exec -it storage /bin/bash
在/usr/local/nginx/conf目錄下重归,修改nginx.conf文件
[root@VM-8-7-centos conf]# cd /usr/local/nginx/conf
--------------------------以下是nginx.conf文件--------------------------
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
--------------------------以上是nginx.conf文件--------------------------
6米愿、激動人心的時刻到了!1撬薄育苟!開始測試上傳文件!W的尽违柏!
使用web模塊進行文件的上傳,將文件上傳至FastDFS文件系統(tǒng)香椎。
將一張照片(logo.png)放置在/var/fdfs/storage目錄下漱竖,進入storage容器,進入/var/fdfs目錄畜伐,運行下面命令:
1馍惹、在宿主機中。
1.1玛界、這個是宿主機万矾,也就是你的服務(wù)器,并不是容器里的目錄
[root@VM-8-7-centos etc]# cd /var/fdfs/storage
1.2慎框、把圖片放在該文件夾下良狈,這里給了一個樣例,logo.png
[root@VM-8-7-centos storage]# ll
總用量 16
drwxr-xr-x 259 root root 4096 1月 7 04:17 data
-rw-r--r-- 1 root root 5386 1月 7 03:45 logo.png
drwxr-xr-x 2 root root 4096 1月 7 04:04 logs
2笨枯、進入進入storage容器薪丁,進入/var/fdfs目錄遇西。
2.1、進入容器查看storage:
[root@VM-8-7-centos logs]# docker exec -it storage /bin/bash
2.2窥突、進入/var/fdfs下
[root@VM-8-7-centos logs]# cd /var/fdfs
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf [你的圖片名稱.后綴名]
[root@VM-8-7-centos fdfs]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf logo.png
group1/M00/00/00/CgAIB1_2HZ2AIebEAAAVCnox6pU455.png
此時將該圖片已上傳至文件系統(tǒng)努溃,并在執(zhí)行該語句后返回圖片存儲的uri:
group1/M00/00/00/CgAIB1_2HZ2AIebEAAAVCnox6pU455.png
通過url訪問:
http://ip:8888/group1/M00/00/00/CgAIB1_2HZ2AIebEAAAVCnox6pU455.png,即可查看到圖片
7阻问、開放端口
firewall-cmd --zone=public --permanent --add-port=8888/tcp
firewall-cmd --zone=public --permanent --add-port=22122/tcp
firewall-cmd --zone=public --permanent --add-port=23000/tcp
重啟防火墻
systemctl restart firewalld
8.開啟啟動容器
docker update --restart=always tracker
docker update --restart=always storage
能夠用得到的一些命令:
docker中 啟動所有的容器命令
[root@VM-8-7-centos logs]# docker start $(docker ps -a | awk '{ print $1}' | tail -n +2)
docker中 關(guān)閉所有的容器命令
[root@VM-8-7-centos logs]# docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2)
docker中 刪除所有的容器命令
[root@VM-8-7-centos logs]# docker rm $(docker ps -a | awk '{ print $1}' | tail -n +2)
docker中 刪除所有的鏡像
[root@VM-8-7-centos logs]# docker rmi $(docker images | awk '{print $3}' |tail -n +2)
文章如果有錯誤梧税,歡迎指正點評~
文章參考來源