1.環境檢查
[root@xag220 vhosts]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@xag220 vhosts]# java -version;
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
[root@xag220 logs]# hostname -I
10.0.30.220
2.下载nacos
[root@xag220 vhosts]# cd /usr/local/src
wget https://github.com/alibaba/nacos/releases/download/2.0.3/nacos-server-2.0.3.tar.gz
3.安裝
tar -zxvf nacos-server-2.0.3.tar.gz
mv nacos /usr/local/
- 配置启动脚本
[root@xag220 bin]# which javac
/u01/java/jdk1.8.0_181/bin/javac
建立软链接
ln -s /u01/java/jdk1.8.0_181/bin/javac /usr/bin/javac
chmod +x /u01/java/jdk1.8.0_181/bin/javac
5.设置启动项
vim /usr/lib/systemd/system/nacos.service
[Unit]
Description=nacos
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nacos/bin/startup.sh -m standalone
ExecReload=/usr/local/nacos/bin/shutdown.sh
ExecStop=/usr/local/nacos/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
6.配置開機啟動
[root@xag220 bin]# systemctl daemon-reload
[root@xag220 bin]# systemctl is-enabled nacos
disabled
[root@xag220 bin]# systemctl enable nacos.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nacos.service to /usr/lib/systemd/system/nacos.service.
[root@xag220 bin]# systemctl is-enabled nacos
enabled
7.啟動 & 訪問(已安裝完,再後面為高級功能)
[root@xag220 nacos]# systemctl start nacos.service
[root@xag220 nacos]# systemctl status nacos.service
http://10.0.30.220:8848/nacos/
用户名默认:nacos
密码:nacos
- 数据持续化
#创建数据库nacos
create database nacos DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
#创建用户
create user 'nacos'@'%' identified by '123456' PASSWORD EXPIRE NEVER;
grant all privileges on nacos.* to 'nacos'@'%' with grant option;
flush privileges;
#初始化数据库文件
在Nacos的conf目录下找到nacos-mysql.sql文件,在创建的nacos库中执行sql文件
mysql> use nacos;
Database changed
mysql> show tables;
+----------------------+
| Tables_in_nacos |
+----------------------+
| config_info |
| config_info_aggr |
| config_info_beta |
| config_info_tag |
| config_tags_relation |
| group_capacity |
| his_config_info |
| roles |
| tenant_capacity |
| tenant_info |
| users |
+----------------------+
11 rows in set (0.00 sec)
#修改nacos server application.properties配置文件
#修改conf/application.properties文件,增加支持mysql数据源配置(目前只支持mysql),添加mysql数据源的url、用户名和密码
#database mysql 5.x
spring.datasource.platform=mysql
db.num=1
#db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&serverTimezone=UTC
db.user=nacos
db.password=123456
#database mysql 8.x
spring.datasource.platform=mysql
jdbc.DriverClassName=com.mysql.cj.jdbc.Driver
# 指定数据库实例数量
db.num=1
# 第一个数据库实例地址
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?serverTimezone=GMT%2B8&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user= nacos
db.password= 123456
9.1集群配置(3台機器上安裝)
cp cluster.conf.example cluster.conf
vim cluster.conf
* 将自带的几个ip全部注释掉 在下面填写ip地址(不可以填写127.0.0.1),如
192.168.1.101:8848
192.168.1.102:8848
192.168.1.103:8848
將上面啟動項的
ExecStart=/usr/local/nacos/bin/startup.sh -m standalone
改成
ExecStart=/usr/local/nacos/bin/startup.sh
9.2集群配置(1台機器上安裝)
cp cluster.conf.example cluster.conf
vim cluster.conf
* 将自带的几个ip全部注释掉 在下面填写ip地址(不可以填写127.0.0.1),如
10.0.30.220:5555
10.0.30.220:3333
10.0.30.220:4444
9.2.2
修改nacos下bin文件里startup.sh文件
s后面多了一个p
nohup那一行{PORT}
9.2.3 启动nacos集群服务 (注:这里的-P是大写的P,不能再用上面的啟動項啟動,因無配置端口)
./startup.sh -P 5555
./startup.sh -P 3333
./startup.sh -P 4444
10.修改nginx配置文件