first step
- Install the gcc environment (if you install it, you can ignore it)
yum install -y gcc gcc-c++
Second step
- Install libevent (runtime requirement)
yum -y install libevent
third step
- Install libfastcommon
- Download link: https://github.com/happyfish100/libfastcommon
- Upload the downloaded installation package to CentOS and decompress it (I decompressed it to /usr/local/fdfs)
mkdir -p /usr/local/fdfs
tar -zxvf libfastcommon-1.0.41.tar.gz -C /usr/local/fdfs/
- Enter the unzipped directory
cd /usr/local/libfastcommon-1.0.41/
./make.sh #编译
./make.sh install #安装
- After libfastcommon is installed, the libfastcommon.so library file will be generated in the /usr/lib64 directory
- Note: Since the FastDFS program refers to the usr/lib directory, you need to see if there is a libfastcommon.so file in this directory. If not, copy the library files under **/usr/lib64** to /usr/lib. And establish a soft connection
- The following operations do not need to operate if there are files in usr/lib.
cp /usr/lib64/libfastcommon.so /usr/lib/
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
the fourth step
- Install tracker
- Upload fastdfs-6.01.tar.gz to centos;
- Unzip
tar -zxvf fastdfs-6.01.tar.gz -C /usr/local/fdfs
- Enter the unzipped directory
cd /usr/local/fdfs/fastdfs-6.01
./make.sh && ./make.sh install #编译之后接着进行安装
- The installation is successful. Copy the files under conf in the installation directory to /etc/fdfs/;
cp /usr/local/fdfs/fastdfs-6.01/conf/* /etc/fdfs/
the fifth step
- Configure and start tracker
cd /etc/fdfs/
Enter the directory- Edit the configuration file
vim tracker.conf
and change the content to the following
base_path=/home/fastdfs
- Create the /home/fastdfs directory to store logs. If it is not created, an error will be reported
mkdir -p /home/fastdfs
- Start tracker and run the following command:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
Sixth step
- Configure and start storage
- Modify part of the content to the following
- vim
base_path=/home/fastdfs
store_path0=/opt/fastdfs/dfs_storage
tracker_server=你的虚拟机ip:22122
#如果有多个则配置多个tracker
#tracker_server=192.168.101.4:22122
- Create /home/fastdfs/dfs_storage directory
mkdir -p /home/fastdfs/dfs_storage
- Start storage and run the command as follows:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
- You can go in /home/fastdfs/dfs_storage/data/ to view
Seventh step
- Use FastDFS's own tools to test
- Modify the client.conf configuration file
# the base path to store log files
base_path=/home/fastdfs
# tracker_server can ocur more than once for multi tracker servers.
# the value format of tracker_server is "HOST:PORT",
# the HOST can be hostname or ip address,
# and the HOST can be dual IPs or hostnames seperated by comma,
# the dual IPS must be an intranet IP and an extranet IP.
# such as: 192.168.2.100,122.244.141.46
tracker_server=你的虚拟机ip:22122
- First upload a picture to your virtual machine/root, execute the following command to test
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/你的图片
- The above picture shows that the upload is successful, but it is not accessible on the browser according to the ip, and fdfs does not support http, so Nginx needs to be integrated.
Eighth step
- FastDFS and nginx integration
- Upload fastdfs-nginx-module-1.21.tar.gz()
- Unzip
tar -zxvf fastdfs-nginx-module-1.21.tar.gz -C /usr/local/fdfs/
- Enter the src directory of the unzipped directory
cd /usr/local/fdfs/fastdfs-nginx-module-1.21/src/
- Modify the config file
ngx_addon_name=ngx_http_fastdfs_module
if test -n "${ngx_module_link}"; then
ngx_module_type=HTTP
ngx_module_name=$ngx_addon_name
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon"
ngx_module_libs="-L/usr/local/lib -lfastcommon -lfdfsclient"
ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
ngx_module_deps=
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
. auto/module
else
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon"
CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi
- Copy mod_fastdfs.conf under fastdfs-nginx-module/src to /etc/fdfs/
cp mod_fastdfs.conf /etc/fdfs/
- Modify the mod_fastdfs.conf file.
vim /etc/fdfs/mod_fastdfs.conf
base_path=/home/fastdfs
tracker_server=虚拟机ip:22122
#tracker_server=192.168.172.20:22122 #(多个tracker配置多行)
url_have_group_name=true #url中包含group名称
store_path0=/home/fastdfs/fdfs_storage #指定文件存储路径(上面配置的store路径)
Step 9
- Install Nginx How to install Nginx
9.1
-If you install with yum, you need to download a copy of the same version of nginx (if not, please ignore these steps and go directly to 9.2)
nginx -v
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxvf nginx-1.16.1.tar.gz -C /usr/local/nginx/
- Before proceeding to the next step, it is best to back up your previous /usr/sbin/nginx
cp /usr/sbin/nginx /usr/sbin/nginx.back
cp -rf /etc/nginx /etc/nginx.back
- Add module
./configure --add-module=/usr/local/fast/fastdfs-nginx-module-1.21/src/
- After success, an nginx file will be generated under objs in the unzipped directory
- Enter the objs directory to use to
objs
view
- Stop nginx, and overwrite nginx in this directory with nginx in /usr./local/sbin/
sudo systemctl stop nginx
cp nginx /usr/local/nginx
9.2
- Here is to download, compile and install with wget
- Enter the Nginx decompression directory
- Add module
./configure --add-module=/usr/local/fdfs/fastdfs-nginx-module-1.21/src/
- Recompile
make && make install
- Will overwrite the original nginx and generate a nginx.old
Tenth step
- Modify nginx configuration file
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name 47.113.122.120;
location /group1/M00/ {
root /home/fdfs/fdfs_storage/data;
ngx_fastdfs_module;
}
}
- Enter the address of the picture you just made on your browser