序言
docker是目前輕量級的虛擬化環(huán)境,基于docker的環(huán)境部署罐寨,對于開發(fā)和運維有著重要的意義
- 今后在安裝部署應用的時候靡挥,在單機或集群上部署的應用環(huán)境之間可以相互隔離
- docker鏡像資源非常豐富,今后部署各類中間件衩茸,只需要pull一個docker鏡像芹血,啟動容器即可使用
- 單機搭建集群環(huán)境時,非常節(jié)省資源楞慈,不想安裝虛擬機幔烛,占用cpu、內存和磁盤空間巨大囊蓝,啟動很慢
- portainer鏡像提供了可視化操作docker容器的方式饿悬,使得應用部署的管理和監(jiān)控非常方便
下面按照安裝步驟逐一介紹安裝過程:
安裝centos7 最小化安裝
- 最小安裝centos7 step by step
- root用戶登錄
- ip addr命令查看ip地址
- putty通過ssh以root賬戶登錄
安裝wget
-
yum -y install wget
<font color="red">如果該命令有效,則不需安裝</font>
替換國內yum源
- 進入
/etc/yum.repos.d
目錄下備份原有文件
[root@bogon ~]# cd /etc/yum.repos.d/
[root@bogon yum.repos.d]# mkdir repo_bak
[root@bogon yum.repos.d]# mv *.repo repo_bak/
- 在CentOS中配置使用網(wǎng)易和阿里的開源鏡像
[root@bogon yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
[root@bogon yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@bogon yum.repos.d]# ls
Centos-7.repo CentOS-Base-163.repo repo.bak
- 清除系統(tǒng)yum緩存并生成新的yum緩存
[root@bogon yum.repos.d]# ls # 列出/etc/yum.repos.d/目錄下的文件
Centos-7.repo CentOS-Base-163.repo repo.bak
[root@bogon yum.repos.d]# yum clean all # 清除系統(tǒng)所有的yum緩存
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@bogon yum.repos.d]# yum makecache # 生成yum緩存
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/12): base/7/x86_64/filelists_db | 6.7 MB 00:00:02
(2/12): base/7/x86_64/group_gz | 156 kB 00:00:02
(3/12): base/7/x86_64/other_db | 2.5 MB 00:00:01
(4/12): base/7/x86_64/primary_db | 5.7 MB 00:00:02
(5/12): extras/7/x86_64/prestodelta | 51 kB 00:00:01
(6/12): extras/7/x86_64/filelists_db | 494 kB 00:00:02
(7/12): extras/7/x86_64/other_db | 86 kB 00:00:00
(8/12): extras/7/x86_64/primary_db | 130 kB 00:00:01
(9/12): updates/7/x86_64/prestodelta | 406 kB 00:00:01
(10/12): updates/7/x86_64/filelists_db | 2.1 MB 00:00:01
(11/12): updates/7/x86_64/other_db | 354 kB 00:00:00
(12/12): updates/7/x86_64/primary_db | 3.6 MB 00:00:01
Determining fastest mirrors
Metadata Cache Created
- 安裝epel源
[root@bogon yum.repos.d]# yum list | grep epel-release
[root@bogon yum.repos.d]# yum install -y epel-release
[root@bogon yum.repos.d]# ls # epel源安裝成功聚霜,比原來多了一個epel.repo和epel-testing.repo文件
Centos-7.repo CentOS-Base-163.repo epel.repo epel-testing.repo repo.bak
- 使用阿里開源鏡像提供的epel源
[root@bogon yum.repos.d]# wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo # 下載阿里開源鏡像的epel源文件
[root@localhost yum.repos.d]# ls
CentOS7-Base-163.repo epel-7.repo epel-testing.repo
Centos-7.repo epel.repo repo_bak
- 再次清除系統(tǒng)yum緩存狡恬,并重新生成新的yum緩存
[root@bogon yum.repos.d]# yum clean all # 清除系統(tǒng)所有的yum緩存
[root@bogon yum.repos.d]# yum makecache # 生成yum緩存
安裝Docker-ce
- 安裝依賴庫
# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
- 添加穩(wěn)定版本的 Docker CE yum 源
# yum-config-manager –add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# yum makecache fast
- 安裝 Docker-ce
# yum -y install docker-ce
# service docker start #開啟Docker服務
# 注意:
# 官方軟件源默認啟用了最新的軟件珠叔,您可以通過編輯軟件源的方式獲取各個版本的軟件包。例如官方并沒有將測試版本的軟件源置為可用弟劲,你可以通過以下方式開啟祷安。同理可以開啟各種測試版本等。
# vim /etc/yum.repos.d/docker-ce.repo
# 將 [docker-ce-test] 下方的 enabled=0 修改為 enabled=1
#
# 安裝指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r
# Loading mirror speeds from cached hostfile
# Loaded plugins: branch, fastestmirror, langpacks
# docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
# docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable
# docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
# Available Packages
# Step2 : 安裝指定版本的Docker-CE: (VERSION 例如上面的 17.03.0.ce.1-1.el7.centos)
# sudo yum -y install docker-ce-[VERSION]
# yum
-
配置docker鏡像的國內加速器
寫文件daemon.json兔乞,內容:
{
"registry-mirrors":["https://l10nt4hq.mirror.aliyuncs.com"]
}
將文件拷貝到/etc/docker
目錄下
執(zhí)行命令:
# systemctl daemon-reload
# systemctl restart docker
安裝Portainer
# 下載鏡像
docker pull portainer/portainer
docker run -d -p 9000:9000 --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
--name prtainer-test \
portainer/portainer
瀏覽器通過http://容器所在機器IP地址:9000
訪問即可
效果如下圖:
portainer操作界面