- 更新yum,并且更换阿里镜像源
删除yum文件
cd /etc/yum.repos.d/ 进入yum核心目录
ls
sun.repo
rm -rf * 删除之前配置的本地源
ls
配置阿里镜像源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
配置扩展包
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
- 安装jdk8
检索jdk列表
yum list | grep jdk
选择合适的安装
yum install java-1.8.0-openjdk-devel.x86_64
验证
java -version
- 安装宝塔(centos安装脚本)
yum install -y wget && wget -O install.sh https://download.bt.cn/install/install_6.0.sh && sh install.sh ed8484bec
- 使用宝塔安装
mysql、redis、kafka、nacos、nginx
mysql、redis、kafka、nacos
统统不开放外网访问 - 配置
nginx
转发mysql、redis、kafka、nacos
这里的mysql、redis、kafka
与nacos
有所不同
mysql
等服务是tcp
协议,而nacos
是使用的http
协议
user www www;
worker_processes auto;
error_log /www/wwwlogs/nginx_error.log crit;
pid /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
stream {
upstream mysqlProxy {
hash $remote_addr consistent;
server 127.0.0.1:3306 weight=5 max_fails=3 fail_timeout=30s;
}
upstream redisProxy {
hash $remote_addr consistent;
server 127.0.0.1:6379 weight=5 max_fails=3 fail_timeout=30s;
}
upstream kafkaProxy {
hash $remote_addr consistent;
server 127.0.0.1:9092 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 11009;
proxy_connect_timeout 10s;
proxy_timeout 300s;
proxy_pass redisProxy;
}
server {
listen 11008;
proxy_connect_timeout 10s;
proxy_timeout 300s;
proxy_pass mysqlProxy;
}
server {
listen 11007;
proxy_connect_timeout 10s;
proxy_timeout 300s;
proxy_pass kafkaProxy;
}
log_format tcp_format '$time_local|$remote_addr|$protocol|$status|$bytes_sent|$bytes_received|$session_time|$upstream_addr|$upstream_bytes_sent|$upstream_bytes_received|$upstream_connect_time';
access_log /www/wwwlogs/tcp-access.log tcp_format;
error_log /www/wwwlogs/tcp-error.log;
include /www/server/panel/vhost/nginx/tcp/*.conf;
}
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
include mime.types;
include proxy.conf;
lua_package_path "/www/server/nginx/lib/lua/?.lua;;";
default_type application/octet-stream;
server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/json image/jpeg image/gif image/png font/ttf font/otf image/svg+xml application/xml+rss text/x-js;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server_tokens off;
access_log off;
server
{
listen 11005;
# server_name www.test001.com;
location / {
proxy_pass http://127.0.0.1:8848/nacos/;
}
}
server
{
listen 80;
# 这里可以指定每一个块会被那个服务器处理
# server_name 127.0.0.1;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include /www/server/panel/vhost/nginx/*.conf;
}
- 调整
kafka
配置
这样配置是可以将kafka转发到nginx的11007端口
但是在消费的时候会提示连接断开
或者无法获取连接
修改kafka配置文件
listeners
配置kafka
服务的地址
advertised.listeners
配置nginx
转发的地址
listeners=PLAINTEXT://127.0.0.1:9092
# 外部代理地址
advertised.listeners=PLAINTEXT://127.0.0.1:11007
- 编写生产者和消费者测试
补充:有条件的可以把nginx放在公网即可,并且可以利用nginx限制ip