Nacos 集群部署
环境说明
主机名 | IP地址 | 角色 | 软件 |
---|---|---|---|
nacos-1 | 192.168.200.13 | nacos, mysql-master | nacos, mysql |
nacos-2 | 192.168.200.14 | nacos, mysql-slave | nacos, mysql |
nacos-3 | 192.168.200.15 | nacos, nginx | nacos, nginx |
预备环境准备
以下操作在所有节点都要执行
所有节点安装 jdk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17# 创建 JDK 安装目录
mkdir /usr/local/java
# 解压压缩包
tar xvf jdk1.8.0_202.tar.gz -C /usr/local/java/
# 配置环境变量
cat > /etc/profile.d/java.sh <<EOF
#!/bin/bash
export JAVA_HOME=/usr/local/java/jdk1.8.0_202
export CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib
export PATH=\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin:\$PATH:$HOME/bin
EOF
# 刷新环境变量
source /etc/profile.d/java.sh所有节点安装部署 maven
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45# 下载 maven 安装包
wget https://dlcdn.apache.org/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz --no-check-certificate
# 解压安装包
mkdir -p /usr/local/maven
tar xvf apache-maven-3.8.5-bin.tar.gz -C /usr/local/maven
# 配置环境变量
cat > /etc/profile.d/maven.sh <<EOF
#!/bin/bash
export MAVEN_HOME=/usr/local/maven/apache-maven-3.8.5
export PATH=\$MAVEN_HOME/bin:\$PATH:$HOME/bin
EOF
# 刷新环境变量
source /etc/profile.d/maven.sh
# 查看 maven 版本信息
mvn -version
# 修改配置文件,在 mirrors 配置里面添加阿里云 maven 仓库
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
<mirror>
# 修改资源保存位置。在 localRepository 下面加入配置
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>/data/maven/repo</localRepository>
... 省略 N 行
# 创建 repo 目录
mkdir /data/maven/repo -p
安装 MySQL 8.x
以下所有操作在 nacos-1 以及 nacos-2 主机上操作
安装 MySQL
卸载自带的 MariaDB
1
2
3
4
5# 查看默认安装的 mariadb
rpm -qa |grep mariadb
# 卸载已安装的
rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps下载 rpm 安装包
1
wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar
安装 MySQL,应当按照 common–>libs–>client–>server 的顺序安装,否则安装过程会提醒依赖顺序,其他的为非必须安装包。
1
2
3
4
5
6
7
8
9
10
11
12
13
14# 解压压缩包
tar xf mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar
# 安装 MySQL
rpm -ivh mysql-community-common-8.0.27-1.el7.x86_64.rpm
rpm -ivh \
mysql-community-libs-compat-8.0.27-1.el7.x86_64.rpm \
mysql-community-libs-8.0.27-1.el7.x86_64.rpm \
mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.27-1.el7.x86_64.rpm创建 MySQL 配置文件 my.cnf,内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102# 备份 my.cnf 文件
cp /etc/my.cnf /etc/my.cnf.bak
# cat /etc/my.cnf
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set = utf8mb4
[mysql]
prompt="MySQL [\\d]> "
no-auto-rehash
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
default_authentication_plugin = mysql_native_password
# 设置数据库不区分大小写
lower_case_table_names = 1
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
collation-server = utf8mb4_0900_ai_ci
skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
binlog_expire_logs_seconds = 604800
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 500M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M创建数据库数据存放目录 /data/mysql
1
mkdir /data/mysql -p
初始化数据库,不区分大小写
1
mysqld --user=mysql --lower_case_table_names=1 --initialize-insecure --basedir=/var/lib/mysql --datadir=/data/mysql
启动 MySQL,并配置开机启动
1
systemctl enable --now mysqld
执行以下命令,对数据库进行安全性设置
1
mysql_secure_installation
配置主从方案参考 MySQL 8.0主从(Master-Slave)配置
配置主从
修改 Master 节点的配置文件
/etc/my.cnf
1
2
3
4# 在 my.cnf 文件中加入如下配置内容,主要注意 server-id 这个参数的值必须是唯一的
[mysqld]
log_bin = mysql-bin
server-id = 1修改 Slave 节点的配置文件
/etc/my.cnf
,1
2
3[mysqld]
log_bin = mysql-bin
server-id = 2 # 注意这个值不要和 master 节点的一样修改完后需要重启 mysqld 服务,否则配置文件不会生效
在 Master 节点创建用于同步的用户
1
2
3
4
5
6
7
8MySQL [(none)]> create user 'repl'@'192.168.200.14' identified with mysql_native_password by 'shkzC123!@#';
Query OK, 0 rows affected (0.00 sec)
MySQL [(none)]> grant replication slave on *.* to 'repl'@'192.168.200.14';
Query OK, 0 rows affected (0.00 sec)
MySQL [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)获取 Master 节点 bin_log 文件名以及 pos 位置
1
2
3
4
5
6
7MySQL [(none)]> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 1855 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)登录 Slave 节点,执行以下命令设置 Master 节点参数
1
2
3
4
5
6
7
8MySQL [(none)]> change master to
master_host='192.168.200.13',
master_user='repl',
master_password='shkzC123!@#',
master_log_file='mysql-bin.000002',
master_log_pos=1855;
Query OK, 0 rows affected, 8 warnings (0.01 sec)查看主从同步状态,在 Slave 节点执行以下命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63MySQL [(none)]> show slave status \G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.200.13
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 1855
Relay_Log_File: nacos-2-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1855
Relay_Log_Space: 156
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.00 sec)开启主从同步,在 Slave 节点执行以下命令
1
2MySQL [(none)]> start slave;
Query OK, 0 rows affected, 1 warning (0.01 sec)再次查看 Slave 状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63MySQL [(none)]> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 192.168.200.13
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 1855
Relay_Log_File: nacos-2-relay-bin.000003
Relay_Log_Pos: 324
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1855
Relay_Log_Space: 714
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 9ae436ba-b5a1-11ec-a0e1-0050563ec15e
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.01 sec)开启主从之后,如果状态如上图所示,那么说明主从信息就已经配置好了。
- 注意:查看状态时,可能会出现 I/O 任务启动失败的情况,即如下错误:
1
Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).
这是因为在 MySQL 主从结构中,从机上的 server_id 和主机上的 server_id 不能相同,我们可以看一下主机上的 server_id 和从机上的 server_id 是否相同。还有就是修改完配置后需要重启 MySQL 服务
安装 nacos
以下操作,未作特别说明的,则需要在所有节点执行
安装配置 nacos
在 GitHub 上下载编译好的 nacos 安装包,下载地址: Release
1
wget https://github.com/alibaba/nacos/releases/download/1.4.3/nacos-server-1.4.3.tar.gz
解压
1
tar xvf nacos-server-1.4.3.tar.gz -C /usr/local/
登录 MySQL Master 节点,执行以下命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17# 创建数据库 nacos_config
create database nacos_config character set utf8 collate utf8_bin;
# 创建用户
create user 'nacos'@'%' identified by '6Siknnr6c~Pa';
# 授权
grant all privileges on nacos_config.* to 'nacos'@'%';
# 刷新权限表
flush privileges;
# 切换数据库
use nacos_config;
# 执行 nacos 初始化数据脚本
source /usr/local/nacos/conf/nacos-mysql.sql;所有节点配置 nacos 后端数据库,在 nacos 的 conf 目录下的 application.properties,添加以下配置
1
2
3
4
5spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://192.168.200.13:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=nacos
db.password.0=6Siknnr6c~Pa配置集群文件,在 nacos 的解压目录
nacos/conf
的目录下,有配置文件cluster.conaf
,请每行配置成 ip:port。1
2
3
4
5
6
7
8
9cd /usr/local/nacos/conf/
# 复制一份 sample 文件作为 nacos 的配置文件
cp cluster.conf.example cluster.conf
# 修改 cluster.conf 文件,添加节点信息,如下:
192.168.200.13:8848
192.168.200.14:8848
192.168.200.15:8848
启动 nacos
手动执行命令启动服务,所有节点执行以下命令
1
2
3
4
5# sh bin/startup.sh
/usr/local/java/jdk1.8.0_202/bin/java -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/nacos/logs/java_heapdump.hprof -XX:-UseLargePages -Dnacos.member.list= -Djava.ext.dirs=/usr/local/java/jdk1.8.0_202/jre/lib/ext:/usr/local/java/jdk1.8.0_202/lib/ext -Xloggc:/usr/local/nacos/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/usr/local/nacos/plugins/health,/usr/local/nacos/plugins/cmdb -Dnacos.home=/usr/local/nacos -jar /usr/local/nacos/target/nacos-server.jar --spring.config.additional-location=file:/usr/local/nacos/conf/ --logging.config=/usr/local/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288
nacos is starting with cluster
nacos is starting,you can check the /usr/local/nacos/logs/start.out查看日志
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21# tailf logs/start.out
2022-04-06 20:50:44,895 INFO Nacos is starting...
2022-04-06 20:50:45,905 INFO Nacos is starting...
2022-04-06 20:50:46,920 INFO Nacos is starting...
2022-04-06 20:50:47,926 INFO Nacos is starting...
2022-04-06 20:50:48,549 INFO Nacos started successfully in cluster mode. use external storage
# tailf /usr/local/nacos/logs/nacos.log
2022-04-06 20:50:40,226 INFO Started Nacos in 15.445 seconds (JVM running for 16.204)
2022-04-06 20:50:40,227 INFO Nacos started successfully in cluster mode. use external storage
2022-04-06 20:50:45,579 INFO Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-04-06 20:50:45,579 INFO Initializing Servlet 'dispatcherServlet'
2022-04-06 20:50:45,607 INFO Completed initialization in 28 ms打开浏览器访问 nacos 页面
http://192.168.200.13:8848/nacos
,默认用户名密码为nacos/nacos
配置 systemd 管理 nacos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29# 添加 nacos 服务运行用户
useradd -s /sbin/nologin -M nacos
# 修改 bin/start.sh 文件。添加 java 环境变量
sed -i '/cygwin=false/i\source /etc/profile.d/java.sh\n' /usr/local/nacos/bin/startup.sh
# 修改 nacos 目录权限
chown -R nacos:nacos /usr/local/nacos
# 创建 service 文件
cat > /usr/lib/systemd/system/nacos.service <<EOF
[Unit]
Description=nacos
After=network.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_202"
Environment="CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib"
ExecStart=/usr/local/nacos/bin/startup.sh
ExecReload=/bin/kill -HUP \$MAINPID
ExecStop=/usr/local/nacos/bin/shutdown.sh
PrivateTmp=true
User=nacos
Group=nacos
[Install]
WantedBy=multi-user.target
EOF启动 nacos 并配置开机启动
1
systemctl enable --now nacos.service
查看服务状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19# systemctl status nacos
● nacos.service - nacos
Loaded: loaded (/usr/lib/systemd/system/nacos.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2022-04-06 21:17:08 CST; 12min ago
CGroup: /system.slice/nacos.service
└─5996 /usr/local/java/jdk1.8.0_202/bin/java -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMe...
Apr 06 21:17:08 nacos-1 systemd[1]: Starting nacos...
Apr 06 21:17:08 nacos-1 systemd[1]: Started nacos.
# ps aux |grep nacos
nacos 5996 3.3 57.8 4420776 1173964 ? Sl 21:17 0:24 /usr/local/java/jdk1.8.0_202/bin/java -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/nacos/logs/java_heapdump.hprof -XX:-UseLargePages -Dnacos.member.list= -Djava.ext.dirs=/usr/local/java/jdk1.8.0_202/jre/lib/ext:/usr/local/java/jdk1.8.0_202/lib/ext -Xloggc:/usr/local/nacos/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/usr/local/nacos/plugins/health,/usr/local/nacos/plugins/cmdb -Dnacos.home=/usr/local/nacos -jar /usr/local/nacos/target/nacos-server.jar --spring.config.additional-location=file:/usr/local/nacos/conf/ --logging.config=/usr/local/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288 nacosnacos
root 6776 0.0 0.0 112808 968 pts/0 R+ 21:29 0:00 grep --color=auto nacos
# netstat -anptl |grep 8848
tcp6 0 0 :::8848 :::* LISTEN 5996/java
tcp6 0 0 192.168.200.13:37558 192.168.200.15:8848 TIME_WAIT -
tcp6 0 0 192.168.200.13:8848 192.168.200.15:42372 ESTABLISHED 5996/java
tcp6 0 0 192.168.200.13:8848 192.168.200.14:59538 ESTABLISHED 5996/java
安装 nginx 并配置负载均衡
在 nacos-3 节点安装 nginx 服务
1
2
3yum install -y nginx
systemctl enable --now nginx修改 nginx 配置文件,添加 nacos 服务文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29# 创建配置文件
cat >/etc/nginx/conf.d/nacos.conf <<EOF
upstream nacos-servers {
server 192.168.200.13:8848;
server 192.168.200.14:8848;
server 192.168.200.15:8848;
}
server {
listen 8088;
server_name _;
location / {
proxy_pass http://nacos-servers/;
proxy_set_header Host \$host:\$server_port;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_ignore_client_abort on;
}
}
EOF
# 检查配置文件是否配置正确
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# 重新加载配置文件
nginx -s reload