當前位置:首頁 » 操作系統 » dht爬蟲源碼

dht爬蟲源碼

發布時間: 2023-03-11 18:24:57

1. python好學嗎

記得剛學Python的時候,幾乎所有人都說Python 簡單易學,而對於編程零基礎,只掌握Word和Excel的人來說,感覺真的好難。

學習之前網上的教材看了,Python的書也看了,包括《核心編程》,公開課也看了,包括萊斯大學和MIT的課。很多知識點,看的時候好像明白了,然後馬上就忘,看了三四遍也記不住。

就算是多練習,多做題,很多題也是照著例題依樣畫葫蘆就能做出來,改動一下就不明白了,感覺還是沒有深入理解。

在網上看,到處都是自學幾個月就很懂瞭然後找到滿意工作的帖子,有沒有人像我一樣覺得很難呢?

有網友點評說:

Python語言本身是比較容易的,樓主說的難應該指programming本身。

不覺得非計算機專業出身就學不好編程,我就是學通信的,學Python全憑興趣。平時用Python干各種臟活累活,數值計算、數據處理、復雜文本處理、資料庫導入導出excel、網上搶票、Web數據抓取、消息推送、DHT網路爬蟲、Kodi插件、Web自動化測試、網盤下載、雲點播。甚至有次日記軟體密碼忘了,都是通過py+autoit暴力破解出來的。

我的win、debian、mac上面一般都會開一兩個ipython,臨時處理各類雜務。簡單來說,Python現在就是我日常生活的一部分。我不是專業程序員,也沒用Python做過什麼大項目,只是每天享受Python帶來的便捷與快樂。

樓主所說的不能深入理解,其實是不願意花時間鑽研。用了十幾年Python,現在也要一直翻看官方文檔和一些第三方mole的文檔,不斷把遇到的問題弄懂弄透,學習不就是這個過程么?

我覺得樓主對Python無愛,對編程無愛,那就沒必要強迫自己填鴨式「學習」了。

另外一個建議,練習時盡量不要後在現有demo基礎上改,從頭開始寫起,遇到問題一個個查清,這樣才能學到東西。

接收到這個小夥伴的答案,我內心開始反思,其實他說得都對的3個點是:

1.其實本身我對編程是不熱愛的,只是因為需要;

2.其實本身我是對Python更上層可以用來做什麼是不清楚的,思維還是在機械的完成一個Python習題;

3.其實我本身對編程的難度是小悄了的,Python簡單是相對於C、java等語言。

說到這里,不知道看到本文的小夥伴有幾個有類似的心理映射,如果你是上面的狀態,那你學習Python一定是難的。

下面我們來看看另外一位學習者的建議:

python是一門簡單易學,容易理解,分分鍾就可以掌握的語言,我也是學了大概一兩個星期吧,就開始做項目了,嘻嘻!!!

這里有一個很嚴重的問題,,我在學python之前,做過3點的C#,一年的php和一年的java!

所以呢,我想說的是,如果你對編程不那麼敏感,就需要時間來彌補了,那些什麼書啊,公開課啊,我覺得都是輔助的,你要是不經歷幾個項目,怎麼知道python為什麼容易學,怎麼知道python好理解,怎麼知道python有哪些超級好用的框架,比如django,tonado之類的。

所以呀,編程沒有捷徑,你甭想通過看。。。就學會,寫起來才是最重要的!

最終通過對學習Python這件事,我總結了幾點關於學習Python的建議,希望跟大家一起分享:

1.編程語言是一回事,但更重要的是編程思想,不要把應試教育的思想帶到這裡面來,並不是所有的知識都能靠「五年高考三年模擬」來掌握;

2.自己找個想用程序解決的任務,然後自己邊學邊完成。

3.沒有編程基礎的人新學一門語言一定一定要有耐心,基礎知識沒有半年以上的學習和練習是很難徹底掌握的,千萬不要圖快,學的太快或許會有一時的成就感,但基礎知識不扎實終將會成為你前進道路上的瓶頸,不僅學新的知識一知半解,工作時也會磕磕絆絆。

4.沒有計算機基礎,不管學什麼語言都會有點吃力的,python語法比較簡單的。

5.現在要做的就是把錯誤犯下100遍,那你就拿下這個Get了!

2. 如何在gluster的源碼中添加自己的xlator

glusterfs中主線為xlator,幾乎每一個大的功能點,或者性能,都可以以xlator形式參與進glusterfs中,那麼xlator的開發就必不可少,所以,這里介紹一下簡單的向glusterfs中增加xlator的方法,首先創建一個卷testvol
[root@CM addxlator]# mkdir /opt/test
[root@CM addxlator]# gluster volume create testvol 192.168.0.194:/opt/test force
volume create: testvol: success: please start the volume to access data
[root@CM addxlator]# gluster volume info all

Volume Name: testvol
Type: Distribute
Volume ID: f0ef2a09-09c0-4a84-aeb6-3f2e0aebf4c2
Status: Created
Number of Bricks: 1
Transport-type: tcp
Bricks:
Brick1: 192.168.0.194:/opt/test
[root@CM addxlator]#
[root@CM addxlator]# gluster volume start testvol force
volume start: testvol: success
[root@CM addxlator]#

創建成功後,可以查看volume file中的內容
cat /var/lib/glusterd/vols/testvol/testvol-fuse.vol
volume testvol-client-0
type protocol/client
option transport-type tcp
option remote-subvolume /opt/test
option remote-host 192.168.0.194
end-volume

volume testvol-dht
type cluster/distribute
subvolumes testvol-client-0
end-volume

volume testvol-write-behind
type performance/write-behind
subvolumes testvol-dht
end-volume

volume testvol-read-ahead
type performance/read-ahead
subvolumes testvol-write-behind
end-volume

volume testvol-io-cache
type performance/io-cache
subvolumes testvol-read-ahead
end-volume

volume testvol-quick-read
type performance/quick-read
subvolumes testvol-io-cache
end-volume

volume testvol-open-behind
type performance/open-behind
subvolumes testvol-quick-read
end-volume

volume testvol-md-cache
type performance/md-cache
subvolumes testvol-open-behind
end-volume

volume testvol
type debug/io-stats
option count-fop-hits off
option latency-measurement off
subvolumes testvol-md-cache
end-volume

這個配置為默認的配置,接下來需要將自己的xlator增加入該配置中,根據之前所提到過的xlator_dyload的過程,需要修改這個volume file,來增加xlator,修改配置如下:
volume testvol-client-0
type protocol/client
option transport-type tcp
option remote-subvolume /opt/test
option remote-host 192.168.0.194
end-volume

volume testvol-dht
type cluster/distribute
subvolumes testvol-client-0
end-volume

volume testvol-write-behind
type performance/write-behind
subvolumes testvol-dht
end-volume

volume testvol-read-ahead
type performance/read-ahead
subvolumes testvol-write-behind
end-volume

volume testvol-io-cache
type performance/io-cache
subvolumes testvol-read-ahead
end-volume

volume testvol-quick-read
type performance/quick-read
subvolumes testvol-io-cache
end-volume

volume testvol-open-behind
type performance/open-behind
subvolumes testvol-quick-read
end-volume

volume testvol-md-cache
type performance/md-cache
subvolumes testvol-open-behind
end-volume volume testvol-test
type debug/test
subvolumes testvol-md-cache
end-volume volume testvol
type debug/io-stats
option count-fop-hits off
option latency-measurement off
subvolumes testvol-test
end-volume

可以看到,配置中多了個testvol-test這么一層,接下來將glusterfs掛載至掛載點查看輸出log
[root@CM addxlator]#
[root@CM addxlator]# mount -t glusterfs 192.168.0.194:testvol /media
[root@CM addxlator]#
查看gluster掛載到的掛載點對應的log輸出信息
cat /usr/local/var/log/glusterfs/media.log
[2013-06-10 11:00:29.899440] I [glusterfsd.c:1878:main] 0-/usr/local/sbin/glusterfs: Started running /usr/local/sbin/glusterfs version 3git (/usr/local/sbin/glusterfs --volfile-id=testvol --volfile-server=192.168.0.194 /media)
[2013-06-10 11:00:29.903627] I [socket.c:3515:socket_init] 0-glusterfs: SSL support is NOT enabled
[2013-06-10 11:00:29.903823] I [socket.c:3530:socket_init] 0-glusterfs: using system polling thread
[2013-06-10 11:00:29.909423] E [test.c:54:init] 0-testvol-test: test translator loaded
[2013-06-10 11:00:29.909718] I [dht-shared.c:311:dht_init_regex] 0-testvol-dht: using regex rsync-hash-regex = ^\.(.+)\.[^.]+$
[2013-06-10 11:00:29.911047] I [socket.c:3515:socket_init] 0-testvol-client-0: SSL support is NOT enabled
[2013-06-10 11:00:29.911173] I [socket.c:3530:socket_init] 0-testvol-client-0: using system polling thread
[2013-06-10 11:00:29.911218] I [client.c:2236:notify] 0-testvol-client-0: parent translators are ready, attempting connect on transport
Final graph:
經過查看log,可以看到test模塊中的列印輸出, in test translator lookup
接下來查看描述一下外掛xlator的方式
首先現在glusterfs的源代碼,編譯以後,在本地也就存在了glusterfs的開發環境,為了開發調試方便,可暫不將xlator存於glusterfs工程中,這時可以編寫一個Makefile
首先建立一個目錄
mkdir addxlator_sample
cd addxlator_sample
Makefile中內容可如下:
#Add translator into glusterfs volume file
#Author Steven Liu
#E-mail [email protected]
#Blog: http://blog.fs-linux.org

TARGET = test.so
OBJECTS = test.o

GLUSTERFS_SRC = /opt/glusterfs
GLUSTERFS_LIB = /usr/local/lib
HOST_OS = HF_LINUX_HOST_OS

CFLAGS = -fPIC -Wall -O0 -g \
-DHAVE_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D$(HOST_OS) \
-I$(GLUSTERFS_SRC) -I$(GLUSTERFS_SRC)/libglusterfs/src \
-I$(GLUSTERFS_SRC)/contrib/uuid

LDFLAGS = -shared -nostartfiles -L$(GLUSTERFS_LIB) -lglusterfs -lpthread

$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) $(LDFLAGS) -o $(TARGET)

clean:
rm -rf $(TARGET) $(OBJECTS)
Makefile編寫完成之後,需要OBJECTS,這時需要編寫test.c來保證編譯通過,當然,test這個xlator也需要在這里生成
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#include "xlator.h"
#endif

#include <fnmatch.h>
#include <errno.h>
#include "glusterfs.h"
#include "xlator.h"
#include <stdarg.h>
#include "defaults.h"
#include "logging.h"

int test_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
inode_t *inode, struct iatt *buf,
dict_t *xdata, struct iatt *postparent)
{
STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf, xdata,
postparent);
return 0;
}

static int test_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
gf_log(this->name, GF_LOG_ERROR, "in test translator lookup");
STACK_WIND (frame, test_lookup_cbk,
FIRST_CHILD(this), FIRST_CHILD(this)->fops->lookup,
loc, xdata);
return 0;
}

static int test_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
gf_log(this->name, GF_LOG_ERROR, "in test translator stat");
return 0;
}

int
reconfigure (xlator_t *this, dict_t *options)
{
return 0;
}

int
init (xlator_t *this)
{
struct ios_conf *conf = NULL;
int ret = -1;

gf_log (this->name, GF_LOG_ERROR, "test translator loaded");
if (!this)
return -1;

if (!this->children) {
gf_log (this->name, GF_LOG_ERROR,
"test translator requires atleast one subvolume");
return -1;
}

if (!this->parents) {
gf_log (this->name, GF_LOG_ERROR, "dangling volume. check volfile ");
}

conf = this->private;

this->private = conf;
ret = 0;
return ret;
}

void
fini (xlator_t *this)
{
struct ios_conf *conf = NULL;

if (!this)
return;

conf = this->private;

if (!conf)
return;
this->private = NULL;

GF_FREE(conf);
gf_log (this->name, GF_LOG_ERROR, "test translator unloaded");
return;
}

int
notify (xlator_t *this, int32_t event, void *data, ...)
{
default_notify (this, event, data);
return 0;
}

struct xlator_fops fops = {
.stat = test_stat,
.lookup = test_lookup,
};

struct xlator_cbks cbks = {
};

struct volume_options options[] = {
};
目前僅用於測試的xlator而已,所以自己定義了lookup與stat,還有lookup_cbk,其他的並未定義,全部走default,這個原理在之前已經提到過。
然後執行make既可生成對應的xlator文件
Makefile test.c test.o test.so
將test.so復制至/usr/local/lib/glusterfs/3git/xlator/debug中
然後執行glusterfs的客戶端,mount至掛載節點,如果成功,可以查看log,整個過程成功矣~~!
轉載

3. python好學嗎

有網友點評說:

Python語言本身是比較容易的,樓主說的難應該指programming本身。

不覺得非計算機專業出身就學不好編程,我就是學通信的,學Python全憑興趣。平時用Python干各種臟活累活,數值計算、數據處理、復雜文本處理、資料庫導入導出excel、網上搶票、Web數據抓取、消息推送、DHT網路爬蟲、Kodi插件、Web自動化測試、網盤下載、雲點播。甚至有次日記軟體密碼忘了,都是通過py+autoit暴力破解出來的。

我的win、debian、mac上面一般都會開一兩個ipython,臨時處理各類雜務。簡單來說,Python現在就是我日常生活的一部分。我不是專業程序員,也沒用Python做過什麼大項目,只是每天享受Python帶來的便捷與快樂。

樓主所說的不能深入理解,其實是不願意花時間鑽研。用了十幾年Python,現在也要一直翻看官方文檔和一些第三方mole的文檔,不斷把遇到的問題弄懂弄透,學習不就是這個過程么?

我覺得樓主對Python無愛,對編程無愛,那就沒必要強迫自己填鴨式「學習」了。

另外一個建議,練習時盡量不要後在現有demo基礎上改,從頭開始寫起,遇到問題一個個查清,這樣才能學到東西。

接收到這個小夥伴的答案,我內心開始反思,其實他說得都對的3個點是:

1.其實本身我對編程是不熱愛的,只是因為需要;

2.其實本身我是對Python更上層可以用來做什麼是不清楚的,思維還是在機械的完成一個Python習題;

3.其實我本身對編程的難度是小悄了的,Python簡單是相對於C、Java等語言。

說到這里,不知道看到本文的小夥伴有幾個有類似的心理映射,如果你是上面的狀態,那你學習Python一定是難的。

下面我們來看看另外一位學習者的建議:

python是一門簡單易學,容易理解,分分鍾就可以掌握的語言,我也是學了大概一兩個星期吧,就開始做項目了,嘻嘻!!!

這里有一個很嚴重的問題,,我在學python之前,做過3點的C#,一年的php和一年的java!

所以呢,我想說的是,如果你對編程不那麼敏感,就需要時間來彌補了,那些什麼書啊,公開課啊,我覺得都是輔助的,你要是不經歷幾個項目,怎麼知道python為什麼容易學,怎麼知道python好理解,怎麼知道python有哪些超級好用的框架,比如django,tonado之類的。

所以呀,編程沒有捷徑,你甭想通過看。。。就學會,寫起來才是最重要的!

最終通過對學習Python這件事,我總結了幾點關於學習Python的建議,希望跟大家一起分享:

1.編程語言是一回事,但更重要的是編程思想,不要把應試教育的思想帶到這裡面來,並不是所有的知識都能靠「五年高考三年模擬」來掌握;

2.自己找個想用程序解決的任務,然後自己邊學邊完成。

3.沒有編程基礎的人新學一門語言一定一定要有耐心,基礎知識沒有半年以上的學習和練習是很難徹底掌握的,千萬不要圖快,學的太快或許會有一時的成就感,但基礎知識不扎實終將會成為你前進道路上的瓶頸,不僅學新的知識一知半解,工作時也會磕磕絆絆。

4.沒有計算機基礎,不管學什麼語言都會有點吃力的,python語法比較簡單的。

5.現在要做的就是把錯誤犯下100遍,那你就拿下這個Get了!

祝你學習Python之路愉快。

知乎網友任泉經典評論:

說Python簡單的都是程序員或者半程序員,說其實還是很困難的都是有需求但並非依賴性的業余愛好者。

Python的簡單,是相對於C++的簡單,而不是相對於Word、Excel的簡單。它再接近自然語言,也有語法,也有數據結構,也有編程思想,而這些對於「業務愛好者」來說就等於「難」。

想要不難也很容易,保證自己每天都會去使用它就好了,每天不管是看書學習也好,照著案例敲代碼也好,針對需求寫個小程序也好,一定要每天用,直到自己習慣語法,習慣數據結構,習慣編程思想為止,到那個時候,你就變成了半個程序員。

想以一周一兩次,甚至更低的頻率來學習編程,無論你內心多麼熱愛,無論這門語言多麼簡單,都是學不會的,更別談學好了。

熱點內容
python數組切片 發布:2025-08-22 15:45:39 瀏覽:240
便捷式存儲什麼意思 發布:2025-08-22 15:29:31 瀏覽:416
sql選擇查詢 發布:2025-08-22 15:24:52 瀏覽:234
python子線程異常 發布:2025-08-22 15:12:03 瀏覽:212
設置ftp用戶名和密碼 發布:2025-08-22 15:00:37 瀏覽:491
mss資料庫 發布:2025-08-22 14:52:55 瀏覽:840
c語言多個c 發布:2025-08-22 14:51:17 瀏覽:579
我的世界伺服器教程手機版網易 發布:2025-08-22 14:37:45 瀏覽:257
如何屏蔽安卓系統提示 發布:2025-08-22 14:25:29 瀏覽:889
編譯程序的配置是什麼意思 發布:2025-08-22 14:17:55 瀏覽:885