After installing Docker on raspberry PI, you can use Docker to compile and deploy nacOS services. Nacos is a dynamic service discovery, configuration management and service management platform that is easier to build cloud native applications. It is completely developed based on the Java language and supports Spring applications natively. It is usually used as a registry for microservices.

The goal of this chapter is to run nacOS on Raspberry PI 4B, but unfortunately the arm64 architecture is no longer supported in the official pre-compiled installation package since Nacos 1.1.3, so if you want to run the latest version of Nacos 2.0.3 on raspberry PI, you’ll need to compile it yourself.

Here’s what I did after two weeks of potholes:

1. Prepare the environment

To avoid contaminating the actual Raspberry PI system environment, the entire NACOS compilation needs to take place in a container, starting with a base image container based on the Ubuntu system.

docker run --name temp -d ubuntu:focal /bin/sh -c "while true; do sleep 1; Docker exec -it temp bash #
#The following commands are executed in the container to install system dependencies
apt-get update && apt-get install -y gcc g++ make libc6-dev wget vim unzip
Copy the code

Download Java8 and Maven 3.2.5 that meet the requirements of the lowest version according to the official documents, decompress Java8 to /root/tools/jdk8, and maven to /root/tools/maven, and configure environment variables.

export JAVA_HOME=/root/tools/jdk8
export MAVEN_HOME=/root/tools/maven
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
Copy the code

After the configuration, run the MVN –version command to view the output.

Avoid using the highest version of java17 and maven3.8.4, or you will get a variety of weird errors when compiling nacos.

Install Protobuf

ProtoBuf is a structured data serialization method that is a simple analogy to XML. ProtoBuf is installed mainly for the various header files that are contained in it, and there are dependencies when compiling nacOS.

Wget https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/protobuf-all-3.17.3.tar.gz - O Protobuf-all-3.17.3.tar. gz tar xf protobuf-all-3.17.3.tar.gz CD protobuf-3.17.3./configure --disable-shared make-j4 make installCopy the code

ProtoBuf libraries are installed to /usr/local/lib.

Install grPC-Java

To compile the nacos-consistency component, use protoc-gen-grpc-java. The specified version must be 1.24. However, the 1.24 grPC-Java precompiled package can only run on X86 cpus.

Wget GRPC https://github.com/grpc/grpc-java/archive/refs/tags/v1.24.2.zip - O - Java - v1.24.2. Zip unzip GRPC - Java - v1.24.2.zip CD GRPC - Java - v1.24.2 / compiler.. /gradlew java_pluginExecutableCopy the code

Compiled after the completion of the generated executable file in. / compiler/build/exe/java_plugin/protoc – gen – GRPC – Java, need to install the file to the local maven repository, compile nacos – consistency components will use this package, The installation command is as follows:

Cp/root/downloads/GRPC - Java - 1.24.2 / compiler/build/exe/java_plugin protoc - gen - GRPC - Java /root/downloads/protoc-gen-grpc-java-1.24.0-linux-aarch_64.exe # Copy the compiled executable file MVN install:install-file -dgroupid = IO - DartifactId = protoc - gen - GRPC - Java - Dversion = 1.24.0 - Dclassifier = Linux - aarch_64 - Dpackaging = exe -dfile =/root/downloads/protoc-gen-grpc-java-1.24.0-linux-aarch_64.exe # Install files to the local Maven libraryCopy the code

After completion of execution will be under the local maven repository path generation/root /. M2 / repository/IO/GRPC/protoc – gen – GRPC – Java / 1.24.0 / protoc – gen – GRPC – Java – 1.24.0 – Linux – aarch_64. Exe file. This file ends in exe but does run on Linux with arm64 architecture.

Refer to blog post:

www.cnblogs.com/ghj1976/p/5…

Blog.csdn.net/u013985522/…

Maven package query:

Search.maven.org/artifact/io…

Compile nacos2.0.3

Finally, the most important step is to compile Nacos2.0.3, use wget to download the source code package from the source code download address, and then unzip the package.

Nacos wget https://github.com/alibaba/nacos/archive/refs/tags/2.0.3.tar.gz - O - 2.0.3. Tar. Gz tar xf nacos - 2.0.3. Tar. Gz CD Nacos 2.0.3 /Copy the code

/console/pom. XML file, add version information

2.3.12.release
under

spring-boot-Maven-plugin
, Otherwise, the spring-boot-Maven-plugin will not be found when compiling the nacos-Console component.

Configure maven domestic source, otherwise there may be some dependence lead to download a timeout, maven profile in maven tools the conf directory under the installation path, namely the/root/tools/maven/conf/Settings. The XML file, Add ali’s public Maven library to the

node in this file:

<mirror>
    <id>aliyunmaven</id>
    <mirrorOf>*</mirrorOf>
    <name>aliyunmaven</name>
    <url>https://maven.aliyun.com/repository/public</url>
</mirror>
Copy the code

Save the file, then run the compile command in the nacos source directory:

mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U
Copy the code

Wait for a while (it’s not long, but it took me two weeks !!!!!) Screenshot as a souvenir:

After compiling, the nacOS executable file is located at./distribution/target/. Save the nacos-server-2.0.3.tar.gz file.

No solution for plug-in found:

Stackoverflow website wiki

Packet transmission timeout solution:

Apache Official Configuration Description Ali Cloud public library description

5. Test NACOS

Decompress the compiled NACOS deployment package to /root/tools to start the service

The tar xf. / distribution/target/nacos - server - the 2.0.3. Tar. Gz - C/root/tools/CD/root/tools/nacos/bin/bash startup. Sh - m standaloneCopy the code

According to the prompt to view/root/tools/nacos/logs/start out log output, up to normal boot service without error, log content about the following:

/root/tools/jdk8/bin/java -Djava.ext.dirs=/root/tools/jdk8/jre/lib/ext:/root/tools/jdk8/lib/ext -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xloggc:/root/tools/nacos/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/root/tools/nacos/plugins/health,/root/tools/nacos/plugins/cmdb -Dnacos.home=/root/tools/nacos -jar /root/tools/nacos/target/nacos-server.jar --spring.config.additional-location=file:/root/tools/nacos/conf/ --logging.config=/root/tools/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288 ,--. ,--.'| ,--,: : ` ` - | Nacos 2.0.3. '|' :, -. Running in stand u.s mode, All function modules | : : | | ', '\. -. -. Port: 8848: | \ | : ,--.--. ,---. / / | / / ' Pid: 467815 | : ' '; | / \ \.; . : | : / `. / Console: http://172.17.0.5:8848/nacos/index.html '; .; . -.. -. | / / '| | : : | :; _ | | | \ | \ __ \ / :... '/' |.; : \ \ `. https://nacos.io ' : | ; . ', ". -. | '; : __ | | ` -. \ | | '` -' / /,. | '|', '| \ \ / / / ` --'/' : |. :.' \ : : '----' --'. /; | |. ', . -. / \ \ / ` - '-' '-' ` - ` - '` - 2021-12-08 15:32:42, 094 INFO Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@1ea9f009' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: Not eligible for auto - proxying) 2021-12-08 15:32:42, 127 INFO Bean 'methodSecurityMetadataSource' of the type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: Not eligible for auto-proxying) 2021-12-08 15:32:44,036 INFO Tomcat initialized with port(s): 8848 (HTTP) 2021-12-08 15:32:48,664 INFO Root WebApplicationContext: Initialization Completed in 37406 MS 2021-12-08 15:33:13,997 INFO Initializing orservice 'applicationTaskExecutor' 2021-12-08 15:33:14,832 INFO Adding Welcome Page: Class Path Resource [static/index.html] 2021-12-08 15:33:17,352 INFO Creating Filter chain: Ant [pattern='/**'], [] 2021-12-08 15:33:17,570 INFO Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@6a937336, org.springframework.security.web.context.SecurityContextPersistenceFilter@35f639fa, org.springframework.security.web.header.HeaderWriterFilter@6b69761b, org.springframework.security.web.csrf.CsrfFilter@5c448433, org.springframework.security.web.authentication.logout.LogoutFilter@5d425813, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@6c6333cd, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@8deb645, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@278667fd, org.springframework.security.web.session.SessionManagementFilter@26221bad, Org. Springframework. Security. Web. Access. ExceptionTranslationFilter @ 1 b5c3e5f] 15:33:18 2021-12-08, 283 the INFO the Initializing Open the door to the 2005 2005 edition of the OPERATING system: 2021-12-08 15:33:18,408 INFO Exposing 16 Endpoint (s) : 2021-12-08 15:33:19,047 INFO Tomcat started on port(s): 8848 (HTTP) with context path '/nacos' 2021-12-08 15:33:19,070 INFO nacos started successfully in stand alone mode. Use embedded storageCopy the code

6. Build the mirror

All the above operations are just to get the NACOS-server-2.3.0.tar. gz file available for ARM64 architecture as the deployment package of nacOS service. Using this compiled deployment package to build docker image will not need to compile nacOS from source again. There is no need to re-install and configure maven, Protobuf, grPC-Java dependencies, etc., just a basic Java environment is required.

So, the resources required to build the NACOS :2.0.3 image are roughly as follows.

│ ├─ files │ ├─ EntryPoint_raw.sh # │ ├─ 8U271-Linux-AARCH64.tar. gz # Java Environment │ ├─ installEnV_raw Nacos - server - the 2.0.3. Tar. Gz # nacos service │ └ ─ ─ start_services_raw. Sh # container operation start nacos service ├ ─ ─ nacos - mysql. # nacos SQL database table structure └ ─ ─ Readme. md # Help files 1 Directory, 8 filesCopy the code

Among them, Dockerfile file is a text file used to build nacOS :2.0.3 image, which contains the instructions and instructions required to build the image one by one. Here, it mainly transfers files and executes scripts. The installenv_raw. Sh file is used to install system dependencies and configure Java and nacOS. The entrypoint_raw.sh command is used to render configuration files based on parameters, such as the IP address, port, account, and password of the database, when the container is started. Start_services_raw. sh is used to automatically start the NACOS service after starting the container.

Below is the code for each of the main files.

1. The fileDockerfile
FROM ubuntu:focal
MAINTAINER [email protected]

ADD files/ /tmp/

# remove ^ M
RUN cat /tmp/start_services_raw.sh | tr -d "\r" >> /tmp/start_services.sh
RUN chmod +x /tmp/start_services.sh
RUN cat /tmp/entrypoint_raw.sh | tr -d "\r" >> /tmp/entrypoint.sh
RUN chmod +x /tmp/entrypoint.sh

Clear ^M and execute the installation script
RUN cat /tmp/installenv_raw.sh | tr -d "\r" >> /tmp/installenv.sh
RUN chmod +x /tmp/installenv.sh && /bin/bash /tmp/installenv.sh

EXPOSE 22/tcp
EXPOSE 8848/tcp

CMD is run at docker run time
CMD ["/tmp/start_services.sh"]
ENTRYPOINT ["/tmp/entrypoint.sh"]
Copy the code
2. Install the scriptfiles/installenv_raw.sh
#! /bin/shecho "===========================================" echo -e "`date '+%Y-%m-%d %H:%M:%S'`: \n" apt-get update && apt-get upgrade -y && apt-get -y install locales tzdata vim openssh-sftp-server apt-get clean \n" apt-get update && apt-get upgrade -y && apt-get -y install locales tzdata vim openssh-sftp-server apt-get clean Echo "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" echo - e "` date '+ Y % % m - H: % d % % m: % S' ` : configure the time zone and character set \ n"#The time zone and character set are configured in non-interactive modeExport DEBIAN_FRONTEND = # noninteractive through the environment variable is set to use the interactive mode ln - fs/usr/share/zoneinfo/Asia/Shanghai/etc/localtime && dpkg-reconfigure -f noninteractive tzdata localedef -c -i zh_CN -f UTF-8 zh_CN.UTF-8 echo "===========================================" echo -e "`date '+%Y-%m-%d %H:%M:%S'`: Decompress the project file \n" mkdir -p /root/tools/ tar xf/TMP /nacos-server-2.0.3.tar.gz -c /root/tools/ tar xf Gz -c /root/tools/ mv /root/tools/jdk1.8.0_271 /root/tools/jdk8 rm -rf / TMP/nacos - server - the 2.0.3. Tar. Gz/TMP/JDK - 8 u271 - Linux - aarch64. Tar. Gz echo "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" Echo -e "' date '+%Y-%m-%d %H:% m :%S' : install end \n"Copy the code
3. Scripts related to configuration files and environment variablesfiles/entrypoint_raw.sh
#! /bin/sh

#The DB_CONF variable is used by the sed command. Note that characters such as /:& are escapedDB_CONF="characterEncoding=utf8\&connectTimeout=1000\&socketTimeout=3000\&autoReconnect=true\&useUnicode=true\&useSSL=fa lse\&serverTimezone=UTC"
#The container accepts DB_HOST, DB_PORT, DB_NAME, DB_USER, and DB_PASSWORD as parameters to start the container.
#If all the parameters are present, the configuration file of the NACOS service is updated based on the given parameter values.if [ "$DB_HOST" -a "$DB_PORT" -a "$DB_NAME" -a "$DB_USER" -a "$DB_PASSWORD" ]; Then # this DB_STR variables for the use of the sed command, pay attention to escape / : & characters such as DB_STR = "JDBC \ : mysql \ \ / \ / ${DB_HOST} \ : ${DB_PORT} \ / ${DB_NAME}? ${DB_CONF}" sed -i 's/^# \(spring.datasource.platform=\)/\1/' /root/tools/nacos/conf/application.properties sed -i "s/spring.datasource.platform=.*/spring.datasource.platform=mysql/g" /root/tools/nacos/conf/application.properties sed -i 's/^# \(db.num=\)/\1/' /root/tools/nacos/conf/application.properties sed -i "s/db.num=.*/db.num=1/g" /root/tools/nacos/conf/application.properties sed -i 's/^# \(db.url.0=\)/\1/' /root/tools/nacos/conf/application.properties sed -i "s/db.url.0=.*/db.url.0=${DB_STR}/g" /root/tools/nacos/conf/application.properties sed -i 's/^# \(db.user.0=\)/\1/' /root/tools/nacos/conf/application.properties sed -i "s/db.user.0=.*/db.user.0=${DB_USER}/g" /root/tools/nacos/conf/application.properties sed -i 's/^# \(db.password.0=\)/\1/' /root/tools/nacos/conf/application.properties sed -i "s/db.password.0=.*/db.password.0=${DB_PASSWORD}/g" /root/tools/nacos/conf/application.properties fi exec "$@"Copy the code
4. Service startup scriptfiles/start_services_raw.sh
#! /bin/shExport JAVA_HOME=/root/tools/jdk8 export PATH=$JAVA_HOME/bin:$PATH CD /root/tools/nacos/bin/ bash shutdown.sh # Stop the service Bash startup. Sh -m standalone # in standalone mode to start the service tail - 500 - f/root/tools/nacos/logs/start out # block command, as docker log output of the commandCopy the code
5. nacos-mysql.sqlfile

This file is an official SQL table structure provided by NACOS. It is located in the conf directory of the compilation package and has been extracted for use.

After the preceding resource files are ready, you can run the build command in the directory where the Dockerfile is located. For such time-consuming commands, you are advised to use nohup to suspend the command in the background and redirect the command output to the log file: Nohup docker build -t nacos:2.0.3. &> build.log &, you can run tail -f build.log to view the progress.

After construction, it is recommended to use the Docker save command to save the image. Combined with the XZ compressed image package, it is convenient for transmission and saving.

Docker save -o nacos_arm64_v2.0.3.tar nacos:2.0.3 #Copy the code

The compressed image file size is about 416MB and can be copied to other Linux operating systems based on the arm64 architecture. You only need to run the docker load -i nacos_arm64_v2.0.3.tar.xz command to import the docker image.

7. Start nacOS service

To start nacOS, you need to prepare the database service and create a database and account. Mariadb has been deployed using Docker with IP address 192.168.3.14 and port 3306. In this case, you only need to create an account and a new database.

CREATE DATABASE `nacosdata` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';  /* Create database nacosData, default encoding utf8MB4 */
CREATE USER 'nacos'@'192.168. %' IDENTIFIED BY '* * * * * * * * * * *';  /* Create user */
GRANT USAGE ON *.* TO 'nacos'@'192.168. %';
GRANT ALL PRIVILEGES ON `nacosdata`.* TO 'nacos'@'192.168. %' WITH GRANT OPTION;  /* Assign full permissions to the nacosData library to the user nacos */
--grant all privileges on nacosdata.* to nacos@'%' identified by '*********'; /* * * * * * * * * * * * *
FLUSH PRIVILEGES;  /* Refresh permission Settings */
Copy the code

Log in to the database using the newly created NACOS account. After confirming that the account is available, import the SQL file nacOS-mysql. SQL provided by NACOS, which contains the table structure required by NACOS.

Once the database and data tables are ready, create and start the NACOS container, passing in the above database information as container parameters.

Docker run -d --name work_nacos --restart=always \ -e "DB_HOST=192.168.3.14" -e "DB_PORT=3306" \ -e "DB_NAME=nacosdata" - e "DB_USER = nacos \" e "DB_PASSWORD = * * * * * * * *" -p 2288:8848 nacos: 2.0.3Copy the code

This command takes a period of time. You can run the docker logs work_nacos command to view the logs.

Confirm services can use the browser to http://192.168.3.14:2288/nacos view after normal boot nacos page, the default account and password are nacos, can see the service version 2.0.3 after login.

Attached: extend hand party welfare

All resources required for the content of this article have been uploaded to Baidu web disk, extraction code: 8FRx, please help yourself.