dream_653
作者dream_6532019-09-19 15:05
系统应用运维, *****

Rancher搭建

字数 15365阅读 1701评论 0赞 1

Rancher搭建

环境信息:
5台Linux主机
主机情况:
10.181.14.11 Rancher 2核心 8G 100G磁盘
10.181.14.12 node1 8核心 16G 500G
10.181.14.13 node2 8核心 16G 500G
10.181.14.14 node3 8核心 16G 500G
10.181.14.15 node4 8核心 16G 500G

结果大致如下:

Rancher安装如下:
首先需要在所有节点安装Docker环境,咱们安装Docker-ce版本方式如下:下面命令在每个节点上都要安装

yum remove docker docker-client docker-client-latest docker-common \\ docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine -y  
yum install -y yum-utils device-mapper-persistent-data lvm2  
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo  
yum-config-manager --enable docker-ce-edge  
yum  install docker-ce-18.09.0-3.el7.x86_64 -y  
#yum install docker-ce -y#input y  
systemctl start docker  
systemctl enable docker  

安装Rancher,有了环境之后下面一句话搞定。而且将Rancher的数据库落在本地/var/lib/docker-mysql目录,定期备份即可,注意-v -p -d命令的学习

docker run -d -v /var/lib/docker-mysql:/var/lib/mysql --restart=unless-stopped -p 8080:8080 docker.io/rancher/server  

安装完成大致如下:
Rancher-master root@rancher:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/rancher/server latest 9f086c15073d 4 weeks ago 1.08 GB

Rancher-master root@rancher:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3655171be04b docker.io/rancher/server "/usr/bin/entry /u..." 26 seconds ago Up 25 seconds 3306/tcp, 0.0.0.0:8080->8080/tcp elegant_shockley

节点安装如下:注意这里在每个节点安装的时候,只是部分标签的不同,具体命令需要到Rancher后台去生成
sudo docker run -e CATTLE_HOST_LABELS='Rancher=node2'
--rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.11 http://10.181.14.11:8080/v1/scripts/67493BFD2202EE4C638B:1514678400000:Ds6OVDbGaImZeEtuolUpJK25co
具体操作链接http://10.181.14.11:8080/env/1a5/infra/hosts/add?driver=custom

当在所有节点执行完对应的命令之后。 Ranch 集群就搭建完成了了。

Rancher 后台看到如下:


做为一个完整的项目来讲,不建议直接添加容器。建议走应用 -- 服务的方式

【好处,不掉线,自动扩展,支持 Docker 里面的负载均衡】

Rancher 中应用、服务、容器的概念

参考 :

https://blog.csdn.net/CSDN_duomaomao/article/details/76184437

下面举例一个服务的列子, Redis 主从,通过日志能看到配置 OK

 11/20/2018 2:50:26 PM1:C 20 Nov 2018 06:50:26.589 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

11/20/2018 2:50:26 PM1:C 20 Nov 2018 06:50:26.589 # Redis version=5.0.1, bits=64, commit=00000000, modified=0, pid=1, just started

11/20/2018 2:50:26 PM1:C 20 Nov 2018 06:50:26.589 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf

11/20/2018 2:50:26 PM  _._

11/20/2018 2:50:26 PM  _.-``__ ''-._

11/20/2018 2:50:26 PM  _.-``  `.  `_.  ''-._  Redis 5.0.1 (00000000/0) 64 bit

11/20/2018 2:50:26 PM  .-`` .-```.  ```\\/  _.,_ ''-._

11/20/2018 2:50:26 PM (  '  ,  .-`  | `,  )  Running in standalone mode

11/20/2018 2:50:26 PM |`-._`-...-` __...-.``-._|'` _.-'|  Port: 6379

11/20/2018 2:50:26 PM |  `-._  `._  /  _.-'  |  PID: 1

11/20/2018 2:50:26 PM  `-._  `-._  `-./  _.-'  _.-'

11/20/2018 2:50:26 PM |`-._`-._  `-.__.-'  _.-'_.-'|

11/20/2018 2:50:26 PM |  `-._`-._  _.-'_.-'  |  http://redis.io

11/20/2018 2:50:26 PM  `-._  `-._`-.__.-'_.-'  _.-'

11/20/2018 2:50:26 PM |`-._`-._  `-.__.-'  _.-'_.-'|

11/20/2018 2:50:26 PM |  `-._`-._  _.-'_.-'  |

11/20/2018 2:50:26 PM  `-._  `-._`-.__.-'_.-'  _.-'

11/20/2018 2:50:26 PM  `-._  `-.__.-'  _.-'

11/20/2018 2:50:26 PM  `-._  _.-'

11/20/2018 2:50:26 PM  `-.__.-'

11/20/2018 2:50:26 PM

11/20/2018 2:50:26 PM1:M 20 Nov 2018 06:50:26.591 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

11/20/2018 2:50:26 PM1:M 20 Nov 2018 06:50:26.591 # Server initialized

11/20/2018 2:50:26 PM1:M 20 Nov 2018 06:50:26.591 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

11/20/2018 2:50:26 PM1:M 20 Nov 2018 06:50:26.591 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

11/20/2018 2:50:26 PM1:M 20 Nov 2018 06:50:26.591 * Ready to accept connections

日志分段

11/20/2018 2:53:20 PM1:M 20 Nov 2018 06:53:20.750 # Possible SECURITY ATTACK detected. It looks like somebody is sending POST or Host: commands to Redis. This is likely due to an attacker attempting to use Cross Protocol Scripting to compromise your Redis instance. Connection aborted.

11/20/2018 2:57:52 PM1:M 20 Nov 2018 06:57:52.284 * Replica 10.42.63.112:6380 asks for synchronization

11/20/2018 2:57:52 PM1:M 20 Nov 2018 06:57:52.284 * Full resync requested by replica 10.42.63.112:6380

11/20/2018 2:57:52 PM1:M 20 Nov 2018 06:57:52.284 * Starting BGSAVE for SYNC with target: disk

11/20/2018 2:57:52 PM1:M 20 Nov 2018 06:57:52.284 * Background saving started by pid 23

11/20/2018 2:57:52 PM23:C 20 Nov 2018 06:57:52.285 * DB saved on disk

11/20/2018 2:57:52 PM23:C 20 Nov 2018 06:57:52.286 * RDB: 6 MB of memory used by copy-on-write

11/20/2018 2:57:52 PM1:M 20 Nov 2018 06:57:52.337 * Background saving terminated with success

11/20/2018 2:57:52 PM1:M 20 Nov 2018 06:57:52.337 * Synchronization with replica 10.42.63.112:6380 succeeded


redis-server --port 6380 --slaveof 10.42.212.145 6379

可以通过配置文件、启动参数或者命令来新建一个从实例。接下来我们用启动参数的方式

下面是从的日志

11/20/2018 2:57:52 PM1:C 20 Nov 2018 06:57:52.285 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

11/20/2018 2:57:52 PM1:C 20 Nov 2018 06:57:52.285 # Redis version=5.0.1, bits=64, commit=00000000, modified=0, pid=1, just started

11/20/2018 2:57:52 PM1:C 20 Nov 2018 06:57:52.285 # Configuration loaded

11/20/2018 2:57:52 PM  _._

11/20/2018 2:57:52 PM  _.-``__ ''-._

11/20/2018 2:57:52 PM  _.-``  `.  `_.  ''-._  Redis 5.0.1 (00000000/0) 64 bit

11/20/2018 2:57:52 PM  .-`` .-```.  ```\\/  _.,_ ''-._

11/20/2018 2:57:52 PM (  '  ,  .-`  | `,  )  Running in standalone mode

11/20/2018 2:57:52 PM |`-._`-...-` __...-.``-._|'` _.-'|  Port: 6380

11/20/2018 2:57:52 PM |  `-._  `._  /  _.-'  |  PID: 1

11/20/2018 2:57:52 PM  `-._  `-._  `-./  _.-'  _.-'

11/20/2018 2:57:52 PM |`-._`-._  `-.__.-'  _.-'_.-'|

11/20/2018 2:57:52 PM |  `-._`-._  _.-'_.-'  |  http://redis.io

11/20/2018 2:57:52 PM  `-._  `-._`-.__.-'_.-'  _.-'

11/20/2018 2:57:52 PM |`-._`-._  `-.__.-'  _.-'_.-'|

11/20/2018 2:57:52 PM |  `-._`-._  _.-'_.-'  |

11/20/2018 2:57:52 PM  `-._  `-._`-.__.-'_.-'  _.-'

11/20/2018 2:57:52 PM  `-._  `-.__.-'  _.-'

11/20/2018 2:57:52 PM  `-._  _.-'

11/20/2018 2:57:52 PM  `-.__.-'

11/20/2018 2:57:52 PM

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.286 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.286 # Server initialized

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.286 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.286 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.286 * Ready to accept connections

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.286 * Connecting to MASTER 10.42.249.153:6379

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.286 * MASTER <-> REPLICA sync started

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.287 * Non blocking connect for SYNC fired the event.

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.287 * Master replied to PING, replication can continue...

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.287 * Partial resynchronization not possible (no cached master)

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.289 * Full resync from master: 7b6d475b37ddc62c01f937a302a7c9f217832cf3:0

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.341 * MASTER <-> REPLICA sync: receiving 175 bytes from master

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.341 * MASTER <-> REPLICA sync: Flushing old data

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.341 * MASTER <-> REPLICA sync: Loading DB in memory

11/20/2018 2:57:52 PM1:S 20 Nov 2018 06:57:52.341 * MASTER <-> REPLICA sync: Finished with success

后来发现上面的办法比较死板。更好的解决方案如下:


redis-server --port 6380 --slaveof redis-master 6379


查看下


生成的名称如下 :

znzz-redis-master-1

znzz-redis-master-redis-slave-1

查看 master

11/21/2018 9:44:19 AM1:C 21 Nov 2018 01:44:19.195 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

11/21/2018 9:44:19 AM1:C 21 Nov 2018 01:44:19.195 # Redis version=5.0.1, bits=64, commit=00000000, modified=0, pid=1, just started

11/21/2018 9:44:19 AM1:C 21 Nov 2018 01:44:19.195 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf

11/21/2018 9:44:19 AM  _._

11/21/2018 9:44:19 AM  _.-``__ ''-._

11/21/2018 9:44:19 AM  _.-``  `.  `_.  ''-._  Redis 5.0.1 (00000000/0) 64 bit

11/21/2018 9:44:19 AM  .-`` .-```.  ```\\/  _.,_ ''-._

11/21/2018 9:44:19 AM (  '  ,  .-`  | `,  )  Running in standalone mode

11/21/2018 9:44:19 AM |`-._`-...-` __...-.``-._|'` _.-'|  Port: 6379

11/21/2018 9:44:19 AM |  `-._  `._  /  _.-'  |  PID: 1

11/21/2018 9:44:19 AM  `-._  `-._  `-./  _.-'  _.-'

11/21/2018 9:44:19 AM |`-._`-._  `-.__.-'  _.-'_.-'|

11/21/2018 9:44:19 AM |  `-._`-._  _.-'_.-'  |  http://redis.io

11/21/2018 9:44:19 AM  `-._  `-._`-.__.-'_.-'  _.-'

11/21/2018 9:44:19 AM |`-._`-._  `-.__.-'  _.-'_.-'|

11/21/2018 9:44:19 AM |  `-._`-._  _.-'_.-'  |

11/21/2018 9:44:19 AM  `-._  `-._`-.__.-'_.-'  _.-'

11/21/2018 9:44:19 AM  `-._  `-.__.-'  _.-'

11/21/2018 9:44:19 AM  `-._  _.-'

11/21/2018 9:44:19 AM  `-.__.-'

11/21/2018 9:44:19 AM

11/21/2018 9:44:19 AM1:M 21 Nov 2018 01:44:19.197 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

11/21/2018 9:44:19 AM1:M 21 Nov 2018 01:44:19.197 # Server initialized

11/21/2018 9:44:19 AM1:M 21 Nov 2018 01:44:19.197 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

11/21/2018 9:44:19 AM1:M 21 Nov 2018 01:44:19.197 * Ready to accept connections

11/21/2018 9:44:19 AM1:M 21 Nov 2018 01:44:19.202 * Replica 10.42.136.75:6380 asks for synchronization

11/21/2018 9:44:19 AM1:M 21 Nov 2018 01:44:19.202 * Full resync requested by replica 10.42.136.75:6380

11/21/2018 9:44:19 AM1:M 21 Nov 2018 01:44:19.202 * Starting BGSAVE for SYNC with target: disk

11/21/2018 9:44:19 AM1:M 21 Nov 2018 01:44:19.202 * Background saving started by pid 17

11/21/2018 9:44:19 AM17:C 21 Nov 2018 01:44:19.207 * DB saved on disk

11/21/2018 9:44:19 AM17:C 21 Nov 2018 01:44:19.207 * RDB: 2 MB of memory used by copy-on-write

11/21/2018 9:44:19 AM1:M 21 Nov 2018 01:44:19.298 * Background saving terminated with success

11/21/2018 9:44:19 AM1:M 21 Nov 2018 01:44:19.298 * Synchronization with replica 10.42.136.75:6380 succeeded

[root@node2 ~]# telnet 10.42.65.29 6379

Trying 10.42.65.29...

Connected to 10.42.65.29.

Escape character is '^]'.

quit

+OK

Connection closed by foreign host.

查看 slave

11/21/2018 9:44:19 AM1:C 21 Nov 2018 01:44:19.195 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

11/21/2018 9:44:19 AM1:C 21 Nov 2018 01:44:19.195 # Redis version=5.0.1, bits=64, commit=00000000, modified=0, pid=1, just started

11/21/2018 9:44:19 AM1:C 21 Nov 2018 01:44:19.195 # Configuration loaded

11/21/2018 9:44:19 AM _._

11/21/2018 9:44:19 AM _.-``__ ''-._

11/21/2018 9:44:19 AM _.-`` `. `_. ''-._ Redis 5.0.1 (00000000/0) 64 bit

11/21/2018 9:44:19 AM .-`` .-```. ```\\/ _.,_ ''-._

11/21/2018 9:44:19 AM ( ' , .-` | `, ) Running in standalone mode

11/21/2018 9:44:19 AM |`-._`-...-` __...-.``-._|'` _.-'| Port: 6380

11/21/2018 9:44:19 AM | `-._ `._ / _.-' | PID: 1

11/21/2018 9:44:19 AM `-._ `-._ `-./ _.-' _.-'

11/21/2018 9:44:19 AM |`-._`-._ `-.__.-' _.-'_.-'|

11/21/2018 9:44:19 AM | `-._`-._ _.-'_.-' | http://redis.io

11/21/2018 9:44:19 AM `-._ `-._`-.__.-'_.-' _.-'

11/21/2018 9:44:19 AM |`-._`-._ `-.__.-' _.-'_.-'|

11/21/2018 9:44:19 AM | `-._`-._ _.-'_.-' |

11/21/2018 9:44:19 AM `-._ `-._`-.__.-'_.-' _.-'

11/21/2018 9:44:19 AM `-._ `-.__.-' _.-'

11/21/2018 9:44:19 AM `-._ _.-'

11/21/2018 9:44:19 AM `-.__.-'

11/21/2018 9:44:19 AM

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.197 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.197 # Server initialized

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.197 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.197 * Ready to accept connections

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.198 * Connecting to MASTER redis-master:6379

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.201 * MASTER <-> REPLICA sync started

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.201 * Non blocking connect for SYNC fired the event.

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.202 * Master replied to PING, replication can continue...

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.202 * Partial resynchronization not possible (no cached master)

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.203 * Full resync from master: e1e259c2b8e74c71c8a9dcdad2ae362f12751994:0

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.298 * MASTER <-> REPLICA sync: receiving 175 bytes from master

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.298 * MASTER <-> REPLICA sync: Flushing old data

11/21/2018 9:44:19 AM1:S 21 Nov 2018 01:44:19.298 * MASTER <-> REPLICA sync: Loading DB in memory

11/21/2018

 9:44:19 AM1:S

 21 Nov 2018 01:44:19.298 * MASTER <-> REPLICA sync: Finished with success

[root@node2 ~]# telnet 10.42.136.75 6380

Trying 10.42.136.75...

Connected to 10.42.136.75.

Escape character is '^]'.

quit

+OK

Connection closed by foreign host.

有了服务之后现在可以动态扩展服务,比如容器数量的增加,最少保持多少个存活之类。更或者给容器增加负载均衡

举例如下:


重点在于可以将这个负载均衡附加到我们的目标 -- 可选项 - 类似刚才创建的服务之类的。

这样,随着服务的自动扩展负载均衡的配置也能自动发生变化,适配分发请求到后端

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

1

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关问题

X社区推广