本系列文章是把作者刚接触和学习Linux时候的实操记录分享出来,内容主要包括Linux入门的一些理论概念知识、Web程序、mysql数据库的简单安装部署,希望能够帮到一些初学者,少走一些弯路。
注意:
Linux下区分大小写;
Linux多用户多线程;
Linux下每个文件和目录都有访问权限;
FastDFS单机部署一键安装脚本
本文是FastDFS的单机部署的意见安装脚本,方便大家。
安装环境:CentOS7 64位、FasDFS-5.12、libfastcommon-1.0.38、fastdfs-nginx-module-1.20、nginx-1.20.1
FastDFS#、#FastDFS安装#、#FastDFS单机部署#、#FastDFS一键安装#、#一键安装脚本#
1.准备工作
1)FastDFS及其组件下载地址
https://gitee.com/fastdfs100
或
https://github.com/happyfish100
不想费事的人可以直接下载我整理的一键安装脚本和FastDFS及其组件安装包:
链接:https://pan.baidu.com/s/1LswEtyCxxw8sbRIh9kVBAA
提取码:ue8k
2)上传shell脚本和安装包
注意:shell脚本和各个安装包在同一级目录下
如:
# ls
fastDFS_nginx_exec.sh
fastdfs-5.12.tar.gz
fastdfs-nginx-module-1.20.tar.gz
libfastcommon-1.0.38.tar.gz
nginx-1.15.2.tar.gz
nginx-1.20.1.tar.gz
2.修改shell脚本变量
根据自己的实际需求,修改shell脚本中的定义的端口、ip、安装目录等内容,除了ip地址外,其他都可以使用默认内容。
shell脚本内容如下:
#!/bin/bash
source ~/.bashrc
#准备工作
#在生产环境中,建议不要关闭防火墙,根据实际需要开启端口即可
#使用ifconfig查看本机ip地址
#自定义变量(注!!!执行脚本前需要进行修改)
#安装包目录soft_path,即执行脚本的当前目录
soft_path=$(cd "$(dirname "$0")";pwd)
#安装包名称fn,根据自己下载的文件名字修改,主要是版本号有所不同
fn_libfastcommon="libfastcommon-1.0.38.tar.gz"
fn_fastdfs="fastdfs-5.12.tar.gz"
fn_fastdfs_nginx_module="fastdfs-nginx-module-1.20.tar.gz"
fn_nginx="nginx-1.15.2.tar.gz"
#定义配置参数
ip="172.16.2.100" #服务器的IP,根据实际情况修改
tracker_port="22122" #跟踪服务器端口号,一般使用默认,不用修改
storage_port="23000" #存储服务器端口号,一般使用默认,不用修改
nginx_port="80" #Nginx端口号,根据实际情况修改
#定义安装目录参数
bp_fastdfs="/homework/fastdfs" #base_path目录,fastdfs存放数据和日志的目录,根据实际情况修改
bp_tracker=${bp_fastdfs}"/tracker" #tracker目录,一般不用修改
bp_storage=${bp_fastdfs}"/storage" #storage目录,一般不用修改
bp_client=${bp_fastdfs}"/client" #client目录,一般不用修改
bp_storage0=${bp_fastdfs}"/storage0" #storage_path目录,即文件存储目录,一般不用修改
#以上部分需要根据实际情况修改
echo "下面开始安装......."
echo "创建目录"
mkdir -p ${bp_tracker}
mkdir -p ${bp_storage}
mkdir -p ${bp_client}
mkdir -p ${bp_storage0}
echo "解压缩安装包"
cd ${soft_path}
tar -zxvf ${fn_libfastcommon}
tar -zxvf ${fn_fastdfs}
tar -zxvf ${fn_fastdfs_nginx_module}
tar -zxvf ${fn_nginx}
#获取安装文件解压缩后的目录名称sp
sp_libfastcommon=${fn_libfastcommon%.tar.gz}
sp_fastdfs=${fn_fastdfs%.tar.gz}
sp_fastdfs_nginx_module=${fn_fastdfs_nginx_module%.tar.gz}
sp_nginx=${fn_nginx%.tar.gz}
echo "安装fastdfs依赖包"
yum install -y gcc-c++
echo "安装nginx依赖包"
yum -y install zlib-devel pcre-devel openssl-devel
echo "编译安装libfastcommon"
cd ${soft_path}/${sp_libfastcommon}
./make.sh
./make.sh install
#创建软链接(暂时没啥用)
#ln -s /usr/local/include/fastcommon /usr/include/fastcommon
echo "编译安装FastDFS"
cd ${soft_path}/${sp_fastdfs}
./make.sh
./make.sh install
echo "开始配置FastDFS"
echo "FastDFS配置文件准备"
cd /etc/fdfs
cp tracker.conf.sample tracker.conf #tracker配置文件
cp storage.conf.sample storage.conf #storage配置文件
cp client.conf.sample client.conf #客户端配置文件,测试上传文件用
echo "nginx访问配置文件准备"
cp ${soft_path}/${sp_fastdfs_nginx_module}/src/mod_fastdfs.conf /etc/fdfs #mod_fastdfs配置文件,供nginx访问使用
cp ${soft_path}/${sp_fastdfs}/conf/http.conf /etc/fdfs #供nginx访问使用
cp ${soft_path}/${sp_fastdfs}/conf/mime.types /etc/fdfs #供nginx访问使用
echo "配置tracker.conf 文件"
#tracker服务器端口(默认22122,一般不修改)
sed -i "s#port=22122#port=${tracker_port}#g" tracker.conf
#存储数据和日志的根目录
sed -i "s#base_path=/home/yuqing/fastdfs#base_path=${bp_tracker}#g" tracker.conf
#暂时不知道有啥用
#sed -i "s#http.server_port=8080#http.server_port=${nginx_port}#g" tracker.conf
echo "配置storage.conf 文件"
#storage服务端口(默认23000,一般不修改)
sed -i "s#port=23000#port=${storage_port}#g" storage.conf
#存储数据和日志的根目录
sed -i "s#base_path=/home/yuqing/fastdfs#base_path=${bp_storage}#g" storage.conf
#第一个文件存储目录
sed -i "s#store_path0=/home/yuqing/fastdfs#store_path0=${bp_storage}#g" storage.conf
#tracker服务器
sed -i "s#tracker_server=192.168.209.121:22122#tracker_server=${ip}:${tracker_port}#g" storage.conf
#使用http访问文件时的端口(和nginx中保持一致)
sed -i "s#http.server_port=8888#http.server_port=${nginx_port}#g" storage.conf
echo "配置client.conf 文件"
#存储数据和日志的根目录
sed -i "s#base_path=/home/yuqing/fastdfs#base_path=${bp_client}#g" client.conf
#tracker服务器
sed -i "s#tracker_server=192.168.0.197:22122#tracker_server=${ip}:${tracker_port}#g" client.conf
#sed -i "s#http.tracker_server_port=80#http.tracker_server_port=${nginx_port}#g" client.conf
echo "Nginx插件安装及配置"
#cd ${soft_path}/${sp_fastdfs_nginx_module}/src
#sed -i "s#/usr/local/include/fastdfs#/usr/include/fastdfs#g" config
#sed -i "s#/usr/local/lib#/usr/lib64#g" config
echo "配置mod_fastdfs.conf文件"
cd /etc/fdfs
#sed -i "s#base_path=/tmp#base_path=${bp_storage}#g" mod_fastdfs.conf
#tracker服务器IP和端口
sed -i "s#tracker_server=tracker:22122#tracker_server=${ip}:${tracker_port}#g" mod_fastdfs.conf
#storage服务端口(与storage.conf中port保持一致)
sed -i "s#port=23000#port=${storage_port}#g" mod_fastdfs.conf
#url中是否包含group名称
sed -i "s#url_have_group_name = false#url_have_group_name = true#g" mod_fastdfs.conf
#第一个文件存储目录
sed -i "s#store_path0=/home/yuqing/fastdfs#store_path0=${bp_storage0}#g" mod_fastdfs.conf
echo "编译安装nginx"
cd ${soft_path}/${sp_nginx}
./configure --add-module=${soft_path}/${sp_fastdfs_nginx_module}/src
make
make install
echo "修改nginx配置文件"
cd /usr/local/nginx/conf/
# 该端口为storage.conf中的http.server_port相同
sed -i "s#listen 80#listen ${nginx_port}#g" nginx.conf
#在#error_page前一行增加location
sed -i "/#error_page/i location ~/group[0-9]/ {ngx_fastdfs_module;}" nginx.conf
echo "配置开机自启动"
echo "配置fastdfs开机自启动"
systemctl enable fdfs_trackerd
systemctl enable fdfs_storaged
echo "配置nginx开机自启动"
cat >> /etc/rc.d/rc.local << EOF
# nginx start
/usr/local/nginx/sbin/nginx
EOF
chmod +x /etc/rc.d/rc.local
echo "启动程序"
systemctl start fdfs_trackerd
systemctl start fdfs_storaged
/usr/local/nginx/sbin/nginx
echo "安装结束"
3.执行一键安装脚本
# sh fastDFS_nginx_exec.sh
4.测试文件上传及访问
1)文件上传测试
# fdfs_upload_file /etc/fdfs/client.conf /tmp/a.txt
返回FID表示成功 如:group1/M00/00/00/xx.txt
2)nginx文件访问测试
在浏览器中输入刚刚测试上传过的文件地址(storage的ip+nginx端口+FID),这里nginx端口是80。
http://172.16.2.100/group1/M00/00/00/xx.txt
IT小胖豆:初学者踩坑之路及过程分享,希望能够帮到一些初学者,欢迎各位IT打工人,入坑讨论-_-