[Environmental configuration] Nacos cluster construction

声明: 这篇博客用来记录自己初学Nacos集群配置的过程,踩过一些坑,希望对大家有所帮助!

Software Environment:

  • Linux virtual machine: CentOS 6.5
  • JDK1.8 installation package, mysql 5.7 installation package, nginx installation package, nacos 1.1.4 installation package (here are all linux installation packages)

Installation process

Upload the installation package to linux through tools

What I use here: WinSCP tool
Insert picture description here

JDK 1.8 installation

JDK installation, I will not go into details here, it is too simple, Baidu has a lot!
General steps:

  • Unzip
  • Move the decompressed file to the directory you want to put
  • Configure environment variables in /etc/profile system environment variables

Nginx installation

This can refer to the rookie tutorial, very detailed: https://www.runoob.com/linux/nginx-install-setup.html

Configure proxy nacos cluster

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;
        }
}

Don’t copy the past:
major changes

Insert picture description here

mysql 5.7 installation

I have to talk about this. At first, I thought it was the same as the mysql 5.6 installation tutorial. The result was a problem when I tried it. There are a lot of Baidus, and I usually report an error when I do it.

Installation package download address: http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

General steps

注意:一下命令只是演示,里面出现的文件名,根据你的具体情况而定, 还要注意执行这些命令时在拿个路径下

# 解压
# 我的压缩包都上传到 /usr/local/temp 

# 当前路径:/usr/local/temp
tar -zxvf mysql-5.7.17-linux-glibc2.12-x86_64.tar.gz

# 移动mysql到想放的目录,当然不移动也可以
# 当前路径:/usr/local/temp
mv mysql-5.7.17-linux-glibc2.12-x86_64 /usr/local/mysql

# 切换路径到mysql目录中
cd /usr/local/mysql

# 创建mysql用户和用户组
[root@localhost /]# groupadd mysql
[root@localhost /]# useradd -r -g mysql mysql

# 创建data目录
mkdir /usr/local/mysql/data

# 初始化数据库
[root@localhost /]# cd /usr/local/mysql/bin
[root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

After running the initialization command successfully, the output log is as follows:
Insert picture description here
temporarily save the circled string, which is the temporary login password of the mysql administrator!

Edit the configuration file my.cnf and add the configuration as follows

# 编辑
[root@localhost bin]#  vim /etc/my.cnf

# 配置内容
[mysqld]
datadir=/usr/local/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
lower_case_table_names=1

Start the test

/usr/local/mysql/support-files/mysql.server start

Add soft connection and restart mysql service

[root@localhost /]#  ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 
[root@localhost /]#  ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[root@localhost /]#  service mysql restart

Log in to mysql and change the password (the password is the temporary password generated in step 5)

[root@localhost /]#  mysql -u root -p
Enter password:
mysql>set password for root@localhost = password('yourpass');

Open remote connection

mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;

Set automatic startup

# 将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# 赋予可执行权限
[root@localhost /]# chmod +x /etc/init.d/mysqld
# 添加服务
[root@localhost /]# chkconfig --add mysqld

At this point, the mysql database installation has been completed.

Prepare the data and data sheet needed by Naocs

Here is a bit simpler, use the windows database connection tool to connect, create: nacos_config database, and then execute the nacos-mysql.sql file under the conf under the nacos installation package.

Navicat I use here:
Insert picture description here

Insert picture description here

Finally, run sql (this is also available under the Linux installation package):
Insert picture description here

Installation and configuration of Naocs

# 解压、将解压后的文件copy到 /usr/local/nacos
tar -zxvf nacos-server-1.1.4.tar.gz

mv nacos-server-1.1.4.tar.gz /usr/local/nacos



# 需要修改三个文件

## 第一个:cluster.conf
cd /usr/local/nacos/conf

cp cluster.conf.example cluster.conf

vim cluster.conf

# 将之前的内容全部删除,配置如下,ip为你自己虚拟机的ip
192.168.75.141:3333
192.168.75.141:4444
192.168.75.141:5555


## 第二个,修改application.properties
vim application.properties

# 在最下面加上如下配置
nacos.istio.mcp.server.enabled=false

db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=121891

# 注意这里的密码

## 第三个文件
cd /usr/local/nacos/bin

vim startup.sh

# 找到如下配置修改和我一样
while getopts ":m:f:s:p:" opt
do
    case $opt in
        m)
            MODE=$OPTARG;;
        f)
            FUNCTION_MODE=$OPTARG;;
        s)
            SERVER=$OPTARG;;
        p)
            PORT=$OPTARG;;
        ?)
        echo "Unknown parameter"
        exit 1;;
    esac
done


## 最下面
# start
echo "$JAVA ${JAVA_OPT}" > ${BASE_DIR}/logs/start.out 2>&1 &
nohup $JAVA -Dserver.port=${PORT} ${JAVA_OPT} nacos.nacos >> ${BASE_DIR}/logs/start.out 2>&1 &
echo "nacos is starting,you can check the ${BASE_DIR}/logs/start.out"


## 还有一个地方就是一个坑,本来到这里配置已经完成,但你启动的时候可能有些节点用不了,原因就是配置的java启动参数太大


## 找到如下配置,修改和我一样

JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

This configuration is complete

start up

# 启动nginx
# 启动mysql

# 启动nacos

cd /usr/local/nacos/bin

./startup.sh -p 3333

./startup.sh -p 4444

./startup.sh -p 5555


## 验证
ps -ef|grep nacos|grep -v grep|wc -l

# 如果结果为3这证明启动成功

Three places where the third file is modified:
Insert picture description here

Insert picture description here

Insert picture description here

Finally,
visit on the windows side : 192.168.75.141:1111/nacos

If successful, the login interface of nacos will be displayed

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_42380734/article/details/107752961