在Kylin Linux上使用非root用户编译安装FastDFS

FastDFS是一个开源的高性能分布式文件系统,但其默认的安装脚本设计是使用root进行编译和安装,在某些情况下处于安全考虑,我们不希望FastDFS运行在root用户下,下面介绍使用非root用户编译安装的方法。

环境:
操作系统:Kylin Linux Advanced Server V10 (Lance)
FastDFS:6.0.7
libfastdfs:1.0.53
用户名:user
安装目录:/u01/FastDFS

一、安装依赖包

注意使用root用户执行以下命令:

dnf install gcc gcc-c++ make automake autoconf libtool pcre zlib openssl openssl-devel

二、建立目录

注意使用root用户执行,并授权:

mkdir /u01/FastDFS
chown user:user /u01/FastDFS

三、获取代码包

使用user登录服务器。
在Github获取代码包:https://github.com/happyfish100/fastdfs
fastdfs-V6.07.tar.gz –FastDFS代码包
libfastcommon-V1.0.53.tar.gz –FastDFS公共库代码包
都解压到/home/user目录下

四、编译和安装

注意使用user用户执行命令。

编译libfastcommon

cd libfastcommon-1.0.53/
export DESTDIR=/u01/FastDFS
./make.sh
./make.sh install

这时候/u01/FastDFS目录应该是下面的样子:

/u01/FastDFS/
└── usr
    ├── include
    │   └── fastcommon
    │       ├── avl_tree.h
    │       ├── base64.h
    │       ├── buffered_file_writer.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_atomic.h
    │       ├── fc_list.h
    │       ├── fc_memory.h
    │       ├── fc_queue.h
    │       ├── flat_skiplist.h
    │       ├── hash.h
    │       ├── http_func.h
    │       ├── id_generator.h
    │       ├── ini_file_reader.h
    │       ├── ioevent.h
    │       ├── ioevent_loop.h
    │       ├── json_parser.h
    │       ├── local_ip_func.h
    │       ├── locked_list.h
    │       ├── locked_timer.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
    │       ├── server_id_func.h
    │       ├── shared_buffer.h
    │       ├── shared_func.h
    │       ├── skiplist_common.h
    │       ├── skiplist.h
    │       ├── skiplist_set.h
    │       ├── sockopt.h
    │       ├── system_info.h
    │       ├── thread_pool.h
    │       └── uniq_skiplist.h
    ├── lib
    │   └── libfastcommon.so -> /u01/FastDFS/usr/lib64/libfastcommon.so
    └── lib64
        └── libfastcommon.so

编译FastDFS

需要先修改部分编译配置文件:

vim /home/user/fastdfs-6.07/make.sh


第38行,改成:

LIBS='-Wl,-rpath=/u01/FastDFS/usr/lib64'


第164和165行,改成:

if [ ! -d $TARGET_CONF_PATH ]; then
  mkdir -p $TARGET_CONF_PATH
vim /home/user/fastdfs-6.07/tracker/Makefile.in


第4第5行,改成:

INC_PATH = -I../common -I${DESTDIR}/usr/include
LIB_PATH = $(LIBS) -L${DESTDIR}/usr/lib64 -lfastcommon
vim /home/user/fastdfs-6.07/storage/Makefile.in


第4第5行,改成:

INC_PATH = -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I${DESTDIR}/usr/include
LIB_PATH = $(LIBS) -L${DESTDIR}/usr/lib64 -lfastcommon
vim /home/user/fastdfs-6.07/client/Makefile.in


第6第7行,改成:

INC_PATH = -I../common -I../tracker -I${DESTDIR}/usr/include
LIB_PATH = $(LIBS) -L${DESTDIR}/usr/lib64 -lfastcommon

开始编译:

export DESTDIR=/u01/FastDFS
./make.sh
./make.sh install

执行完毕后,/u01/FastDFS目录应该是下面的样子:

/u01/FastDFS
├── etc
│   ├── fdfs
│   │   ├── client.conf.sample
│   │   ├── storage.conf.sample
│   │   ├── storage_ids.conf.sample
│   │   └── tracker.conf.sample
│   └── init.d
│       ├── fdfs_storaged
│       └── fdfs_trackerd
└── usr
    ├── bin
    │   ├── fdfs_appender_test
    │   ├── fdfs_appender_test1
    │   ├── fdfs_append_file
    │   ├── fdfs_crc32
    │   ├── fdfs_delete_file
    │   ├── fdfs_download_file
    │   ├── fdfs_file_info
    │   ├── fdfs_monitor
    │   ├── fdfs_regenerate_filename
    │   ├── fdfs_storaged
    │   ├── fdfs_test
    │   ├── fdfs_test1
    │   ├── fdfs_trackerd
    │   ├── fdfs_upload_appender
    │   ├── fdfs_upload_file
    │   ├── restart.sh
    │   └── stop.sh
    ├── include
    │   ├── fastcommon
    │   │   ├── avl_tree.h
    │   │   ├── base64.h
    │   │   ├── buffered_file_writer.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_atomic.h
    │   │   ├── fc_list.h
    │   │   ├── fc_memory.h
    │   │   ├── fc_queue.h
    │   │   ├── flat_skiplist.h
    │   │   ├── hash.h
    │   │   ├── http_func.h
    │   │   ├── id_generator.h
    │   │   ├── ini_file_reader.h
    │   │   ├── ioevent.h
    │   │   ├── ioevent_loop.h
    │   │   ├── json_parser.h
    │   │   ├── local_ip_func.h
    │   │   ├── locked_list.h
    │   │   ├── locked_timer.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
    │   │   ├── server_id_func.h
    │   │   ├── shared_buffer.h
    │   │   ├── shared_func.h
    │   │   ├── skiplist_common.h
    │   │   ├── skiplist.h
    │   │   ├── skiplist_set.h
    │   │   ├── sockopt.h
    │   │   ├── system_info.h
    │   │   ├── thread_pool.h
    │   │   └── uniq_skiplist.h
    │   └── fastdfs
    │       ├── client_func.h
    │       ├── client_global.h
    │       ├── fdfs_client.h
    │       ├── fdfs_define.h
    │       ├── fdfs_global.h
    │       ├── fdfs_http_shared.h
    │       ├── fdfs_server_id_func.h
    │       ├── fdfs_shared_func.h
    │       ├── mime_file_parser.h
    │       ├── storage_client1.h
    │       ├── storage_client.h
    │       ├── tracker_client.h
    │       ├── tracker_proto.h
    │       ├── tracker_types.h
    │       └── trunk_shared.h
    ├── lib
    │   ├── libfastcommon.so -> /u01/FastDFS/usr/lib64/libfastcommon.so
    │   └── libfdfsclient.so
    └── lib64
        ├── libfastcommon.so
        └── libfdfsclient.so

上一篇