起步:Tor源码编译

Tor 源码编译

运行环境:Debian 9/Ubuntu 19.04

依赖库

安装make

sudo apt-get install make

安装gccg++

sudo apt-get install gcc
sudo apt-get install g++

安装 openssl

sudo apt-get install openssl

安装 zlib
首先要先装 ruby

sudo apt-get install ruby
sudo apt-get install zlib1g
sudo apt-get install zlib1g-dev

安装 libevent(异步通信库)

sudo apt-get install libevent-dev

安装 OpenSSL

sudo apt-get install libssl-dev

编译 Tor 源码

进入https://www.torproject.org/download/download.html.en下载 stable 的 tor 源码。

或使用git clone https://git.torproject.org/tor.git获取源码。

tor 官方仓库:https://gitweb.torproject.org/tor.git

wget https://www.torproject.org/dist/tor-0.3.4.8.tar.gz
tar -zxvf tor-0.3.4.8.tar.gz
cd tor-0.3.4.8
./configure
make

此处如果无法运行./configure

阅读根目录的INSTALL

If you got the source from git, run “./autogen.sh”, which will
run the various auto* programs. Then you can run ./configure, and
refer to the above instructions.

./autogen.sh

# 上面命令如果报错
sudo apt-get install automake
sudo apt-get install autoconf

如果有以下报错:

==================================

Building Tor has failed since manpages cannot be built.

You need asciidoc installed to be able to build the manpages.
To build without manpages, use the --disable-asciidoc argument
when calling configure.

==================================

则在configure后添加--disable-asciidoc即可

./configure --disable-asciidoc

其实可以从编译的顺序看出 Tor 的文件调用关系

编译阶段可以看出调用关系

运行 tor:

root@localhost:~/tor# make install
make[1]: Entering directory '/root/tor'
 /usr/bin/mkdir -p '/usr/local/bin'
  /usr/bin/install -c src/or/tor src/tools/tor-resolve src/tools/tor-gencert '/usr/local/bin'
 /usr/bin/mkdir -p '/usr/local/bin'
 /usr/bin/install -c contrib/client-tools/torify '/usr/local/bin'
 /usr/bin/mkdir -p '/usr/local/etc/tor'
 /usr/bin/install -c -m 644 src/config/torrc.sample '/usr/local/etc/tor'
 /usr/bin/mkdir -p '/usr/local/share/tor'
 /usr/bin/install -c -m 644 src/config/geoip src/config/geoip6 '/usr/local/share/tor'
make[1]: Leaving directory '/root/tor'
# 然后直接运行tor即可
root@localhost:~/tor# tor

从上面的make install过程可以看出,系统会把配置文件torrc.sample拷贝到/usr/local/etc/tor下。

出现如下信息则运行成功:

root@localhost:~# tor
Jun 18 03:49:19.723 [notice] Tor 0.3.3.9 (git-45028085ea188baf) running on Linux with Libevent 2.1.8-stable, OpenSSL 1.1.1b, Zlib 1.2.11, Liblzma N/A, and Libzstd N/A.
Jun 18 03:49:19.724 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Jun 18 03:49:19.724 [notice] Configuration file "/usr/local/etc/tor/torrc" not present, using reasonable defaults.
Jun 18 03:49:19.728 [notice] Scheduler type KIST has been enabled.
Jun 18 03:49:19.728 [notice] Opening Socks listener on 127.0.0.1:9050
Jun 18 03:49:19.000 [notice] Parsing GEOIP IPv4 file /usr/local/share/tor/geoip.
Jun 18 03:49:19.000 [notice] Parsing GEOIP IPv6 file /usr/local/share/tor/geoip6.
Jun 18 03:49:19.000 [warn] You are running Tor as root. You don't need to, and you probably shouldn't.
Jun 18 03:49:20.000 [notice] Bootstrapped 0%: Starting
Jun 18 03:49:20.000 [notice] Starting with guard context "default"
Jun 18 03:49:20.000 [notice] Bootstrapped 5%: Connecting to directory server
Jun 18 03:49:21.000 [notice] Bootstrapped 10%: Finishing handshake with directory server
Jun 18 03:49:22.000 [notice] Bootstrapped 15%: Establishing an encrypted directory connection
Jun 18 03:49:22.000 [notice] Bootstrapped 20%: Asking for networkstatus consensus
Jun 18 03:49:22.000 [notice] Bootstrapped 25%: Loading networkstatus consensus
Jun 18 03:49:24.000 [notice] I learned some more directory information, but not enough to build a circuit: We have no usable consensus.
Jun 18 03:49:25.000 [notice] Bootstrapped 40%: Loading authority key certs
Jun 18 03:49:25.000 [notice] Bootstrapped 45%: Asking for relay descriptors
Jun 18 03:49:25.000 [notice] I learned some more directory information, but not enough to build a circuit: We need more microdescriptors: we have 0/6392, and can only build 0% of likely paths. (We have 0% of guards bw, 0% of midpoint bw, and 0% of exit bw = 0% of path bw.)
Jun 18 03:49:27.000 [notice] Bootstrapped 50%: Loading relay descriptors
Jun 18 03:49:28.000 [notice] Bootstrapped 55%: Loading relay descriptors
Jun 18 03:49:29.000 [notice] Bootstrapped 61%: Loading relay descriptors
Jun 18 03:49:29.000 [notice] Bootstrapped 66%: Loading relay descriptors
Jun 18 03:49:29.000 [notice] Bootstrapped 72%: Loading relay descriptors
Jun 18 03:49:29.000 [notice] Bootstrapped 80%: Connecting to the Tor network
Jun 18 03:49:30.000 [notice] Bootstrapped 90%: Establishing a Tor circuit
Jun 18 03:49:31.000 [notice] Tor has successfully opened a circuit. Looks like client functionality is working.
Jun 18 03:49:31.000 [notice] Bootstrapped 100%: Done

文章作者: 玄霄
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 玄霄 !
评论
  目录