安装 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 yum install -y gcc-c++ yum install -y libevent wget -P ~/soft/ "http://ou0y29lb2.bkt.clouddn.com/libfastcommonV1.0.7.tar.gz" wget -P ~/soft/ "http://ou0y29lb2.bkt.clouddn.com/fastdfs-5.05.tar.gz" if [ ! -d "/usr/local/fastdfs" ]; then mkdir /usr/local/fastdfs fi cp ~/soft/libfastcommonV1.0.7 .tar.gz /usr/local/fastdfs cp ~/soft/fastdfs-5.05 .tar.gz /usr/local/fastdfs cd /usr/local/fastdfs tar -zxvf libfastcommonV1.0.7 .tar.gz tar -zxvf fastdfs-5.05 .tar.gz cd libfastcommon-1.0 .7 ./make.sh && ./make.sh install cp /usr/lib64/libfastcommon.so /usr/lib/ cd /usr/local/fastdfs/fastdfs-5.05 ./make.sh && ./make.sh install if [ ! -d "/etc/fdfs" ]; then mkdir /etc/fdfs fi cp /usr/local/fastdfs/fastdfs-5.05 /conf/* /etc/fdfs/ cd /etc/fdfs sed -i '/^base_path/s/^/#/' /etc/fdfs/tracker.conf sed -i '/^#base_path/a\\base_path=\/usr\/local\/fastdfs\/tracker' /etc/fdfs/tracker.conf filepath="/etc/fdfs/storage.conf" ipaddr=`ifconfig -a|grep inet|grep -v 127.0 .0.1 |grep -v inet6|awk '{print $2}' |tr -d "addr:" ` names=("group_name" "base_path" "store_path0" "tracker_server" ) replace_names=("group_name=group1" "base_path=\/usr\/local\/fastdfs\/storage" "store_path0=\/usr\/local\/fastdfs\/storage" "tracker_server=$ipaddr:22122 " ) count=${ for (( i=0 ; i<"$count " ; i=i+1 ))do sed -i "/^${names[$i ]}/s/^/#/" $filepath sed -i "/^#${names[$i ]}/a\\${replace_names[$i ]}" $filepath done if [ ! -d "/usr/local/fastdfs/tracker" ]; then mkdir /usr/local/fastdfs/tracker –p fi if [ ! -d "/usr/local/fastdfs/storage" ]; then mkdir /usr/local/fastdfs/storage –p fi ps -ef | grep tracker | awk -F " " '{if($8!="grep")print $2}' | xargs kill -9 ps -ef | grep storage | awk -F " " '{if($8!="grep")print $2}' | xargs kill -9 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
上传图片测试 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 cd /etc/fdfs cp client.conf.sample client.conf ipaddr=`ifconfig -a|grep inet|grep -v 127.0 .0.1 |grep -v inet6|awk '{print $2}' |tr -d "addr:" ` sed -i '/^base_path/s/^/#/' /etc/fdfs/client.conf sed -i '/^#base_path/a\\base_path=\/usr\/local\/fastdfs\/client' /etc/fdfs/client.conf sed -i '/^tracker_server/s/^/#/' /etc/fdfs/client.conf sed -i "/^#tracker_server/a\\tracker_server=$ipaddr:22122 " /etc/fdfs/client.conf mkdir -p /usr/local/fastdfs/client /usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/tomcat.jpg
FastDFS 和nginx整合 在tracker服务器上安装nginx 在每个tracker上安装nginx,的主要目的是做负载均衡及实现高可用。如果只有一台tracker服务器可以不配置nginx。
在storage服务器上安装nginx 安装fastdfs-nginx-module 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 wget -P ~/soft/ "http://ou0y29lb2.bkt.clouddn.com/fastdfs-nginx-module_v1.16.tar.gz" cp ~/soft/fastdfs-nginx-module_v1.16 .tar.gz /usr/local/fastdfs/ cd /usr/local/fastdfs tar -zxvf fastdfs-nginx-module_v1.16 .tar.gz filepath="/usr/local/fastdfs/fastdfs-nginx-module/src/config" sed -i "s/\/usr\/local\/include\/fastdfs/\/usr\/include\/fastdfs/g" $filepath sed -i "s/\/usr\/local\/include\/fastcommon/\/usr\/include\/fastcommon/g" $filepath sed -i "s/\/usr\/local\/lib/\/usr\/lib/g" $filepath cp /usr/local/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ modfilepath="mod_fastdfs.conf" ipaddr=`ifconfig -a|grep inet|grep -v 127.0 .0.1 |grep -v inet6|awk '{print $2}' |tr -d "addr:" ` names=("base_path" "tracker_server" "url_have_group_name" ) replace_names=("base_path=\/usr\/local\/fastdfs\/storage" "tracker_server=$ipaddr:22122 " "url_have_group_name=true" ) count=${ for (( i=0 ; i<"$count " ; i=i+1 ))do sed -i "/^${names[$i ]}/s/^/#/" $modfilepath sed -i "/^#${names[$i ]}/a\\${replace_names[$i ]}" $modfilepath done sed -ie "/^store_path0/s/^/#/" $modfilepath sed -E -ie "/^#\[group1\]/a\\store_path0=\/usr\/local\/fastdfs\/storage" $modfilepath cp /usr/lib64/libfdfsclient.so /usr/lib/ if [ ! -d "/var/temp/nginx/client" ]; then mkdir -p /var/temp/nginx/client fi
安装nginx 参考 Linux 安装nginx
唯一不一样的地方是 configure配置
1 2 3 4 5 6 7 8 9 10 11 12 13 ./configure \ --prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi \ --add-module=/usr/local/fastdfs/fastdfs-nginx-module/src
如果之前安装了nginx也没事, 重新编译会生成新的nginx可执行文件, 老的会自动修改成nginx.old
编译安装
修改nginx.conf配置文件(有坑) /usr/local/nginx 有conf文件夹, 里面的nginx.conf 才起作用
/usr/local/nginx/nginx-1.8.0/ 也有conf文件夹, 修改这个不起作用
1 2 3 4 5 6 7 8 9 server { listen 80; server_name localhost; location /group1/M00/{ #root /usr/local/fastdfs/storage/data; ngx_fastdfs_module; } }