搭建基于Docker的MongoDB复制集群环境
一步一步教你搭建基于Docker的MongoDB复制集群环境,Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到
一步一步教你搭建基于Docker的MongoDB复制集群环境
1.安装docker
2.创建MongoDB的Image
3.搭建MongoDB的集群
Docker 是一个开源的应用容器引擎,,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中。
1.Ubuntu14.04安装docker
参考文档
参考文档
linuxidc@linuxidc:~$ wget -qO-https://get.docker.com/ | sh
linuxidc@linuxidc:~$ sudo usermod -aG docker pc
linuxidc@linuxidc:~$ sudo reboot
如果是其他(更早)版本的Linux参考
安装Docker使用apt-get命令:
$ apt-get install docker.io
启动服务和守护进程
$ service docker.io status
$ service docker.io start
创建软连接:ln -sf /usr/bin/docker.io /usr/local/bin/docker
如没有提示错误则说明你已经在Ubuntu14.04上面快速安装Docker成功了。
卸载Uninstallation
$ sudo apt-get purge lxc-docker
To uninstall the Docker package and dependencies that are no longer needed:
$ sudo apt-get autoremove --purge lxc-docker
2.创建MongoDB的Image
linuxidc@linuxidc:~$ docker pull ubuntu:14.04
linuxidc@linuxidc:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 6d4946999d4f 3 weeks ago 188.3 MB
linuxidc@linuxidc:~$
编写dockerfile
linuxidc@linuxidc:~$ vim Dockerfile
Dockerfile内容如下
#VERSION 0.1.0
FROM ubuntu:14.04
#Install some
RUN apt-get clean
RUN apt-get update
RUN apt-get install -y g++
RUN apt-get install -y openssh-server
RUN mkdir -p /var/run/sshd
#open port 22
EXPOSE 22
#CMD ["/usr/sbin/sshd", "-D"]
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
ENV MONGO_MAJOR 3.0
RUN echo "deb wheezy/mongodb-org/$MONGO_MAJOR main" > /etc/apt/sources.list.d/mongodb-org.list
# Install MongoDB
RUN apt-get update
RUN sudo apt-get install -y mongodb-org=3.0.4 mongodb-org-server=3.0.4 mongodb-org-shell=3.0.4 mongodb-org-mongos=3.0.4 mongodb-org-tools=3.0.4
# Create the MongoDB data directory
RUN mkdir -p /data/db
#open port 27017
EXPOSE 27017
ENTRYPOINT ["usr/bin/mongod"]
写好了Dockerfile 就可以生成带有mongodb的image :后面是flag .表示当前路径的Dockerfile
linuxidc@linuxidc:~$ sudo docker build -t pc/mongos:master .
再次查看一下docker image
linuxidc@linuxidc:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
pc/mongod master 6fcc1b62e091 54 minutes ago 542 MB
ubuntu 14.04 6d4946999d4f 4 weeks ago 188.3 MB
3.搭建MongoDB的集群
下面我们就启动3个基于mongod:master的container
linuxidc@linuxidc:~$ sudo docker run --name rs_server1 -p 21117:27017 -d pc/mongod:master --noprealloc --smallfiles --replSet rs1
操作成功之后返回的就是容器的id
6306bf3057f8ebca79d7bd130ba35e260da7177925a85a1c9a3d5d21c551e0aa
后面两个容器同理
linuxidc@linuxidc:~$ sudo docker run --name rs_server2 -p 22117:27017 -d pc/mongod:master --noprealloc --smallfiles --replSet rs1
b60c977313e1b6143c0346e1c6138c3ad4831818f6349fc98181fa76edbd2eff
linuxidc@linuxidc:~$ sudo docker run --name rs_server3 -p 23117:27017 -d pc/mongod:master --noprealloc --smallfiles --replSet rs1
cebebc142a1bfed7162a06441ad841f4173c3f71c97f3dded8d5c3833ea9fa78
选择一个容器执行一下ifconfig 查看ip 一般都是同网段中递增的
linuxidc@linuxidc:~$ sudo docker exec 6306bf3057f8ebca79d7bd130ba35e260da7177925a85a1c9a3d5d21c551e0aa ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:01
inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:acff:fe11:1/64 Scope:Link
UP BROADCAST RUNNING MTU:1500 Metric:1
RX packets:26 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2124 (2.1 KB) TX bytes:828 (828.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
可以想象 3个容器的ip应该是172.17.0.1 172.17.0.2 172.17.0.3

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

InnoDB的全文搜索功能非常强大,能够显着提高数据库查询效率和处理大量文本数据的能力。 1)InnoDB通过倒排索引实现全文搜索,支持基本和高级搜索查询。 2)使用MATCH和AGAINST关键字进行搜索,支持布尔模式和短语搜索。 3)优化方法包括使用分词技术、定期重建索引和调整缓存大小,以提升性能和准确性。

本文讨论了使用MySQL的Alter Table语句修改表,包括添加/删除列,重命名表/列以及更改列数据类型。

全表扫描在MySQL中可能比使用索引更快,具体情况包括:1)数据量较小时;2)查询返回大量数据时;3)索引列不具备高选择性时;4)复杂查询时。通过分析查询计划、优化索引、避免过度索引和定期维护表,可以在实际应用中做出最优选择。

是的,可以在 Windows 7 上安装 MySQL,虽然微软已停止支持 Windows 7,但 MySQL 仍兼容它。不过,安装过程中需要注意以下几点:下载适用于 Windows 的 MySQL 安装程序。选择合适的 MySQL 版本(社区版或企业版)。安装过程中选择适当的安装目录和字符集。设置 root 用户密码,并妥善保管。连接数据库进行测试。注意 Windows 7 上的兼容性问题和安全性问题,建议升级到受支持的操作系统。

聚集索引和非聚集索引的区别在于:1.聚集索引将数据行存储在索引结构中,适合按主键查询和范围查询。2.非聚集索引存储索引键值和数据行的指针,适用于非主键列查询。

文章讨论了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比较了它们对初学者和高级用户的功能和适合性。[159个字符]

本文讨论了使用Drop Table语句在MySQL中放下表,并强调了预防措施和风险。它强调,没有备份,该动作是不可逆转的,详细介绍了恢复方法和潜在的生产环境危害。
