mycat實現mysql基於GITD實現雙主雙從讀寫分離master節點高可用

来源:https://www.cnblogs.com/yeyouqing/archive/2023/05/24/17426909.html
-Advertisement-
Play Games

架構說明 10.0.0.18 master節點和10.0.0.22節點互為主 10.0.0.19 10.0.0.18的slave節點 10.0.0.22 master節點和10.0.0.19節點互為主 10.0.0.24 10.0.0.22的slave節點 10.0.0.23 mycat節點 mys ...


架構說明

10.0.0.18 master節點和10.0.0.22節點互為主
10.0.0.19 10.0.0.18的slave節點
10.0.0.22 master節點和10.0.0.19節點互為主
10.0.0.24 10.0.0.22的slave節點
10.0.0.23 mycat節點
mysql版本8.0.32
系統版本:rocky8.4

mysql主從搭建

#搭建雙主節點
#搭建第一個主10.0.0.18
#註釋掉/etc/my.cnf.d/mysql-server.cnf
cat >/etc/my.cnf.d/mysql-server.cnf<<'EOF'
#
# This group are read by MySQL server.
# Use it for options that only the server (but not clients) should see
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html

# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd

#[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
#log-error=/var/log/mysql/mysqld.log
#pid-file=/run/mysqld/mysqld.pid
#log-bin=/data/mysql/logbin/mysql-bin
EOF

#配置主節點的my.cat配置
cat >/etc/my.cnf<<'EOF'
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
server-id=18
#read-only
general_log
gtid_mode=ON
enforce_gtid_consistency
log-bin=/data/mysql/logbin/mysql-bin
EOF

#創建存放二進位日誌的目錄
mkdir -p /data/mysql/logbin/
chown -R mysql.mysql /data

#啟動資料庫
systemctl enable --now mysqld

#配置賬號和授權
mysql
create user 'repluser'@'10.0.0.%' identified by '123456';
grant replication slave on *.* to 'repluser'@'10.0.0.%';
#創建mycat使用的賬號
create user 'wbiao'@'10.0.0.%' IDENTIFIED BY '123456';
grant ALL ON hellodb.* TO 'wbiao'@'10.0.0.%';

#搭建第二個主10.0.0.22
#註釋掉/etc/my.cnf.d/mysql-server.cnf
cat >/etc/my.cnf.d/mysql-server.cnf<<'EOF'
#
# This group are read by MySQL server.
# Use it for options that only the server (but not clients) should see
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html

# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd

#[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
#log-error=/var/log/mysql/mysqld.log
#pid-file=/run/mysqld/mysqld.pid
#log-bin=/data/mysql/logbin/mysql-bin
EOF

#配置主節點的my.cat配置
cat >/etc/my.cnf<<'EOF'
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
server-id=22
#read-only
general_log
gtid_mode=ON
enforce_gtid_consistency
log-bin=/data/mysql/logbin/mysql-bin
EOF

#創建存放二進位日誌的目錄
mkdir -p /data/mysql/logbin/
chown -R mysql.mysql /data

#啟動資料庫
systemctl enable --now mysqld

#10.0.0.22指向10.0.0.18
執行change master to
CHANGE MASTER TO
MASTER_HOST='10.0.0.18',
MASTER_USER='repluser',
MASTER_PASSWORD='123456',
MASTER_PORT=3306,
MASTER_AUTO_POSITION=1;
#開啟IO線程和SQL線程
start slave;
#檢查狀態
show slave status\G
#檢查
mysql> select user,host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| repluser         | 10.0.0.%  |
| wbiao            | 10.0.0.%  |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
6 rows in set (0.00 sec)


10.0.0.18指向10.0.0.22
執行change master to
CHANGE MASTER TO
MASTER_HOST='10.0.0.22',
MASTER_USER='repluser',
MASTER_PASSWORD='123456',
MASTER_PORT=3306,
MASTER_AUTO_POSITION=1;
#開啟IO線程和SQL線程
start slave;
#檢查狀態
show slave status\G

#配置10.0.0.18的從節點10.0.0.19
#註釋掉/etc/my.cnf.d/mysql-server.cnf
cat >/etc/my.cnf.d/mysql-server.cnf<<'EOF'
#
# This group are read by MySQL server.
# Use it for options that only the server (but not clients) should see
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html

# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd

#[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
#log-error=/var/log/mysql/mysqld.log
#pid-file=/run/mysqld/mysqld.pid
#log-bin=/data/mysql/logbin/mysql-bin
EOF
#配置從節點10.0.0.19的my.cat配置
cat >/etc/my.cnf<<'EOF'
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
server-id=19
read-only
general_log
gtid_mode=ON
enforce_gtid_consistency
log-bin=/data/mysql/logbin/mysql-bin
EOF

#創建存放二進位日誌的目錄
mkdir -p /data/mysql/logbin/
chown -R mysql.mysql /data
#啟動資料庫
systemctl enable --now mysqld

#從節點10.0.0.19執行change master to
CHANGE MASTER TO
MASTER_HOST='10.0.0.18',
MASTER_USER='repluser',
MASTER_PASSWORD='123456',
MASTER_PORT=3306,
MASTER_AUTO_POSITION=1;
#開啟IO線程和SQL線程
start slave;
#檢查狀態
show slave status\G


##配置10.0.0.22的從節點10.0.0.24
#註釋掉/etc/my.cnf.d/mysql-server.cnf
cat >/etc/my.cnf.d/mysql-server.cnf<<'EOF'
#
# This group are read by MySQL server.
# Use it for options that only the server (but not clients) should see
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html

# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd

#[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
#log-error=/var/log/mysql/mysqld.log
#pid-file=/run/mysqld/mysqld.pid
#log-bin=/data/mysql/logbin/mysql-bin
EOF
#配置從節點10.0.0.24的my.cat配置
cat >/etc/my.cnf<<'EOF'
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
server-id=24
read-only
general_log
gtid_mode=ON
enforce_gtid_consistency
log-bin=/data/mysql/logbin/mysql-bin
EOF

#創建存放二進位日誌的目錄
mkdir -p /data/mysql/logbin/
chown -R mysql.mysql /data
#啟動資料庫
systemctl enable --now mysqld

#從節點10.0.0.24執行change master to
CHANGE MASTER TO
MASTER_HOST='10.0.0.22',
MASTER_USER='repluser',
MASTER_PASSWORD='123456',
MASTER_PORT=3306,
MASTER_AUTO_POSITION=1;
#開啟IO線程和SQL線程
start slave;
#檢查狀態
show slave status\G

#10.0.0.18導入hellodb的資料庫
[root@10 ~]# mysql <hellodb_innodb.sql
##檢查狀態
show slave status\G
#所有節點檢查數據
select * from hellodb.students;
#雙主只能對一個主進行寫操作

 mycat搭建10.0.0.23

#安裝java環境
yum -y install java
#創建安裝目錄和解壓
mkdir -p /apps
tar -xf Mycat-server-1.6.7.6-release-20210303094759-linux.tar.gz -C /app
#配置環境變數
[root@10 ~]# echo 'PATH=/apps/mycat/bin:$PATH' > /etc/profile.d/mycat.sh
[root@10 ~]# . /etc/profile.d/mycat.sh
[root@10 ~]# echo $PATH
/apps/mycat/bin:/usr/share/Modules/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

#配置mycat實現讀寫分離主從高可用
#修改schema.xml的配置文件
#balance="2",所有讀操作都隨機的在writeHost、readhost上分發。
#balance="1",全部的readHost與stand by writeHost參與select語句的負載均衡,簡單的說,當雙主雙從模式(M1->S1,M2->S2,並且M1與M2互為主備)
#writeType屬性負載均衡類型,目前的取值有3種:
#1.writeType="0", 所有寫操作發送到配置的第一個writeHost,第一個掛了切到還生存的第二個writeHost,重新啟動後已切換後的為準,切換記錄在配置文件中:dnindex.properties.
#2.writeType="1",所有寫操作都隨機的發送到配置的writeHost,1.5以後廢棄不推薦。
#3.writeType="2",不執行寫操作
[root@10 conf]# cat schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
    <schema name="wbiao" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
    </schema>
    <dataNode name="dn1" dataHost="localhost1" database="hellodb" />
    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
              writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
        <heartbeat>select user()</heartbeat>
        <writeHost host="host1" url="10.0.0.18:3306" user="wbiao" password="123456">
         <readHost host="host2" url="10.0.0.19:3306" user="wbiao" password="123456" />
        </writeHost>
    <writeHost host="host3" url="10.0.0.22:3306" user="wbiao" password="123456">
         <readHost host="host4" url="10.0.0.23:3306" user="wbiao" password="123456" />
        </writeHost>
    </dataHost>
</mycat:schema>


#server.xml配置文件
[root@10 conf]# cat server.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 
    - you may not use this file except in compliance with the License. - You 
    may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 
    - - Unless required by applicable law or agreed to in writing, software - 
    distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
    License for the specific language governing permissions and - limitations 
    under the License. -->
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
    <system>
    <property name="nonePasswordLogin">0</property> <!-- 0為需要密碼登陸、1為不需要密碼登陸 ,預設為0,設置為1則需要指定預設賬戶-->
    <property name="ignoreUnknownCommand">0</property><!-- 0遇上沒有實現的報文(Unknown command:),就會報錯、1為忽略該報文,返回ok報文。
    在某些mysql客戶端存在客戶端已經登錄的時候還會繼續發送登錄報文,mycat會報錯,該設置可以繞過這個錯誤-->
    <property name="useHandshakeV10">1</property>
    <property name="removeGraveAccent">1</property>
    <property name="useSqlStat">0</property>  <!-- 1為開啟實時統計、0為關閉 -->
    <property name="useGlobleTableCheck">0</property>  <!-- 1為開啟全加班一致性檢測、0為關閉 -->
    <property name="sqlExecuteTimeout">300</property>  <!-- SQL 執行超時 單位:秒-->
        <property name="sequenceHandlerType">1</property>
    <!--<property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>
    INSERT INTO `travelrecord` (`id`,user_id) VALUES ('next value for MYCATSEQ_GLOBAL',"xxx");
    -->
    <!--必須帶有MYCATSEQ_或者 mycatseq_進入序列匹配流程 註意MYCATSEQ_有空格的情況-->
    <property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>
    <property name="subqueryRelationshipCheck">false</property> <!-- 子查詢中存在關聯查詢的情況下,檢查關聯欄位中是否有分片欄位 .預設 false -->
    <property name="sequenceHanlderClass">io.mycat.route.sequence.handler.HttpIncrSequenceHandler</property>
      <!--  <property name="useCompression">1</property>--> <!--1為開啟mysql壓縮協議-->
        <!--  <property name="fakeMySQLVersion">5.6.20</property>--> <!--設置模擬的MySQL版本號-->
    <!-- <property name="processorBufferChunk">40960</property> -->
    <!-- 
    <property name="processors">1</property> 
    <property name="processorExecutor">32</property> 
     -->
        <!--預設為type 0: DirectByteBufferPool | type 1 ByteBufferArena | type 2 NettyBufferPool -->
        <property name="processorBufferPoolType">0</property>
        <property name="serverPort">3306</property>
        <!--預設是65535 64K 用於sql解析時最大文本長度 -->
        <!--<property name="maxStringLiteralLength">65535</property>-->
        <!--<property name="sequenceHandlerType">0</property>-->
        <!--<property name="backSocketNoDelay">1</property>-->
        <!--<property name="frontSocketNoDelay">1</property>-->
        <!--<property name="processorExecutor">16</property>-->
        <!--
            <property name="serverPort">8066</property>
            <property name="managerPort">9066</property>
            <property name="idleTimeout">300000</property>
            <property name="authTimeout">15000</property>
            <property name="bindIp">0.0.0.0</property>
            <property name="dataNodeIdleCheckPeriod">300000</property> 5 * 60 * 1000L; //連接空閑檢查
            <property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->
        <!--分散式事務開關,0為不過濾分散式事務,1為過濾分散式事務(如果分散式事務內只涉及全局表,則不過濾),2為不過濾分散式事務,但是記錄分散式事務日誌-->
        <property name="handleDistributedTransactions">0</property>
        
            <!--
            off heap for merge/order/group/limit      1開啟   0關閉
        -->
        <property name="useOffHeapForMerge">0</property>

        <!--
            單位為m
        -->
        <property name="memoryPageSize">64k</property>

        <!--
            單位為k
        -->
        <property name="spillsFileBufferSize">1k</property>

        <property name="useStreamOutput">0</property>

        <!--
            單位為m
        -->
        <property name="systemReserveMemorySize">384m</property>


        <!--是否採用zookeeper協調切換  -->
        <property name="useZKSwitch">false</property>

        <!-- XA Recovery Log日誌路徑 -->
        <!--<property name="XARecoveryLogBaseDir">./</property>-->

        <!-- XA Recovery Log日誌名稱 -->
        <!--<property name="XARecoveryLogBaseName">tmlog</property>-->
        <!--如果為 true的話 嚴格遵守隔離級別,不會在僅僅只有select語句的時候在事務中切換連接-->
        <property name="strictTxIsolation">false</property>
        <!--如果為0的話,涉及多個DataNode的catlet任務不會跨線程執行-->
        <property name="parallExecute">0</property>
        <property name="serverBacklog">2048</property>
    </system>
    
    <!-- 全局SQL防火牆設置 -->
    <!--白名單可以使用通配符%或著*-->
    <!--例如<host host="127.0.0.*" user="root"/>-->
    <!--例如<host host="127.0.*" user="root"/>-->
    <!--例如<host host="127.*" user="root"/>-->
    <!--例如<host host="1*7.*" user="root"/>-->
    <!--這些配置情況下對於127.0.0.1都能以root賬戶登錄-->
    <!--
    <firewall>
       <whitehost>
          <host host="1*7.0.0.*" user="root"/>
       </whitehost>
       <blacklist check="false">
       </blacklist>
    </firewall>
    -->

    <user name="root" defaultAccount="true">
        <property name="password">qwe123</property>
        <property name="schemas">wbiao</property>
        <property name="defaultSchema">wbiao</property>
        <!--No MyCAT Database selected 錯誤前會嘗試使用該schema作為schema,不設置則為null,報錯 -->
        
        <!-- 表級 DML 許可權設置 -->
        <!--         
        <privileges check="false">
            <schema name="wbiao" dml="0110" >
                <table name="tb01" dml="0000"></table>
                <table name="tb02" dml="1111"></table>
            </schema>
        </privileges>        
         -->
    </user>

    <user name="user">
        <property name="password">user</property>
        <property name="schemas">wbiao</property>
        <property name="readOnly">true</property>
        <property name="defaultSchema">wbiao</property>
    </user>

</mycat:server>


#啟動mycat
[root@10 conf]# mycat start
Starting Mycat-server...
監控日誌
[root@10 ~]# tail -F /apps/mycat/logs/wrapper.log
STATUS | wrapper  | 2023/05/24 02:44:41 | <-- Wrapper Stopped
STATUS | wrapper  | 2023/05/24 02:44:45 | --> Wrapper Started as Daemon
STATUS | wrapper  | 2023/05/24 02:44:45 | Launching a JVM...
INFO   | jvm 1    | 2023/05/24 02:44:46 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
INFO   | jvm 1    | 2023/05/24 02:44:46 |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.
INFO   | jvm 1    | 2023/05/24 02:44:46 | 
INFO   | jvm 1    | 2023/05/24 02:44:48 | MyCAT Server startup successfully. see logs in logs/mycat.log

#鏈接測試
[root@10 conf]# mysql -uroot -pqwe123 -h10.0.0.23
#讀測試
mysql> select @@hostname;
+------------+
| @@hostname |
+------------+
| 10.0.0.24  |
+------------+
1 row in set (0.08 sec)

mysql> select @@hostname;
+------------+
| @@hostname |
+------------+
| 10.0.0.22  |
+------------+
1 row in set (0.00 sec)

mysql> select @@hostname;
+------------+
| @@hostname |
+------------+
| 10.0.0.19  |
+------------+
1 row in set (0.01 sec)

mysql> select @@hostname;
+------------+
| @@hostname |
+------------+
| 10.0.0.19  |
+------------+
1 row in set (0.01 sec)

mysql> select @@hostname;
+------------+
| @@hostname |
+------------+
| 10.0.0.24  |
+------------+
1 row in set (0.01 sec

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 在之前較早隨筆中介紹過實現多行表頭的處理,通過手工創建欄位以及映射數據源欄位屬性的方式實現,有些客戶反映是否可以通過代碼方式更方便的創建對應的處理操作,因此本篇隨筆繼續探討這個多行表頭的處理的操作,使用代碼的方式結合擴展函數處理,快速的實現GridControl的多行表頭的處理操作。 ...
  • >依賴註入實現了系統之間、模塊之間和對象之間依賴關係的解耦,基本上是現代應用程式框架必不可少的一個組成部分。 > >ABP的依賴註入系統是基於Microsoft的依賴註入擴展庫(Microsoft.Extensions.DependencyInjection),所以能夠完全相容.net Core中的 ...
  • 目錄 一、yum安裝 二、yum安裝分類 三、yum命令 四、實驗 一、yum安裝 yum:1.基於rpm升級,彌補rpm只能一個一個安裝依賴文件 2.yum可以自動安裝依賴文件。 3.從倉庫中下載包 centos8:使用yum或者dhf(兩種命令格式基本一致,文件格式.rpm) ubuntu:使用 ...
  • 目錄 一、nfs服務 二、nfs優點 三、配置文件 四、共用文件配置過程 五、實驗 1.創建共用文件(兩台終端共用) 一、nfs服務 概念:網路上共用文件系統的協議,運行多個伺服器之間通過網路共用文件和目錄 服務端:將指定目錄標記為共用目錄,服務段有訪問許可權,共用目錄有全部許可權 客戶端:通過nfs協 ...
  • SPI單線半雙工數據收發應用筆記 SPI 介面可以工作在單線半雙工模式,即主設備使用 MOSI 引腳,從設備使用 MISO 引腳進行通訊。CH32V203C8T6 晶元內置兩路 SPI,使用 SPI1 作為主機,SPI2 作為從機,配合 DMA 完成 SPI 介面的單線半雙工通信測試。 查閱應用手冊 ...
  • 目錄 一、ssh概念 二、配置文件 三、ssh組成結構 四、遠程式控制制過程 五、遠程複製 六、配置密鑰 七、wraooers防火牆 一、ssh概念 ssh:一種安全通道協議 功能:1.實現字元界面遠程登錄 2.遠程複製 3.ssh協議是對通信對方的數據傳輸進行加密出來,包括用戶口令(安全性) 4.客戶 ...
  • 目錄 一、文本傳輸協議 二、連接方式 三、程式安裝 四、黑名單和白名單 五、實驗 1.實驗一:匿名用戶下載與上傳 2.實驗二:關閉匿名用戶登錄,允許普通用戶登錄在家目錄上傳和下載 3.實驗三:禁止用戶切換目錄,只能在家目錄操作 4.實驗四:黑名單限制test1登錄 5.實驗五:白名單限制 6.實驗六 ...
  • 常用配置路徑代理映射 http和https 配置nginx路徑下的配置文件:/etc/nginx/conf.d/nginx.conf (每個人的可能不一樣,但是我這個就是yum 直接安裝的) 如下配置 配置http 和 https 、ws 和 wss #自定義配置地址upstream halo { ...
一周排行
    -Advertisement-
    Play Games
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...