云原生|kubernetes|k8s下部署SQLServer以及Navicat连接SQLServer报错:远程主机强迫关闭了一个现有的连接 错误的解决

本文涉及的产品
RDS SQL Server Serverless,2-4RCU 50GB 3个月
推荐场景:
云数据库 RDS SQL Server,基础系列 2核4GB
容器服务 Serverless 版 ACK Serverless,317元额度 多规格
简介: 云原生|kubernetes|k8s下部署SQLServer以及Navicat连接SQLServer报错:远程主机强迫关闭了一个现有的连接 错误的解决

前言:

SQLServer数据库的部署比较繁琐,但好在有自动化编排系统kubernetes可以帮助我们从这些繁琐的部署中解放。本文在此仅仅做一个抛砖引玉:

1,利用kubernetes集群,快速的搭建一个安全可用的SQLServer,其中SQLServer的数据库文件利用hostpath挂载到本地目录中,使得这个数据库如同运行在本地一样丝滑柔顺。

2,SQLServer服务部署完成后,使用Navicat远程连接此数据库并建立一个测试数据库。

3,深入分析并解决远程连接数据库报远程主机强迫关闭了一个现有的连接,错误代码10054的错误。

一,

secret的建立

考虑到密码还是比较敏感的,因此,将要使用secret文件保存SQLServer的密码,部署secret的文件内容如下:

base64解码,可以看到解码后的MyC0m9l&xP@ssw0rd就是密码。

[root@node3 ~]# echo "MyC0m9l&xP@ssw0rd"|base64
TXlDMG05bCZ4UEBzc3cwcmQK
[root@node3 ~]# echo "TXlDMG05bCZ4UEBzc3cwcmQK"|base64 -d
MyC0m9l&xP@ssw0rd
cat >sqlserver-passwd.yaml <<EOF
apiVersion: v1
data:
  SA_PASSWORD: TXlDMG05bCZ4UEBzc3cwcmQK
kind: Secret
metadata:
  creationTimestamp: null
  name: mssql
  namespace: kube-system
EOF

或者使用命令直接生成:

kubectl create secret generic mssql --from-literal=SA_PASSWORD="MyC0m9l&xP@ssw0rd" -n kube-system -oyaml

二,

部署SQLServer的文件:

此文件是静态pod的格式,仍然使用hostpath形式挂载本地volume,本地路径为 /opt/mssql/data 特别注意,如果pod启动失败很可能是此目录没有权限,此目录可以开放为777权限。此文件使用的是hostNetwork 网络模式,因此,pod的端口是直接在kubernetes节点上,端口为1433。数据库的账号为sa,密码为上面的secret定义的MyC0m9l&xP@ssw0rd

cat >sqlserver.yaml<<EOF 
apiVersion: v1
kind: Pod
metadata:
  name: sqlserver
  labels:
    run: sqlserver
  name: sqlserver
  namespace: kube-system
spec:
  containers:
  - env:
    - name: MSSQL_PID
      value: Developer
    - name: ACCEPT_EULA
      value: "Y"
    - name: SA_PASSWORD
      valueFrom:
        secretKeyRef:
          name: mssql
          key: SA_PASSWORD
    image: mcr.microsoft.com/mssql/server:2019-latest
    imagePullPolicy: IfNotPresent
    livenessProbe:
      tcpSocket:
         port: 1433
      initialDelaySeconds: 15
      periodSeconds: 5
      failureThreshold: 8
    resources:
      requests:
        cpu: 200m
    name: sqlserver
    volumeMounts:
    - mountPath: /var/opt/mssql
      name: mssqldb
      readOnly: false
  dnsPolicy: ClusterFirst
  restartPolicy: Always
  volumes:
  - name: mssqldb
    hostPath:
      path: /opt/mssql/data
      type: DirectoryOrCreate
  hostNetwork: true
  priorityClassName: system-cluster-critical
status: {}
EOF

部署成功后的样子:

[root@node3 mnt]# kubectl get po -n kube-system 
NAME                            READY   STATUS    RESTARTS   AGE
coredns-7ff77c879f-nsj95        1/1     Running   8          4d3h
etcd-node3                      1/1     Running   8          4d3h
kube-apiserver-node3            1/1     Running   8          4d3h
kube-controller-manager-node3   1/1     Running   8          4d3h
kube-flannel-ds-amd64-6cdl5     1/1     Running   9          4d3h
kube-proxy-vdhzr                1/1     Running   8          4d3h
kube-scheduler-node3            1/1     Running   8          4d3h
mysql-node3                     1/1     Running   2          23h
sqlserver                       1/1     Running   0          57m

正确的pod的日志如下;

[root@node3 mnt]# kubectl logs -n kube-system sqlserver 
SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
Your master database file is owned by mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
2022-11-07 11:57:42.47 Server      Setup step is FORCE copying system data file 'C:\templatedata\model_replicatedmaster.mdf' to '/var/opt/mssql/data/model_replicatedmaster.mdf'.
2022-11-07 11:57:42.56 Server      Setup step is FORCE copying system data file 'C:\templatedata\model_replicatedmaster.ldf' to '/var/opt/mssql/data/model_replicatedmaster.ldf'.
2022-11-07 11:57:42.57 Server      Setup step is FORCE copying system data file 'C:\templatedata\model_msdbdata.mdf' to '/var/opt/mssql/data/model_msdbdata.mdf'.
2022-11-07 11:57:42.59 Server      Setup step is FORCE copying system data file 'C:\templatedata\model_msdblog.ldf' to '/var/opt/mssql/data/model_msdblog.ldf'.
2022-11-07 11:57:42.72 Server      Microsoft SQL Server 2019 (RTM-CU18) (KB5017593) - 15.0.4261.1 (X64) 
  Sep 12 2022 15:07:06 
  Copyright (C) 2019 Microsoft Corporation
  Developer Edition (64-bit) on Linux (Ubuntu 20.04.5 LTS) <X64>
2022-11-07 11:57:42.73 Server      UTC adjustment: 0:00
2022-11-07 11:57:42.73 Server      (c) Microsoft Corporation.
2022-11-07 11:57:42.73 Server      All rights reserved.
2022-11-07 11:57:42.73 Server      Server process ID is 372.
2022-11-07 11:57:42.73 Server      Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'.
2022-11-07 11:57:42.74 Server      Registry startup parameters: 
   -d /var/opt/mssql/data/master.mdf
   -l /var/opt/mssql/data/mastlog.ldf
   -e /var/opt/mssql/log/errorlog
2022-11-07 11:57:42.74 Server      SQL Server detected 2 sockets with 2 cores per socket and 2 logical processors per socket, 4 total logical processors; using 4 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
2022-11-07 11:57:42.75 Server      SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2022-11-07 11:57:42.75 Server      Detected 3146 MB of RAM. This is an informational message; no user action is required.
2022-11-07 11:57:42.76 Server      Using conventional memory in the memory manager.
2022-11-07 11:57:42.76 Server      Page exclusion bitmap is enabled.
2022-11-07 11:57:42.80 Server      Buffer pool extension is not supported on Linux platform.
2022-11-07 11:57:42.80 Server      Buffer Pool: Allocating 524288 bytes for 349377 hashPages.
2022-11-07 11:57:43.03 Server      Buffer pool extension is already disabled. No action is necessary.
2022-11-07 11:57:43.42 Server      Successfully initialized the TLS configuration. Allowed TLS protocol versions are ['1.0 1.1 1.2']. Allowed TLS ciphers are ['ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:!DHE-RSA-AES256-GCM-SHA384:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES256-SHA:!DHE-RSA-AES128-SHA'].
2022-11-07 11:57:43.46 Server      Query Store settings initialized with enabled = 1, 
2022-11-07 11:57:43.47 Server      The maximum number of dedicated administrator connections for this instance is '1'
2022-11-07 11:57:43.49 Server      Node configuration: node 0: CPU mask: 0x000000000000000f:0 Active CPU mask: 0x000000000000000f:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
2022-11-07 11:57:43.51 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
2022-11-07 11:57:43.53 Server      In-Memory OLTP initialized on lowend machine.
2022-11-07 11:57:43.58 Server      [INFO] Created Extended Events session 'hkenginexesession'
2022-11-07 11:57:43.58 Server      Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
ForceFlush is enabled for this instance. 
2022-11-07 11:57:43.60 Server      Total Log Writer threads: 2. This is an informational message; no user action is required.
2022-11-07 11:57:43.65 Server      clflush is selected for pmem flush operation.
2022-11-07 11:57:43.67 Server      Software Usage Metrics is disabled.
2022-11-07 11:57:43.73 spid9s      [1]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-11-07 11:57:43.73 spid9s      Starting up database 'master'.
2022-11-07 11:57:43.75 Server      CLR version v4.0.30319 loaded.
ForceFlush feature is enabled for log durability.
2022-11-07 11:57:44.30 spid9s      Resource governor reconfiguration succeeded.
2022-11-07 11:57:44.30 spid9s      SQL Server Audit is starting the audits. This is an informational message. No user action is required.
2022-11-07 11:57:44.31 spid9s      SQL Server Audit has started the audits. This is an informational message. No user action is required.
2022-11-07 11:57:44.42 spid9s      SQL Trace ID 1 was started by login "sa".
2022-11-07 11:57:44.44 spid9s      Server name is 'node3'. This is an informational message only. No user action is required.
2022-11-07 11:57:44.55 spid24s     Always On: The availability replica manager is starting. This is an informational message only. No user action is required.
2022-11-07 11:57:44.56 spid27s     [4]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-11-07 11:57:44.57 spid12s     [32767]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-11-07 11:57:44.57 spid24s     Always On: The availability replica manager is waiting for the instance of SQL Server to allow client connections. This is an informational message only. No user action is required.
2022-11-07 11:57:44.58 spid27s     Starting up database 'msdb'.
2022-11-07 11:57:44.59 spid12s     Starting up database 'mssqlsystemresource'.
2022-11-07 11:57:44.61 spid29s     [5]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-11-07 11:57:44.62 spid29s     Starting up database 'test'.
2022-11-07 11:57:44.63 spid12s     The resource database build version is 15.00.4261. This is an informational message only. No user action is required.
2022-11-07 11:57:44.73 spid22s     A self-generated certificate was successfully loaded for encryption.
2022-11-07 11:57:44.76 spid22s     Server is listening on [ 'any' <ipv6> 1433].
2022-11-07 11:57:44.78 spid22s     Server is listening on [ 'any' <ipv4> 1433].
2022-11-07 11:57:44.79 spid12s     [3]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-11-07 11:57:44.80 spid12s     Starting up database 'model'.
2022-11-07 11:57:44.80 Server      Common language runtime (CLR) functionality initialized.
2022-11-07 11:57:44.81 Server      Server is listening on [ ::1 <ipv6> 1434].
2022-11-07 11:57:44.81 Server      Server is listening on [ 127.0.0.1 <ipv4> 1434].
2022-11-07 11:57:44.82 Server      Dedicated admin connection support was established for listening locally on port 1434.
2022-11-07 11:57:44.84 spid22s     Server is listening on [ ::1 <ipv6> 1431].
2022-11-07 11:57:44.86 spid22s     Server is listening on [ 127.0.0.1 <ipv4> 1431].
2022-11-07 11:57:44.87 spid22s     SQL Server is now ready for client connections. This is an informational message; no user action is required.
2022-11-07 11:57:44.95 spid29s     Parallel redo is started for database 'test' with worker pool size [2].
2022-11-07 11:57:45.08 spid12s     Clearing tempdb database.
2022-11-07 11:57:45.08 spid9s      Parallel redo is shutdown for database 'test' with worker pool size [2].
2022-11-07 11:57:45.40 spid12s     [2]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2022-11-07 11:57:45.41 spid12s     Starting up database 'tempdb'.
2022-11-07 11:57:46.02 spid12s     The tempdb database has 4 data file(s).
2022-11-07 11:57:46.04 spid24s     The Service Broker endpoint is in disabled or stopped state.
2022-11-07 11:57:46.04 spid24s     The Database Mirroring endpoint is in disabled or stopped state.
2022-11-07 11:57:46.05 spid24s     Service Broker manager has started.
2022-11-07 11:57:46.06 spid9s      Recovery is complete. This is an informational message only. No user action is required.
2022-11-07 12:03:11.29 spid58      Attempting to load library 'xplog70.dll' into memory. This is an informational message only. No user action is required.
2022-11-07 12:03:11.35 spid58      Using 'xplog70.dll' version '2019.150.4261' to execute extended stored procedure 'xp_msver'. This is an informational message only; no user action is required.

OK,部署完成后就可以进入Navicat测试环节了。

三,

Navicat测试连接SQLServer

大概说一下本次部署的版本:SQLServer版本为Microsoft SQL Server 2019,Navicat版本为permium 15,而我们要使用Navicat连接SQLServer服务器,需要一个客户端程序,如同Oracle数据库一样。当然,如果会编程,比如,Java程序或者python程序,连接数据库服务器是需要的驱动。

Navicat自己带有此客户端,但它不是默认安装,需要自己点一哈安装,此客户端存放在Navicat的安装目录下。

 

安装这个客户端最好还是使用管理员权限安装,Navicat自带的客户端版本是10,安装完毕后,打开Navicat,按如下填写:

这里报错了,远程主机强迫关闭了一个现有的连接。那么,前面的提示很明显是SQL Server Native Client 10.0,也就是说客户端的版本和服务器端的版本不兼容,两者之间的版本相差太多,OK,重新下载一个客户端即可,下载地址:https://www.microsoft.com/zh-CN/download/details.aspx?id=50402

新的客户端下载完成后,直接管理员权限安装即可,目前的最新版本是12,安装完毕后在Navicat的高级里将可以看到:

在点击测试连接就OK了:

建立数据库:

右键点击Navicat的连接名,库名自定义,剩下的按我的设置,确定即可。

 

SQL预览里有建库语句,可复制下来保存留底:

SQLServer就这样简单的安装完毕了。

相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS&nbsp;SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/sqlserver
目录
相关文章
|
3天前
|
运维 Kubernetes Cloud Native
Kubernetes云原生架构深度解析与实践指南####
本文深入探讨了Kubernetes作为领先的云原生应用编排平台,其设计理念、核心组件及高级特性。通过剖析Kubernetes的工作原理,结合具体案例分析,为读者呈现如何在实际项目中高效部署、管理和扩展容器化应用的策略与技巧。文章还涵盖了服务发现、负载均衡、配置管理、自动化伸缩等关键议题,旨在帮助开发者和运维人员掌握利用Kubernetes构建健壮、可伸缩的云原生生态系统的能力。 ####
|
4天前
|
存储 运维 Kubernetes
云原生之旅:Kubernetes的弹性与可扩展性探索
【10月更文挑战第32天】在云计算的浪潮中,云原生技术以其独特的魅力成为开发者的新宠。本文将深入探讨Kubernetes如何通过其弹性和可扩展性,助力应用在复杂环境中稳健运行。我们将从基础架构出发,逐步揭示Kubernetes集群管理、服务发现、存储机制及自动扩缩容等核心功能,旨在为读者呈现一个全景式的云原生平台视图。
14 1
|
9天前
|
Kubernetes 负载均衡 Cloud Native
云原生应用:Kubernetes在容器编排中的实践与挑战
【10月更文挑战第27天】Kubernetes(简称K8s)是云原生应用的核心容器编排平台,提供自动化、扩展和管理容器化应用的能力。本文介绍Kubernetes的基本概念、安装配置、核心组件(如Pod和Deployment)、服务发现与负载均衡、网络配置及安全性挑战,帮助读者理解和实践Kubernetes在容器编排中的应用。
35 4
|
9天前
|
Kubernetes 监控 Cloud Native
云原生应用:Kubernetes在容器编排中的实践与挑战
【10月更文挑战第26天】随着云计算技术的发展,容器化成为现代应用部署的核心趋势。Kubernetes(K8s)作为容器编排领域的佼佼者,以其强大的可扩展性和自动化能力,为开发者提供了高效管理和部署容器化应用的平台。本文将详细介绍Kubernetes的基本概念、核心组件、实践过程及面临的挑战,帮助读者更好地理解和应用这一技术。
37 3
|
8天前
|
弹性计算 Kubernetes Cloud Native
云原生架构下的微服务设计原则与实践####
本文深入探讨了在云原生环境中,微服务架构的设计原则、关键技术及实践案例。通过剖析传统单体架构面临的挑战,引出微服务作为解决方案的优势,并详细阐述了微服务设计的几大核心原则:单一职责、独立部署、弹性伸缩和服务自治。文章还介绍了容器化技术、Kubernetes等云原生工具如何助力微服务的高效实施,并通过一个实际项目案例,展示了从服务拆分到持续集成/持续部署(CI/CD)流程的完整实现路径,为读者提供了宝贵的实践经验和启发。 ####
|
15天前
|
Kubernetes Cloud Native 持续交付
云端新纪元:云原生技术重塑IT架构####
【10月更文挑战第20天】 本文深入探讨了云原生技术的兴起背景、核心理念、关键技术组件以及它如何引领现代IT架构迈向更高效、灵活与可扩展的新阶段。通过剖析Kubernetes、微服务、Docker等核心技术,本文揭示了云原生架构如何优化资源利用、加速应用开发与部署流程,并促进企业数字化转型的深度实践。 ####
|
2天前
|
Kubernetes Cloud Native 云计算
云原生技术深度解析:重塑企业IT架构的未来####
本文深入探讨了云原生技术的核心理念、关键技术组件及其对企业IT架构转型的深远影响。通过剖析Kubernetes、微服务、容器化等核心技术,本文揭示了云原生如何提升应用的灵活性、可扩展性和可维护性,助力企业在数字化转型中保持领先地位。 ####
|
1天前
|
运维 Cloud Native Devops
云原生架构:重塑企业IT的未来####
随着数字化转型浪潮的汹涌,云原生架构凭借其高度灵活、可扩展和高效的特性,正逐步成为企业IT系统的核心。本文将深入探讨云原生架构的核心要素、技术优势以及如何引领企业实现业务创新与敏捷交付。 ####
|
14天前
|
监控 Cloud Native Java
云原生架构下微服务治理策略与实践####
【10月更文挑战第20天】 本文深入探讨了云原生环境下微服务架构的治理策略,通过分析当前技术趋势与挑战,提出了一系列高效、可扩展的微服务治理最佳实践方案。不同于传统摘要概述内容要点,本部分直接聚焦于治理核心——如何在动态多变的分布式系统中实现服务的自动发现、配置管理、流量控制及故障恢复,旨在为开发者提供一套系统性的方法论,助力企业在云端构建更加健壮、灵活的应用程序。 ####
61 10
|
9天前
|
Kubernetes Cloud Native API
云原生架构下微服务治理的深度探索与实践####
本文旨在深入剖析云原生环境下微服务治理的核心要素与最佳实践,通过实际案例分析,揭示高效、稳定的微服务架构设计原则及实施策略。在快速迭代的云计算领域,微服务架构以其高度解耦、灵活扩展的特性成为众多企业的首选。然而,伴随而来的服务间通信、故障隔离、配置管理等挑战亦不容忽视。本研究聚焦于云原生技术栈如何赋能微服务治理,涵盖容器编排(如Kubernetes)、服务网格(如Istio/Envoy)、API网关、分布式追踪系统等关键技术组件的应用与优化,为读者提供一套系统性的解决方案框架,助力企业在云端构建更加健壮、可维护的服务生态。 ####

热门文章

最新文章

下一篇
无影云桌面