win7搭建centos7搭建docker

1.下载虚拟机:virtualbox,https://www.docker.com/products/docker-toolbox,下载window版本

2.下载centos7,http://www.xitongzhijia.net/linux/201603/69219.html

3.虚拟新建虚拟电脑,一路默认即可,

  选择下载的centos7光盘,如图



 

  选择网络连接方式,如图



 

启动虚拟电脑,centos7,安装一路默认(选择安装位置,设置root密码,选择最小安装)

4.安装docker

 4.1更新yum

yum update

 4.2 添加yum仓库

sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

 4.3 安装docker

yum install docker-engine

 4.4 启动docker

service docker start

 4.5 使用Docker国内镜像(为Docker镜像下载提速,非必须)

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://fe8a7d6e.m.daocloud.io

5.下载tomcat测试互联访问

   安装桥接方式,可以访问互联网,宿主机可以ssh到虚拟电脑

   可以上传下载好的tomcat,解压tar -xzvf apache-tomcat-7.0.73.tar.gz

   运行tomcat

   本机访问,需下载links工具,命令yum install links

   # links



 

 访问正常按q,回车退出

 

也可以查看端口占用情况

查看进程号
# ps -ef|grep tomcat
root      3697  3640 11 09:33 pts/1    00:00:31 java -jar eureka-server-0.0.1-SNAPSHOT.jar
#查看该进程占用端口
# netstat -tupln | grep 2186  
tcp6       0      0 :::1111                 :::*                    LISTEN      3697/java 

6.查看虚拟机ip 

  
[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:95:71:4d brd ff:ff:ff:ff:ff:ff
    inet 10.99.1.52/24 brd 10.99.1.255 scope global dynamic enp0s3
       valid_lft 84762sec preferred_lft 84762sec
    inet6 fe80::9ac:f719:4b3d:7174/64 scope link 
       valid_lft forever preferred_lft forever

可以看出,桥接方式,虚拟机的ip与宿主机(10.99.1.51)属于同一个网段

7.关闭防火墙

  centos7,摒弃了iptables防火墙而使用firewalld防火墙,

关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
其他方式,可以添加端口,这里不详细介绍,可以参考以下命令
查看firewalld状态
firewall-cmd --zone=dmz --add-port=1111/tcp
firewall-cmd --zone=public --add-port=23/tcp --permanent
firewall-cmd --permanent --query-port=1111/tcp
firewall-cmd --zone=public --list-ports

查看iptbales防火墙状态
service iptables status
service iptbales start
service iptables sotp
service iptables restart

 

8.宿主机浏览器(谷歌浏览器,ie内核不行)访问,显示无法连接

查看端口占用情况
netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1437/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2073/master         
tcp6       0      0 :::8080                 :::*                    LISTEN      2186/java           
tcp6       0      0 :::22                   :::*                    LISTEN      1437/sshd           
tcp6       0      0 :::23                   :::*                    LISTEN      1/systemd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2073/master         
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      2186/java           
tcp6       0      0 :::8009                 :::*                    LISTEN      2186/java            

说明已经被占用

 

使用宿主机telnet访问虚拟机,见http://anhongyang125.iteye.com/admin/blogs/2358862,虚拟机也需要安装telnet,见http://anhongyang125.iteye.com/admin/blogs/2358918

 是可以访问的,但是为什么浏览器不能访问呢,多方百度无果,感觉就是dns的事情,再回想桥接方式宿主机与虚拟机属于同一网段,他们的网关相同,但是网关无法解析虚拟机ip,这样浏览器也无法访问

解决方法:建立第二个网卡通过host_only方式连接,这样宿主机和虚拟机之间有一个虚拟网关,它是可以解析虚拟机的ip的

9.host_only连接方式

   9.1 选择虚拟机的全局设置,添加第二个网卡,如图



 记住,这个MAC地址,待会centos中需要使用

  9.2 启动虚拟机,修改网卡信息

  1.查看网卡名称

 # ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       。。。
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:95:71:4d brd ff:ff:ff:ff:ff:ff
    inet 10.99.1.52/24 brd 10.99.1.255 scope global dynamic enp0s3
      。。。
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:c6:ab:db brd ff:ff:ff:ff:ff:ff
    。。。

  9.2 编辑第二个网卡

cp /etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/ifcfg-enp0s8
vi /etc/sysconfig/network-scripts/ifcfg-enp0s8

  只修改HWADDR=上面的MAC地址和NAME=enp0s8

# vi /etc/sysconfig/network-scripts/ifcfg-enp0s8
HWADDR="08:00:27:C6:AB:DB"
TYPE="Ethernet"
BOOTPROTO="dhcp"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="enp0s8"
UUID="05e0c96f-20ed-4d57-aca2-afea38dee461"
ONBOOT="yes"

重启网卡即可:service network restart

9.3 查看ip addr

# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:95:71:4d brd ff:ff:ff:ff:ff:ff
    inet 10.99.1.52/24 brd 10.99.1.255 scope global dynamic enp0s3
       valid_lft 83266sec preferred_lft 83266sec
    inet6 fe80::9ac:f719:4b3d:7174/64 scope link 
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:c6:ab:db brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.101/24 brd 192.168.56.255 scope global dynamic enp0s8
       valid_lft 973sec preferred_lft 973sec
    inet6 fe80::a00:27ff:fec6:abdb/64 scope link 
       valid_lft forever preferred_lft forever

  ip地址已经生效。

10.宿主机浏览器访问http://192.168.56.101:8080/



 

成功!!

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值