docker 筆記
posted @ 2021-09-22 17:02 楊軍威 閱讀(90) | 評(píng)論 (0) | 編輯 收藏
java學(xué)習(xí)
posted @ 2021-09-22 17:02 楊軍威 閱讀(90) | 評(píng)論 (0) | 編輯 收藏
posted @ 2021-06-01 13:56 楊軍威 閱讀(2928) | 評(píng)論 (0) | 編輯 收藏
posted @ 2021-04-19 09:45 楊軍威 閱讀(559) | 評(píng)論 (0) | 編輯 收藏
如果不配置.gitignore的文件,帶push代碼的時(shí)候就會(huì)把一寫(xiě)不必要的文件push到遠(yuǎn)程倉(cāng)庫(kù),如.idea文件。如果不小心出現(xiàn)此文件在遠(yuǎn)程倉(cāng)庫(kù)可以通過(guò)一下步驟delete此文件:
1.配置.gitignore文件(新建/編輯)
2.將.gitignore文件上傳到遠(yuǎn)程倉(cāng)庫(kù)
3.刪除git的.idea文件
4.同步到遠(yuǎn)程倉(cāng)庫(kù)
完成之后就可以發(fā)現(xiàn)git倉(cāng)庫(kù)中的.idea文件已經(jīng)被刪除,而且之后push代碼也不會(huì)再把.idea文件上傳。
PS:我在使用PyCharm編寫(xiě)python代碼,一般是通過(guò)new -> .ignore file -> .gitignore file
自動(dòng)生成.gitignore文件。
下面是我自己比較常用的.gitignore文件簡(jiǎn)短配置:
posted @ 2021-01-14 15:15 楊軍威 閱讀(185) | 評(píng)論 (0) | 編輯 收藏
posted @ 2020-12-01 10:19 楊軍威 閱讀(280) | 評(píng)論 (0) | 編輯 收藏
posted @ 2020-11-17 10:40 楊軍威 閱讀(131) | 評(píng)論 (0) | 編輯 收藏
posted @ 2020-10-30 16:37 楊軍威 閱讀(89) | 評(píng)論 (0) | 編輯 收藏
1、數(shù)據(jù)庫(kù)配置
首先使用canal需要修改數(shù)據(jù)庫(kù)配置
[mysqld]
log-bin=mysql-bin # 開(kāi)啟
binlog binlog-format=ROW # 選擇 ROW 模式
server_id=1 # 配置 MySQL replaction 需要定義,不要和 canal 的 slaveId 重復(fù)
創(chuàng)建canal數(shù)據(jù)庫(kù)用戶(hù)
CREATE USER canal IDENTIFIED BY 'canal';
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
FLUSH PRIVILEGES;
2、安裝canal
下載:https://github.com/alibaba/canal/releases
解壓(修改版本號(hào)):tar zxvf canal.deployer-1.1.4.tar.gz -C ./canal
配置開(kāi)放服務(wù)器端口:11110、11111、11112
修改canal配置文件(這里設(shè)置了兩個(gè)instance,即兩個(gè)數(shù)據(jù)庫(kù)):
vi canal/conf/canal.properties
canal.destinations = example1,example2
配置instance:
cp -R canal/conf/example conf/example1
mv conf/example conf/example2
第一個(gè)數(shù)據(jù)庫(kù)配置
vi canal/conf/example1/instance.properties
canal.instance.master.address=32.1.2.140:3306
第二個(gè)數(shù)據(jù)庫(kù)配置
vi canal/conf/example2/instance.properties
canal.instance.master.address=32.1.2.140:3307
#如果需要新增一個(gè)instance,只需要修改canal.properties文件,并新增一個(gè)instance配置即可,無(wú)需重啟canal。
運(yùn)行:
sh canal/bin/startup.sh # 查看日志
cat canal/logs/canal/canal
3、Java使用樣例
引入pom依賴(lài),需要與安裝的canal版本一致
<dependencies> <dependency> <groupId>com.alibaba.otter</groupId> <artifactId>canal.client</artifactId> <version>1.1.4</version> </dependency> </dependencies>
示例代碼(異步打印兩個(gè)數(shù)據(jù)庫(kù)的修改內(nèi)容):
package cn.spicybar.dblog; import com.alibaba.otter.canal.client.CanalConnector; import com.alibaba.otter.canal.client.CanalConnectors; import com.alibaba.otter.canal.protocol.CanalEntry.Entry; import com.alibaba.otter.canal.protocol.CanalEntry.EntryType; import com.alibaba.otter.canal.protocol.CanalEntry.RowChange; import com.alibaba.otter.canal.protocol.Message; import java.net.InetSocketAddress; import java.util.List; public class CanalClient { public static void main(String[] args) { new Thread(() -> initConnector("example1")).start(); new Thread(() -> initConnector("example2")).start(); } private static void initConnector(String destination) { CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress("32.1.0.237", 11111), destination, "", ""); try { connector.connect(); connector.subscribe(".*\\..*"); connector.rollback(); while (true) { Message message = connector.getWithoutAck(1000); if (message.getId() != -1 && message.getEntries().size() > 0) { printEntry(message.getEntries()); } connector.ack(message.getId()); } } finally { connector.disconnect(); } } private static void printEntry(List<Entry> entries) { for (Entry entry : entries) { if (entry.getEntryType() == EntryType.TRANSACTIONBEGIN || entry.getEntryType() == EntryType.TRANSACTIONEND) { continue; } try { RowChange rowChange = RowChange.parseFrom(entry.getStoreValue()); System.out.println(rowChange.getSql()); } catch (Exception e) { throw new RuntimeException("ERROR ## parser error, data:" + entry.toString(), e); } } }
posted @ 2020-08-31 10:55 楊軍威 閱讀(671) | 評(píng)論 (0) | 編輯 收藏
public int binarySearch(long value) {
int middle = 0;
int low = 0;
int pow = arr.length;
while(true) {
middle = (pow + low) / 2;
if(arr[middle] == value) {
return middle;
} else if(low > pow) {
return -1;
} else {
if(arr[middle] > value) {
pow = middle - 1;
} else {
low = middle + 1;
}
}
}
}
posted @ 2020-08-07 11:00 楊軍威 閱讀(138) | 評(píng)論 (0) | 編輯 收藏