1.GCC用来对C语言代码进行编译运行,使用yum命令安装: yum -y install gcc (检测是否已经安装gcc:gcc -v 会看到版本号)
2,解压命令(unzip),所以这里可以用yum把unzip 也装一下: yum -y install unzip zip
3,
解压刚刚上传的libfastcommon-master.zip: unzip libfastcommon-master.zip->cd libfastcommon-master->编译:./make.sh 安装:./make.sh install
5,安装FastDFS: tar -zxvf FastDFS_v5.08.tar.gz -> cd FastDFS -> ./make.sh -> ./make.sh install
6,如果安装成功,会看到/etc/init.d/下看到提供的脚本文件(存储服务器启动脚本和踪迹服务器启动脚本):ll /etc/init.d/ | grep fdfs
-rwxr-xr-x 1 root root 918 6月 10 16:21 fdfs_storaged 是storage启动脚本
-rwxr-xr-x 1 root root 920 6月 10 16:21 fdfs_trackerd 是tracker启动脚本
7,能够在 /etc/fdfs/ 目录下看到默认的配置文件模板: ll /etc/fdfs/
-rw-r--r-- 1 root root 1461 6月 10 16:21 client.conf.sample 是客户端的配置文件模板
-rw-r--r-- 1 root root 7927 6月 10 16:21 storage.conf.sample 是storage的配置文件模板
-rw-r--r-- 1 root root 7200 6月 10 16:21 tracker.conf.sample tracker的配置文件模板
8,
我们要启动tracker,就修改刚刚看到的tarcker.conf
,并且启动fdfs_trackerd
1)首先将模板文件复制 cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
2)修改复制后的配置文件: vi /etc/fdfs/tracker.conf
base_path=/leyou/tracker # 存储日志和数据的根目录
3)新建一个文件夹mkdir -p /leyou/tracker
注意:关闭防火墙 查看防火墙状态systemctl status firewalld
启动tracker服务器: /etc/init.d/fdfs_trackerd start
停止tracker服务器: /etc/init.d/fdfs_trackerd stop
设置tracker服务开机启动: chkconfig fdfs_trackerd on
base_path=/leyou/storage # 数据和日志文件存储根目录
store_path0=/leyou/storage # 第一个存储目录
tracker_server=192.168.56.101:22122 # tracker服务器IP和端口
3)新建目录: mkdir -p /leyou/storage
启动storage服务器:/etc/init.d/fdfs_storaged start
停止storage服务器:/etc/init.d/fdfs_storaged stop
service fdfs_storaged start # 启动fdfs_storaged服务,停止用stop
设置storage服务开机启动: chkconfig fdfs_storaged on
检查是否启动成功:ps -ef | grep fdfs
root 5192 1 0 17:02 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root 5796 1 2 17:13 ? 00:00:01 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
root 5852 1976 0 17:14 pts/0 00:00:00 grep --color=auto fdfs
FastDFS通过Tracker服务器,将文件放在Storage服务器存储,但是同组存储服务器之间需要进入文件复制,有同步延迟的问题。
假设Tracker服务器将文件上传到了192.168.4.125,上传成功后文件ID已经返回给客户端。此时FastDFS存储集群机制会将这个文件同步到同组存储192.168.4.126,在文件还没有复制完成的情况下,客户端如果用这个文件ID在192.168.4.126上取文件,就会出现文件无法访问的错误。
而fastdfs-nginx-module可以重定向文件连接到文件上传时的源服务器取文件,避免客户端由于复制延迟导致的文件无法访问错误
connect_timeout=10 # 客户端访问文件连接超时时长(单位:秒)
tracker_server=192.168.56.101:22122 # tracker服务IP和端口
url_have_group_name=true # 访问链接前缀加上组名
store_path0=/leyou/storage # 文件存储路径
复制 FastDFS 的部分配置文件到/etc/fdfs 目录
cd /usr/local/leyou/FastDFS/conf/
cp http.conf mime.types /etc/fdfs/
配置nginx整合fastdfs-module模块
我们需要修改nginx配置文件,在/opt/nginx/config/nginx.conf文件中:
vim /opt/nginx/conf/nginx.conf
server {
listen 80;
server_name image.leyou.com;
# 监听域名中带有group的,交给FastDFS模块处理
location ~/group([0-9])/ {
ngx_fastdfs_module;
}
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
启动nginx:
nginx # 启动nginx
nginx -s stop # 停止nginx
nginx -s reload # 重新载入配置文件
可通过ps -ef | grep nginx查看nginx是否已启动成功
root 11161 1 0 18:10 ? 00:00:00 nginx: master process nginx
nobody 11162 11161 0 18:10 ? 00:00:00 nginx: worker process
root 11216 1976 0 18:11 pts/0 00:00:00 grep --color=auto nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/bin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -`
if [ -n "$user" ]; then
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep ‘configure arguments:‘`
for opt in $options; do
if [ `echo $opt | grep ‘.*-temp-path‘` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
fi
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
修改文件权限,并加入服务列表
# 修改权限
chmod 777 /etc/init.d/nginx
# 添加到服务列表
chkconfig --add /etc/init.d/nginx
设置开机启动
chkconfig nginx on
原文:https://www.cnblogs.com/coffee584/p/14872277.html