docker-rancher-k8s-rancher环境-2

原创
2019/03/26 13:30
阅读数 692

#在已经安装好docker的rancher-mysql节点操作

#安装mysql,老样子,不放心先下载审阅^ ^,为了方便就用了经典密码123456.

curl http://docker-snake.cn-bj.ufileos.com/install_mysql.sh | bash

#安装mysql客户端

yum -y install mysql

#创建数据库

mysql -h127.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

展开阅读全文
打赏
2
3 收藏
分享
加载中
更多评论
打赏
0 评论
3 收藏
2
分享
返回顶部
顶部