本文共 6239 字,大约阅读时间需要 20 分钟。
普通用户安装编译fastDFS on centos 7 64~~~~
1.下载文件fastdfs相关libfastcommon-1.0.39.tar.gzfastdfs-5.11.tar.gzfastdfs-nginx-module-1.20.tar.gz2.下载nginx相关
nginx-1.14.2.tar.gz3.安装相关依赖(如果这些依赖没有权限yum安装或者系统没有预装,就自己编译吧,不在本文讨论范围)
yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel4.新建本次测试普通用户
useradd fastdfssu - fastdfs5.新建安装目录
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.gz6.编译安装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/softtar -zxvf libfastcommon-1.0.39.tar.gz6.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.so6.2安装fastdfs
cd /home/fastdfs/softtar -zxvf fastdfs-5.11.tar.gzcd /home/fastdfs/soft/fastdfs-5.116.2.1修改make.sh
说明:编译完的程序运行时读取额外lib文件的路径。LIBS=''LIBS="-Wl,-rpath=/home/fastdfs/opt/fastdfs/usr/lib64"说明:编译时生成默认配置文件的路径if [ ! -d /etc/fdfs ]; thenmkdir -p /etc/fdfsif [ ! -d $TARGET_CONF_PATH ]; thenmkdir -p $TARGET_CONF_PATH6.2.2修改Makefile.in文件
vi /home/fastdfs/soft/fastdfs-5.11/tracker/Makefile.inINC_PATH = -I../common -I/usr/include/fastcommonLIB_PATH = $(LIBS) -lfastcommonINC_PATH = -I../common -I${DESTDIR}/usr/include/fastcommon
LIB_PATH = $(LIBS) -L${DESTDIR}/usr/lib64 -lfastcommonvi /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/fastcommonLIB_PATH = $(LIBS) -lfastcommonINC_PATH = -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I${DESTDIR}/usr/include/fastcommon
LIB_PATH = $(LIBS) -L${DESTDIR}/usr/lib64 -lfastcommonvi /home/fastdfs/soft/fastdfs-5.11/client/Makefile.in
INC_PATH = -I../common -I../tracker -I/usr/include/fastcommonLIB_PATH = $(LIBS) -lfastcommonINC_PATH = -I../common -I../tracker -I${DESTDIR}/usr/include/fastcommon
LIB_PATH = $(LIBS) -L${DESTDIR}/usr/lib64 -lfastcommon6.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_monitor7.安装Nginx和fastdfs-nginx-module
7.1解压安装文件
cd /home/fastdfs/soft/tar zxvf nginx-1.14.2.tar.gztar zxvf fastdfs-nginx-module-1.20.tar.gz7.2修改fastdfs-nginx-module编译配置
vi fastdfs-nginx-module-1.20/src/configngx_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=""安装Nginxmake install检查nginx是否正常加载所有依赖ldd /home/fastdfs/opt/nginx-fdfs/sbin/nginx8.复制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/bincp /home/fastdfs/opt/fastdfs/etc/init.d/* /home/fastdfs/bin/home/fastdfs/bin/├── fdfs_storaged └── fdfs_trackerd9.2修改两个启动脚本中程序目录和配置文件目录
vi /home/fastdfs/bin/fdfs_trackerdPRG=/usr/bin/fdfs_trackerd CONF=/etc/fdfs/tracker.confPRG=/home/fastdfs/opt/fastdfs/usr/bin/fdfs_trackerd
CONF=/home/fastdfs/opt/fastdfs/etc/fdfs/tracker.confvi /home/fastdfs/bin/fdfs_storaged
PRG=/usr/bin/fdfs_storaged CONF=/etc/fdfs/storage.confPRG=/home/fastdfs/opt/fastdfs/usr/bin/fdfs_storaged
CONF=/home/fastdfs/opt/fastdfs/etc/fdfs/storage.conf9.3启停命令
./fdfs_trackerd start|stop|restart./fdfs_storaged start|stop|restart10.至此普通用户安装编译fastdfs就完成了,小结一下:
我们定义DESTDIR变量的方式改了程序编译安装的默认根路径;因为更改了安装路径,所以编译程序无法通过系统默认路径找到依赖的一些文件,所以我们又更改了Makefile.ini,通过修改INC_PATH,LIB_PATH等让程序编译时去我们指定的目录寻找依赖文件;同时我们利用-Wl,-rpath参数解决编译成的二进制执行程序依赖的库文件自定义路径的问题; 最后通过修改启动脚本中的程序目录和配置文件目录,实现服务的启停。接下来需要合理配置文件,才能正常运行fastdfs相关服务,网上资料很多,就不在本文的讨论范围了。
转载于:https://blog.51cto.com/11185188/2393036