appsmith安装好,那就可以看是练练手。
数据当然是来自数据库,那就连接局域网中现成的一台数据库服务器试试,但是连接数据库的时候一直错误。
找到/home/appsmith/backend 目录下的日志,看到了错误:
[root@localhost backend]# ls
backend-29a34aa6233c.log starting_page_init.log
Failed to initialize pool: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]". ClientConnectionId:f04af734-f327-4959-93af-3f6f051284c2
Exception occurred while creating connection pool. One or more arguments in the datasource configuration may be invalid. Please check your datasource configuration.
一阵查询,在微软文档上找到了这个错误描述。
在 encrypt 属性为 true 且 trustServerCertificate 属性为 false 的情况下,如果连接字符串中的服务器名称与 TLS 证书中的服务器名称不符,则会出现以下错误:The driver couldn't establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "java.security.cert.CertificateException: Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization." 。 在版本 7.2 及以上版本中,驱动程序在 TLS 证书的服务器名称最左边的标签中支持通配符模式匹配。
很显然这个回答方向不对,一堆废话,appsmith不至于如此菜!
回头去看appsmith的文档,原来如此!appsmith根本不支持这样的数据库连接方式。本地部署时它连接数据有三种方式:
**********************************
Connect to Local Datasource
This page describes how to connect a database or API that is hosted locally on the same machine as your Appsmith instance.
Datasource on localhost: There are two methods:
1.ngrok(Recommended): To connect to a local datasource on a self-hosted or an Appsmith cloud instance, expose the datasource via ngrok. For directions, see ngrok.
2.host.docker.internal: This method is only for self-hosted users for connecting from the Docker container to a datasource on localhost. This is for development purposes and does not work in a production environment outside of Docker Desktop. For directions, see host.docker.internal.
3.Datasource in Docker container: This guide is only for self-hosted users for connecting to a datasource in a Docker container. For directions, see Datasource in Docker
**********************************
ngrok不喜欢,host.docker.internal我也不喜欢,幸好还有第三种方式,连接另外一个容器中的数据源。
那就开始安装sql server容器。
步骤一.创建数据存储目录,希望创建的数据库文件不要因为删除容器而被失误删除
[root@localhost home]# mkdir /home/sql_db_files
步骤二:下载镜像
[root@localhost home]# docker pull mcr.microsoft.com/mssql/server:2022-latest
步骤三:创建容器
[root@localhost home]# docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=2024@Passw0rd" \
-v /home/sql_db_files:/var/opt/mssql \
-p 1433:1433 --name mssql --hostname mssql2022 \
-e "MSSQL_PID=Express" \
-e "MSSQL_COLLATION=Chinese_PRC_BIN" \
-e "TZ=Asia/Shanghai" \
-d \
mcr.microsoft.com/mssql/server:2022-latest
参数说明:
ACCEPT_EULA confirms your acceptance of the End-User Licensing Agreement.
MSSQL_SA_PASSWORD is the database system administrator (userid = 'sa') password used to connect to SQL Server once the container is running. 这个SA密码必须要符合复杂度要求
MSSQL_PID is the Product ID (PID) or Edition that the container will run with. Acceptable values:
Developer : This will run the container using the Developer Edition (this is the default if no MSSQL_PID environment variable is supplied)
Express : This will run the container using the Express Edition
Standard : This will run the container using the Standard Edition
Enterprise : This will run the container using the Enterprise Edition
EnterpriseCore : This will run the container using the Enterprise Edition Core
步骤四:查看容器安装结果
[root@localhost home]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
19472a5fbb97 mcr.microsoft.com/mssql/server:2022-latest "/opt/mssql/bin/perm…" 45 seconds ago Exited (1) 44 seconds ago mssql
29a34aa6233c appsmith/appsmith-ce "/opt/appsmith/entry…" 7 days ago Up 7 days (healthy) 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp appsmith
ba7d6e626f06 hello-world "/hello" 2 weeks ago Exited (0) 2 weeks ago practical_hofstadter
2948ab27c7ce hello-world "/hello" 2 weeks ago Exited (0) 2 weeks ago cool_ritchie
[root@localhost home]#
看起来不对劲,看看日志,原来处在目录权限上。
[root@localhost docker]# docker logs -f --until=60s mssql
SQL Server 2022 will run as non-root by default.
This container is running as user mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
/opt/mssql/bin/sqlservr: Error: The system directory [/.system] could not be created. File: LinuxDirectory.cpp:420 [Status: 0xC0000022 Access Denied errno = 0xD(13) Permission denied]
修改存放数据目录的权限设置:
[root@localhost docker]# chmod 777 /home/sql_db_files
步骤五: 重新安装容器
[root@localhost docker]# [root@localhost home]# docker run -d --name mssql --hostname mssql\
-v /home/sql_db_files:/var/opt/mssql \
-p 1433:1433 \
-e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=2024@Passw0rd" \
-e "TZ=Asia/Shanghai" \
-e "MSSQL_PID=Express" \
-e "MSSQL_COLLATION=Chinese_PRC_BIN" \
mcr.microsoft.com/mssql/server:2022-latest
docker: Error response from daemon: Conflict. The container name "/mssql" is already in use by container "19472a5fbb977a9b707b6f4b5895d989370b61007f7a9f19f96265ad48c1e2a2". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
刚才没有安装成功导致,那就删除
[root@localhost docker]# docker rm -f mssql
重新再安装后没出错,再查看,终于成功了
不可否认,这Docker安装速度快的要死,比起在操作系统上安装sql server 不知道要快多少倍。
[root@localhost docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b5b29ae870fd mcr.microsoft.com/mssql/server:2022-latest "/opt/mssql/bin/perm…" 25 seconds ago Up 24 seconds 0.0.0.0:1433->1433/tcp, :::1433->1433/tcp mssql
29a34aa6233c appsmith/appsmith-ce "/opt/appsmith/entry…" 7 days ago Up 7 days (healthy) 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp appsmith
ba7d6e626f06 hello-world "/hello" 2 weeks ago Exited (0) 2 weeks ago practical_hofstadter
2948ab27c7ce hello-world "/hello" 2 weeks ago Exited (0) 2 weeks ago cool_ritchie
步骤六:连接数据库,修改sa密码
[root@localhost docker]# docker exec -it mssql "bash"
mssql@mssql2022:/$ /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 2024@Passw0rd
1> alter login sa with password 2025@Passw0rd
2> ;
3> quit
mssql@mssql2022:/$ exit
exit
可以使用sql server 管理控制台成功连接容器中的数据库了,但是在appsmith中连接时没有反应,错误日志为:连接错误
[2024-01-30 00:25:52,186] [email protected], sessionId=b99a2476-5c35-4a71-9e8e-25c9c3292cfa, thread=boundedElastic-38, requestId=ea262c1d-722b-4176-aac7-4b062d7066b6 - Operator called default onErrorDropped
com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException: Exception occurred while creating connection pool. One or more arguments in the datasource configuration may be invalid. Please check your datasource configuration.
看不出所以然, 真是路漫漫啊!