普通用戶安裝編譯fastDFS on centos 7 64~~~~
1.下載文件fastdfs相關
https://github.com/happyfish100
libfastcommon-1.0.39.tar.gz
fastdfs-5.11.tar.gz
fastdfs-nginx-module-1.20.tar.gz
2.下載nginx相關
http://nginx.org/en/download.html
nginx-1.14.2.tar.gz
3.安裝相關依賴(如果這些依賴沒有權限yum安裝或者系統沒有預裝,就自己編譯吧,不在本文討論範圍)
yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
4.新建本次測試普通用戶
useradd fastdfs
su - fastdfs
5.新建安裝目錄
mkdir -pv /home/opt/fastdfs
目錄層級示意
/home/fastdfs/
├── opt
│ └── fastdfs
└── soft
├── fastdfs-5.11.tar.gz
├── fastdfs-nginx-module-1.20.tar.gz
├── libfastcommon-1.0.39.tar.gz
└── nginx-1.14.2.tar.gz
6.編譯安裝fastdfs
export DESTDIR=/home/fastdfs/opt/fastdfs
設置一個環境變量,軟件的安裝路徑,因爲作者自己的make.sh文件中有這個變量,但爲空所以默認root用戶編譯的安裝的時候就在系統根目錄下,但普通用戶是沒有根目錄的寫入權限的。
也可以不設置這個變量,去修改這個變量實際產生效果的地方,如TARGET_PREFIX、TARGET_CONF_PATH、TARGET_INIT_PATH等,沒細看。
6.1安裝公共lib
6.1.1解壓安裝文件
cd /home/fastdfs/soft
tar -zxvf libfastcommon-1.0.39.tar.gz
6.1.2編譯安裝
cd libfastcommon-1.0.39/
./make.sh
./make.sh install
安裝路徑及文件示意
/home/fastdfs/opt/
└── fastdfs
└── usr
├── include
│ └── fastcommon
│ ├── avl_tree.h
│ ├── base64.h
│ ├── chain.h
│ ├── char_converter.h
│ ├── char_convert_loader.h
│ ├── common_blocked_queue.h
│ ├── common_define.h
│ ├── connection_pool.h
│ ├── fast_allocator.h
│ ├── fast_blocked_queue.h
│ ├── fast_buffer.h
│ ├── fast_mblock.h
│ ├── fast_mpool.h
│ ├── fast_task_queue.h
│ ├── fast_timer.h
│ ├── fc_list.h
│ ├── flat_skiplist.h
│ ├── hash.h
│ ├── http_func.h
│ ├── id_generator.h
│ ├── ini_file_reader.h
│ ├── ioevent.h
│ ├── ioevent_loop.h
│ ├── local_ip_func.h
│ ├── logger.h
│ ├── md5.h
│ ├── multi_skiplist.h
│ ├── multi_socket_client.h
│ ├── _os_define.h
│ ├── php7_ext_wrapper.h
│ ├── process_ctrl.h
│ ├── pthread_func.h
│ ├── sched_thread.h
│ ├── shared_func.h
│ ├── skiplist_common.h
│ ├── skiplist.h
│ ├── skiplist_set.h
│ ├── sockopt.h
│ └── system_info.h
├── lib
│ └── libfastcommon.so -> /home/fastdfs/opt/fastdfs/usr/lib64/libfastcommon.so
└── lib64
└── libfastcommon.so
6.2安裝fastdfs
cd /home/fastdfs/soft
tar -zxvf fastdfs-5.11.tar.gz
cd /home/fastdfs/soft/fastdfs-5.11
6.2.1修改make.sh
說明:編譯完的程序運行時讀取額外lib文件的路徑。
LIBS=''
LIBS="-Wl,-rpath=/home/fastdfs/opt/fastdfs/usr/lib64"
說明:編譯時生成默認配置文件的路徑
if [ ! -d /etc/fdfs ]; then
mkdir -p /etc/fdfs
if [ ! -d $TARGET_CONF_PATH ]; then
mkdir -p $TARGET_CONF_PATH
6.2.2修改Makefile.in文件
vi /home/fastdfs/soft/fastdfs-5.11/tracker/Makefile.in
INC_PATH = -I../common -I/usr/include/fastcommon
LIB_PATH = $(LIBS) -lfastcommon
INC_PATH = -I../common -I${DESTDIR}/usr/include/fastcommon
LIB_PATH = $(LIBS) -L${DESTDIR}/usr/lib64 -lfastcommon
vi /home/fastdfs/soft/fastdfs-5.11/storage/Makefile.in
INC_PATH = -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I/usr/include/fastcommon
LIB_PATH = $(LIBS) -lfastcommon
INC_PATH = -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I${DESTDIR}/usr/include/fastcommon
LIB_PATH = $(LIBS) -L${DESTDIR}/usr/lib64 -lfastcommon
vi /home/fastdfs/soft/fastdfs-5.11/client/Makefile.in
INC_PATH = -I../common -I../tracker -I/usr/include/fastcommon
LIB_PATH = $(LIBS) -lfastcommon
INC_PATH = -I../common -I../tracker -I${DESTDIR}/usr/include/fastcommon
LIB_PATH = $(LIBS) -L${DESTDIR}/usr/lib64 -lfastcommon
6.2.3編譯安裝
cd /home/fastdfs/soft/fastdfs-5.11/
./make.sh
./make.sh install
安裝目錄示意
/home/fastdfs/opt/fastdfs/
/home/fastdfs/opt/fastdfs/
├── etc
│ ├── fdfs(sample配置文件目錄)
│ └── init.d(啓停腳本目錄)
└── usr
├── bin(可執行二進制程序目錄)
├── include(頭文件)
├── lib(庫文件)
└── lib64(庫文件)
6.2.4檢查是否安裝程序正常加載所有依賴
ldd /home/fastdfs/opt/fastdfs/usr/bin/fdfs_trackerd
ldd /home/fastdfs/opt/fastdfs/usr/bin/fdfs_storaged
ldd /home/fastdfs/opt/fastdfs/usr/bin/fdfs_monitor
7.安裝Nginx和fastdfs-nginx-module
7.1解壓安裝文件
cd /home/fastdfs/soft/
tar zxvf nginx-1.14.2.tar.gz
tar zxvf fastdfs-nginx-module-1.20.tar.gz
7.2修改fastdfs-nginx-module編譯配置
vi fastdfs-nginx-module-1.20/src/config
ngx_module_incs="${DESTDIR}/usr/include ${DESTDIR}/usr/include/fastcommon"
CORE_INCS="$CORE_INCS ${DESTDIR}/usr/include ${DESTDIR}/usr/include/fastcommon"
7.3複製fastdfs-nginx-module配置文件到fastdfs存放配置文件的目錄
cp /home/fastdfs/soft/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /home/fastdfs/opt/fastdfs/etc/fdfs/
7.4編譯Nginx
cd /home/fastdfs/soft/nginx-1.14.2
./configure --prefix=/home/fastdfs/opt/nginx-fdfs --add-module=/home/fastdfs/soft/fastdfs-nginx-module-1.20/src --with-http_ssl_module --with-ld-opt="-L /home/fastdfs/opt/fastdfs/usr/lib -Wl,-rpath=/home/fastdfs/opt/fastdfs/usr/lib64"
make
此時需要移除爲了先前三次編譯設置的變量DESTDIR,因爲這個變量和nginx自帶某變量衝突,會導致nginx執行make install是安裝路徑混亂
export DESTDIR=""
安裝Nginx
make install
檢查nginx是否正常加載所有依賴
ldd /home/fastdfs/opt/nginx-fdfs/sbin/nginx
8.複製fastdfs源碼中給的參考配置文件到fastdfs安裝目錄
cd /home/fastdfs/soft/fastdfs-5.11/conf
cp ./*.conf /home/fastdfs/opt/fastdfs/etc/fdfs/
/home/fastdfs/opt/fastdfs/etc/fdfs/
├── client.conf
├── client.conf.sample
├── http.conf
├── mod_fastdfs.conf
├── storage.conf
├── storage.conf.sample
├── storage_ids.conf
├── storage_ids.conf.sample
├── tracker.conf
└── tracker.conf.sample
安裝完畢後,本次實驗配置文件目錄/home/fastdfs/opt/fastdfs/etc/fdfs/中。
tracker.conf #tracker服務依賴的配置
storage_ids.conf #tracker服務依賴的配置
storage.conf #storage服務依賴的配置
http.conf #nginx模塊依賴的配置
mime.types #nginx模塊依賴的配置
mod_fastdfs.conf #nginx模塊依賴的配置
client.conf #測試客戶依賴的配置
9.準備啓動腳本
你可以去/home/fastdfs/opt/fastdfs/etc/init.d/目錄下啓動程序
當然也可以把兩個啓動程序複製出來
9.1創建啓動腳本目錄
mkdir /home/fastdfs/bin
cp /home/fastdfs/opt/fastdfs/etc/init.d/* /home/fastdfs/bin
/home/fastdfs/bin/
├── fdfs_storaged
└── fdfs_trackerd
9.2修改兩個啓動腳本中程序目錄和配置文件目錄
vi /home/fastdfs/bin/fdfs_trackerd
PRG=/usr/bin/fdfs_trackerd
CONF=/etc/fdfs/tracker.conf
PRG=/home/fastdfs/opt/fastdfs/usr/bin/fdfs_trackerd
CONF=/home/fastdfs/opt/fastdfs/etc/fdfs/tracker.conf
vi /home/fastdfs/bin/fdfs_storaged
PRG=/usr/bin/fdfs_storaged
CONF=/etc/fdfs/storage.conf
PRG=/home/fastdfs/opt/fastdfs/usr/bin/fdfs_storaged
CONF=/home/fastdfs/opt/fastdfs/etc/fdfs/storage.conf
9.3啓停命令
./fdfs_trackerd start|stop|restart
./fdfs_storaged start|stop|restart
10.至此普通用戶安裝編譯fastdfs就完成了,小結一下:
我們定義DESTDIR變量的方式改了程序編譯安裝的默認根路徑;
因爲更改了安裝路徑,所以編譯程序無法通過系統默認路徑找到依賴的一些文件,所以我們又更改了Makefile.ini,通過修改INC_PATH,LIB_PATH等讓程序編譯時去我們指定的目錄尋找依賴文件;
同時我們利用-Wl,-rpath參數解決編譯成的二進制執行程序依賴的庫文件自定義路徑的問題;
最後通過修改啓動腳本中的程序目錄和配置文件目錄,實現服務的啓停。
接下來需要合理配置文件,才能正常運行fastdfs相關服務,網上資料很多,就不在本文的討論範圍了。