②. nacos集群前置知识点
①. 预计需要,1个nginx+3个nacos注册中心+1个mysql
②. 安装linux环境,安装Jdk1.8、Nginx1.8、Mysql5.7.24、nacos
③. Nacos下载linux版本
链接:https://pan.baidu.com/s/131QEa12Kc1OJa1NYJncZ-g
提取码:1234
将nacos-server-1.1.4.tar.gz上传到/opt下
在/opt下解压: tar -zxvf nacos-server-1.1.4.tar.gz
将解压好的nacos,复制到/usr/local下: cp -rv nacos /usr/local
③. 集群配置步骤
- ①. Linux服务器上mysql数据库配置(nacos-mysql.sql | application.properties)
②. application.properties
spring.datasource.platform=mysql db.num=1 db.url.0=jdbc:mysql://1.7.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true db.user=root db.password=root
- ③. Linux服务器上nacos的集群配置cluster.conf
- 梳理出3台nacos机器的不同服务端口号(3333、4444、5555)
- 复制出cluster.conf
3. 这个IP不能写127.0.0.1,必须是Linux命令hostname -i能够识别的IP
- ④. 编辑Nacos的启动脚本startup.sh,使它能够接受不同的启动端
- /mynacos/nacos/bin目录下有startup.sh
- 修改如下
执行方式如下
查看nacos有多少个节点(ps -ef | grep nacos | grep -v grep|wc -l)
- ④. Nginx的配置,由它作为负载均衡器
- 修改nginx的配置文件
nginx.conf
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream cluster{ server 127.0.0.1:3333; server 127.0.0.1:4444; server 127.0.0.1:5555; } server { listen 1111; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { #root html; #index index.html index.htm; proxy_pass http://cluster; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
按照指定启动
- ⑤. 截止到此处,1个Nginx+3个nacos注册中心+1个mysql
- 测试通过nginx访问nacos(https://写你自己虚拟机的ip:1111/nacos/#/login)
- 新建一个配置测试
linux服务器的mysql插入一条记录
⑥. 测试:输入192.168.68.129:1111/nacos/#/login
⑦. 高可用小总结