Ubuntu deploys Sonic cloud real machine platform

environment:

Ubuntu 22.04.1 LTS

Sonic version: 2.4.2

jdk:17+

SDK environment

1.Install mysql

update list

sudo apt-get update

Install MySQL service

sudo apt-get install mysql-server

Initialize MySQL configuration

root@iZbp14v3igbgzqxc9il4vsZ:~# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
#是否使用验证密码组件
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: N
#是否修改root密码
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
#是否移除匿名用户
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
#是否禁止root远程登录
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

#是否删除test数据库
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.
#是否重新加载权限
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

Set remote access permissions for root user

root@iZbp14v3igbgzqxc9il4vsZ:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.32-0ubuntu0.22.04.2 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | debian-sys-maint |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
5 rows in set (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Create sonic database

mysql> CREATE DATABASE sonic CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected, 2 warnings (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sonic              |
| sys                |
+--------------------+
5 rows in set (0.01 sec)

2.Install docker

Install the necessary certificates and allow the apt package manager to use the repository over HTTPS using the following command

sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release

Add Docker’s official GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Add Docker official library

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

New Ubuntu source list

sudo apt update

Install the latest Docker CE

sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Check whether docker is installed successfully

root@iZbp14v3igbgzqxc9il4vsZ:~# systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-05-05 17:24:48 CST; 26s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 29393 (dockerd)
      Tasks: 10
     Memory: 25.3M
        CPU: 330ms
     CGroup: /system.slice/docker.service
             └─29393 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

May 05 17:24:47 iZbp14v3igbgzqxc9il4vsZ systemd[1]: Starting Docker Application Container Engine...
May 05 17:24:47 iZbp14v3igbgzqxc9il4vsZ dockerd[29393]: time="2023-05-05T17:24:47.626569902+08:00" level=info msg="Starting up"
May 05 17:24:47 iZbp14v3igbgzqxc9il4vsZ dockerd[29393]: time="2023-05-05T17:24:47.627571744+08:00" level=info msg="detected 127.0.>
May 05 17:24:47 iZbp14v3igbgzqxc9il4vsZ dockerd[29393]: time="2023-05-05T17:24:47.699261043+08:00" level=info msg="Loading contain>
May 05 17:24:47 iZbp14v3igbgzqxc9il4vsZ dockerd[29393]: time="2023-05-05T17:24:47.990848529+08:00" level=info msg="Loading contain>
May 05 17:24:48 iZbp14v3igbgzqxc9il4vsZ dockerd[29393]: time="2023-05-05T17:24:48.005182732+08:00" level=info msg="Docker daemon" >
May 05 17:24:48 iZbp14v3igbgzqxc9il4vsZ dockerd[29393]: time="2023-05-05T17:24:48.005332523+08:00" level=info msg="Daemon has comp>
May 05 17:24:48 iZbp14v3igbgzqxc9il4vsZ systemd[1]: Started Docker Application Container Engine.
May 05 17:24:48 iZbp14v3igbgzqxc9il4vsZ dockerd[29393]: time="2023-05-05T17:24:48.043637879+08:00" level=info msg="API listen on />

Set up startup

sudo systemctl enable docker

3.Install docker compose

Download the corresponding binary file, use xftp to put it in the /usr/local/bin/ directory, and rename it to docker-compose

Releases · docker/compose · GitHub

Give binary files executable permissions

sudo chmod +x /usr/local/bin/docker-compose

Check installed Docker Compose version

root@iZbp14v3igbgzqxc9il4vsZ:~# docker-compose version
Docker Compose version v2.17.2

4. Deploy sonic server

download sonic server

Releases · SonicCloudOrg/sonic-server · GitHub

Modify .env file

SONIC_SERVER_HOST is changed to the local ipv4 address. Since it is deployed using docker, localhost and 127.0.0.1 cannot be used.

MySQL Config is modified to local MySQL configuration

For specific parameters, please refer to the official documentation:

Front-end and back-end deployment | Sonic - open source cloud real machine platform

Upload the modified files to the server using xftp

Enter the sonic root directory and execute the command. The image will be pulled and started for the first time.

docker-compose up -d

Started successfully

 5. Deploy sonic agent

Add an Agent in the platform Agent center and copy the Agent Key 

Download sonic agent: Releases · SonicCloudOrg/sonic-agent · GitHub

Modify/config/application-sonic-agent.yml

 

Execute the modification to utf-8 encoding in the root directory

chcp 65001

 Execute again

java -Dfile.encoding=utf-8 -jar sonic-agent-windows-x86_64.jar

After successful startup, refresh the platform device center and you can see that the device is online and can be used normally.

common problem

1. An error occurs when initializing MySQL to set the password.

Manually configure password:

root@iZbp14v3igbgzqxc9il4vsZ:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.32-0ubuntu0.22.04.2 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)

Re-execute the initialization command

2. Failed to connect to database

2023-05-05 17:55:25.963 -ERROR 1 --- [main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) ~[mysql-connector-j-8.0.32.jar!/:8.0.32]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-j-8.0.32.jar!/:8.0.32]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-j-8.0.32.jar!/:8.0.32]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-j-8.0.32.jar!/:8.0.32]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) ~[mysql-connector-j-8.0.32.jar!/:8.0.32]
	at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:894) ~[mysql-connector-j-8.0.32.jar!/:8.0.32]
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:819) ~[mysql-connector-j-8.0.32.jar!/:8.0.32]
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444) ~[mysql-connector-j-8.0.32.jar!/:8.0.32]
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:237) ~[mysql-connector-j-8.0.32.jar!/:8.0.32]
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-j-8.0.32.jar!/:8.0.32]
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-5.0.1.jar!/:na]
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359) ~[HikariCP-5.0.1.jar!/:na]
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201) ~[HikariCP-5.0.1.jar!/:na]
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470) ~[HikariCP-5.0.1.jar!/:na]
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-5.0.1.jar!/:na]
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:100) ~[HikariCP-5.0.1.jar!/:na]
	

First check whether the root user's host has been changed to "%"

Use the following command to see if you can connect

mysql -h 你的ipv4地址 -u root -p

If an error is reported

ERROR 2003 (HY000): Can't connect to MySQL server on 'ip地址:3306' (111)

Check whether port 3306 is open. As shown in the figure below, it is not open.

root@iZbp14v3igbgzqxc9il4vsZ:/home/sonic-server-v2.4.2# netstat -an| grep 3306
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:33060         0.0.0.0:*               LISTEN 

Modify MySQL configuration file

vim /etc/mysql/mysql.conf.d/mysqld.cnf

Restart mysql service

service mysql restart

 Check port 3306 again and find that it is open

root@iZbp14v3igbgzqxc9il4vsZ:/home/sonic-server-v2.4.2# netstat -an| grep 3306
tcp        0      0 127.0.0.1:33060         0.0.0.0:*               LISTEN     
tcp6       0      0 :::3306                 :::*                    LISTEN 

Connect using ipv4 address, you can already connect

root@iZbp14v3igbgzqxc9il4vsZ:/home/sonic-server-v2.4.2# mysql -h ip地址 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32-0ubuntu0.22.04.2 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Restart docker and it starts normally

Guess you like

Origin blog.csdn.net/y954227239/article/details/130510357