A: 前期准備工作
1. 安裝vscode,詳細請參見vscode官網https://code.visualstudio.com/docs/setup/linux,摘要如下:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo' yum check-update sudo yum install code
2. 下載palo源代碼,本次是基於0.8.1版本編譯的
下載地址為:https://github.com/baidu/palo/archive/v0.8.1-beta.tar.gz
3. 安裝GCC 4.8.2+,Oracle JDK 1.8+,Python 2.7+,確認 gcc, java, python 命令指向正確版本, 設置 JAVA_HOME 環境變量
4. 安裝其他依賴包
sudo yum install -y gcc-c++ libstdc++-static ant cmake byacc flex automake libtool binutils-devel bison
如果是0.8.2或master版本,還需要執行下面的命令:
ubuntu安裝命令為:
sudo apt-get install libssl-dev
Centos安裝命令為:
yum install -y openssl-devel
5. step 4安裝完成后,執行下述命令
sudo updatedb yum install redhat-lsb yum install mlocate
B 編譯
以下操作步驟在/home/workspace/palo0.8.1目錄下進行
1. 解壓A-2下載的0.8.1的源碼
tar palo-0.8.1-beta.tar.gz -d /home/workspace/palo0.8.1
2. 解壓第三方包到/home/workspace/palo0.8.1/thirdparty/src/ 目錄下
tar -zxvf palo-thirdparty-20180418.tar.gz -d /home/workspace/palo0.8.1/thirdparty/src/
3. 編譯第三方依賴包
sh /home/workspace/palo0.8.1/thirdparty/build-thirdparty.sh
如果是0.8.2版本之后的版本,請修改build-thirdparty.sh的build_brpc函數,加上DPROTOBUF_PROTOC_EXECUTABLE的路徑傳參,否則在編譯BRPC時會找不到protobuf的執行文件,報錯
# brpc build_brpc() { check_if_source_exist $BRPC_SOURCE if [ ! -f $CMAKE_CMD ]; then echo "cmake executable does not exit" exit 1 fi cd $TP_SOURCE_DIR/$BRPC_SOURCE mkdir build -p && cd build rm -rf CMakeCache.txt CMakeFiles/ $CMAKE_CMD -v -DBUILD_SHARED_LIBS=0 -DCMAKE_INSTALL_PREFIX=$TP_INSTALL_DIR \ -DBRPC_WITH_GLOG=ON -DCMAKE_INCLUDE_PATH="$TP_INSTALL_DIR/include" \ -DCMAKE_LIBRARY_PATH="$TP_INSTALL_DIR/lib;$TP_INSTALL_DIR/lib64" \ -DPROTOBUF_PROTOC_EXECUTABLE=$TP_INSTALL_DIR/bin/protoc .. make -j$PARALLEL && make install }
在本人的編譯過程中,遇到boost-1.6.4編譯無法通過的情況,解決辦法為:
cd /home/workspace/palo0.8.1/thirdparty/src/boost_1_64_0 patch -p0 < ../../patches/boost-1.64.0-gcc4.8.patch
執行完成后,重新執行
sh /home/workspace/palo0.8.1/thirdparty/build-thirdparty.sh
4. 編譯palo產品代碼
sh /home/workspace/palo0.8.1/build.sh
注意:這個編譯有以下幾條指令:
sh build.sh #同時編譯be 和fe sh build.sh --be #只編譯be sh build.sh --fe #只編譯fe sh build.sh --fe --be#同時編譯be fe sh build.sh --fe --be --clean#刪除並同時編譯be fe sh build.sh --fe --clean#刪除並編譯fe sh build.sh --be --clean#刪除並編譯be sh build.sh --be --fe --clean#刪除並同時編譯be fe
如果不出意外,應該會編譯成功,最終的部署文件將產出到 /home/workspace/palo0.8.1/output/ 目錄下。如果還遇到其他問題,可以參照palo的安裝文檔https://github.com/baidu/palo/wiki/Palo-Install,常見錯誤一節。
C 部署調試
1. 給be編譯結果文件授權
chmod 755 /home/workspace/palo0.8.1/output/be/lib/palo_be
注意: /home/workspace/palo0.8.1/output/be/lib/palo_be為be的執行文件,默認編譯是帶-g的,也就是包含調試符號的。
2. 創建數據存放目錄
通過查看/home/workspace/palo0.8.1/output/be/conf/be.conf
# INFO, WARNING, ERROR, FATAL sys_log_level = INFO # ports for admin, web, heartbeat service be_port = 9060 be_rpc_port = 9070 webserver_port = 8040 heartbeat_service_port = 9050 # Choose one if there are more than one ip except loopback address. # Note that there should at most one ip match this list. # If no ip match this rule, will choose one randomly. # use CIDR format, e.g. 10.10.10.0/24 # Default value is empty. priority_networks = 192.168.1.0/24 # data root path, seperate by ';' storage_root_path = /home/disk1/palo;/home/disk2/palo # Advanced configurations # sys_log_dir = ${PALO_HOME}/log # sys_log_roll_mode = SIZE-MB-1024 # sys_log_roll_num = 10 # sys_log_verbose_modules = # log_buffer_level = -1 # palo_cgroups
需要創建這兩個文件夾,這是be數據存放的地方
mkdir -p /home/disk1/palo mkdir -p /home/disk2/palo
3. 打開vscode,並打開be源碼所在目錄,在本案例中打開目錄為/home/workspace/palo0.8.1/
4. 安裝vscode ms c++調試插件
5. 創建launch.json文件,文件內容如下:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "/home/workspace/palo0.8.1/output/be/lib/palo_be", "args": [], "stopAtEntry": false, "cwd": "/home/workspace/palo0.8.1/", "environment": [{"name":"PALO_HOME","value":"/home/workspace/palo0.8.1/output/be/"}, {"name":"UDF_RUNTIME_DIR","value":"/home/workspace/palo0.8.1/output/be/lib/udf-runtime"}, {"name":"LOG_DIR","value":"/home/workspace/palo0.8.1/output/be/log"}, {"name":"PID_DIR","value":"/home/workspace/palo0.8.1/output/be/bin"} ], "externalConsole": true, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
其中,environment定義了幾個環境變量PALO_HOME UDF_RUNTIME_DIR LOG_DIR PID_DIR,這是palo_be運行時需要的環境變量,如果沒有設置,啟動會失敗。
注意:如果希望是attach(附加進程)調試,配置代碼如下:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "attach", "program": "/home/workspace/palo0.8.1/output/lib/palo_be", "processId":26789, "MIMode": "gdb", "internalConsoleOptions":"openOnSessionStart", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
配置中 "request": "attach", "processId":26789,這兩個配置節是重點: 分別設置gdb的調試模式為attach,附加進程的processId,否則會失敗。如何查找進程id,可以在命令行中輸入以下命令:
ps -A | grep palo_be
如圖:
其中的26789即為當前運行的be的進程id.
如果當前用戶不是root用戶,會出現vscode啟動gdb失敗的情況,實際上vscode attach調試的原理是,啟動一個腳本,在這個腳本中啟動gdb並attach 到processId,具體腳本形如:
echo $$ > /tmp/Microsoft-MIEngine-Pid-inqdl1a1.ccl ; cd /opt/doris/output/be/lib ; DbgTerm=`tty` ; set -o monitor ; trap 'rm /tmp/Microsoft-MIEngine-In-ak1nvfsv.e7p /tmp/Microsoft-MIEngine-Out-zt0opgme.h06 /tmp/Microsoft-MIEngine-Pid-inqdl1a1.ccl /tmp/Microsoft-MIEngine-Cmd-vfkimaay.df7' EXIT ; read -n 1 -p \"Superuser access is required to attach to a process. Attaching as superuser can potentially harm your computer. Do you want to continue? [y/N]\" yn; if [[ ! $yn =~ ^[Yy]$ ]] ; then exit 0; fi; /usr/bin/pkexec /usr/bin/gdb --interpreter=mi --tty=$DbgTerm < /tmp/Microsoft-MIEngine-In-ak1nvfsv.e7p > /tmp/Microsoft-MIEngine-Out-zt0opgme.h06 & clear; pid=$! ; echo $pid > /tmp/Microsoft-MIEngine-Pid-inqdl1a1.ccl ; wait $pid;
但是如果當前用戶的權限不是root,就會出現無法啟動gdb,vscode無法連接上vscode,啟動后毫無反映。解決辦法為:
#第一種解決方法 sudo /usr/share/code/code --unity-launch #默認/root目錄作為工作目錄 #第2種解決方法 sudo /usr/share/code/code --user-data-dir {YOUR SOURCE DIR}
一個完整的lainch.json的例子如下:
1 { 2 // Use IntelliSense to learn about possible attributes. 3 // Hover to view descriptions of existing attributes. 4 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 "version": "0.2.0", 6 "configurations": [ 7 { 8 "name": "(gdb) Attach", 9 "type": "cppdbg", 10 "request": "attach", 11 "program": "/opt/doris/output/be/lib/palo_be", 12 "processId": "${command:pickProcess}", 13 "MIMode": "gdb", 14 "setupCommands": [ 15 { 16 "description": "Enable pretty-printing for gdb", 17 "text": "-enable-pretty-printing", 18 "ignoreFailures": true 19 } 20 ] 21 }, 22 { 23 "name": "(gdb) Launch", 24 "type": "cppdbg", 25 "request": "launch", 26 "program": "/opt/doris/output/be/lib/palo_be", 27 "args": [], 28 "stopAtEntry": false, 29 "cwd": "/opt/doris/output/be", 30 "environment": [ 31 { 32 "name": "DORIS_HOME", 33 "value": "/opt/doris/output/be" 34 }, 35 { 36 "name": "UDF_RUNTIME_DIR", 37 "value": "/opt/doris/output/be/lib/udf-runtime" 38 }, 39 { 40 "name": "LOG_DIR", 41 "value": "/opt/doris/output/be/log" 42 }, 43 { 44 "name": "PID_DIR", 45 "value": "/opt/doris/output/be/bin" 46 } 47 ], 48 "externalConsole": false, 49 "MIMode": "gdb", 50 "setupCommands": [ 51 { 52 "description": "Enable pretty-printing for gdb", 53 "text": "-enable-pretty-printing", 54 "ignoreFailures": true 55 } 56 ] 57 } 58 ] 59 }
6. 點擊調試即可。