这篇文章主要介绍“docker-rancher-k8s-rancher环境怎么搭建”,在日常操作中,相信很多人在docker-rancher-k8s-rancher环境怎么搭建问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”docker-rancher-k8s-rancher环境怎么搭建”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
#在已经安装好docker的rancher-mysql节点操作
#安装mysql
#安装mysql客户端
yum -y install mysql
#创建数据库
mysql -h227.0.0.1 -uroot -p123456 <<-'EOF' create database rancher; EOF
#rancher节点1下操作,换行别忘记在命令行后面增加空格+\
sudo docker run -d --restart=unless-stopped -p 80:8080
-p 9345:9345 rancher/server:v1.6.26
--db-host (数据库IP)
--db-port (数据库端口)
--db-user (数据库账户)
--db-pass (数据库密码)
--db-name rancher (数据库名称)
--advertise-address (节点1内网IP)
#rancher节点2下操作
sudo docker run -d --restart=unless-stopped -p 80:8080
-p 9345:9345 rancher/server:v1.6.26
--db-host (数据库IP)
--db-port (数据库端口)
--db-user (数据库账户)
--db-pass (数据库密码)
--db-name rancher (数据库名称)
--advertise-address (节点2内网IP)
#rancher-proxy负载节点下操作
#创建ngx配置
mkdir -p /data/nginx/conf/vhost.d
#创建nginx.conf
tee /data/nginx/conf/nginx.conf <<-'EOF'
#run user
user www www;
#run work pro
worker_processes 2;
#open file number
worker_rlimit_nofile 65535;
#run pid
pid ./nginx.pid;
events {
worker_connections 65535;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
#gzip
gzip on;
gzip_comp_level 2;
gzip_min_length 1024;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
keepalive_timeout 60;
resolver 8.8.8.8;
access_log off;
#vhost site
include vhost.d/*.conf;
} EOF
#创建[00]0.0.0.0conf
tee /data/nginx/conf/vhost.d/[00]0.0.0.0.conf <<-'EOF'
upstream backend {
#node server ip
server rancher-node1的ip;
server rancher-node2的ip;
}
map $http_upgrade $connection_upgrade {
default Upgrade;
'' close;
}
server {
listen 80;
server_name _;
location / {
proxy_pass http://backend;
# WebScoket Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 900s;
#proxy_set_header Origin xxx;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
} EOF
#拉取基础镜像
docker pull uhub.service.ucloud.cn/pub_snake/pub_centos_ngx_php:v190307001
#运行容器
docker run --name rancher_proxy -dit
-v /data/nginx/conf/nginx.conf:/data/nginx/conf/nginx.conf
-v /data/nginx/conf/vhost.d/[00]0.0.0.0.conf:/data/nginx/conf/vhost.d/[00]0.0.0.0.conf
-p 80:80
uhub.service.ucloud.cn/pub_snake/pub_centos_ngx_php:v190307001
#进入容器
docker exec -it rancher_proxy /bin/bash
#启动容器中的ngx,到此不出意外rancher就可以通过rancher-proxy负载服务的IP直接访问了
/data/nginx/sbin/nginx -c /data/nginx/conf/nginx.conf
到此,关于“docker-rancher-k8s-rancher环境怎么搭建”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注天达云网站,小编会继续努力为大家带来更多实用的文章!