linux下启动fastDFS - Go语言中文社区

linux下启动fastDFS


1-部署文件服务器需要的软件包

在这里插入图片描述

drwxr-xr-x. 10 8980 users   4096 8月  28 03:23 FastDFS
drwxrwxr-x.  3  500   500   4096 5月   4 2014 fastdfs-nginx-module
-rw-r--r--.  1 root root   17510 9月  21 2017 fastdfs-nginx-module_v1.16.tar.gz
-rw-r--r--.  1 root root  344620 9月  21 2017 FastDFS_v5.08.tar.gz
drwxr-xr-x.  4 root root    4096 8月  28 03:21 libfastcommon-master
-rw-r--r--.  1 root root  161971 10月 17 2016 libfastcommon-master.zip
drwxr-xr-x.  9 1001  1001   4096 8月  28 04:40 nginx-1.10.0
-rw-r--r--.  1 root root  908954 4月  26 2016 nginx-1.10.0.tar.gz

2-安装fastDFS

2.1关闭防火墙

查看防火墙状态

[root@localhost nc]# service iptables status

看到防火墙开启了

表格:filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:6379 
6    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination 

接下来关闭防火墙

service iptables stop
[root@localhost nc]# service iptables stop
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]

查看状态

[root@localhost nc]# service iptables status
iptables:未运行防火墙。

2.2.1,安装gcc,如果已经安装也可以执行,以下类似

  yum  -y install gcc
[root@localhost nc]# yum -y install gcc
已加载插件:fastestmirror, security
设置安装进程
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirrors.aliyun.com
base                                                                                                          | 3.7 kB     00:00     
extras                                                                                                        | 3.4 kB     00:00     
updates                                                                                                       | 3.4 kB     00:00     
包 gcc-4.4.7-23.el6.x86_64 已安装并且是最新版本
无须任何处理

2.2.2 安装解压命令 unzip后面用的到

yum install -y  unzip zip
[root@localhost nc]# yum install -y  unzip zip
已加载插件:fastestmirror, security
设置安装进程
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirrors.aliyun.com
包 unzip-6.0-5.el6.x86_64 已安装并且是最新版本
包 zip-3.0-1.el6_7.1.x86_64 已安装并且是最新版本
无须任何处理
[root@localhost nc]# 

2.2.3安装libevent

yum -y install libevent
[root@localhost nc]# yum -y install libevent
已加载插件:fastestmirror, security
设置安装进程
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirrors.aliyun.com
包 libevent-1.4.13-4.el6.x86_64 已安装并且是最新版本
无须任何处理

2.3安装 libfastcommon-master

先解压

unzip libfastcommon-master.zip
drwxr-xr-x.  4 root root    4096 8月  28 03:21 libfastcommon-master
-rw-r--r--.  1 root root  161971 10月 17 2016 libfastcommon-master.zip

[root@localhost nc]# cd libfastcommon-master
[root@localhost libfastcommon-master]# ll
总用量 32
-rw-r–r--. 1 root root 6670 10月 8 2016 HISTORY
-rw-r–r--. 1 root root 566 10月 8 2016 INSTALL
-rw-r–r--. 1 root root 1438 10月 8 2016 libfastcommon.spec
-rwxr-xr-x. 1 root root 3099 10月 8 2016 make.sh
drwxr-xr-x. 2 root root 4096 10月 8 2016 php-fastcommon
-rw-r–r--. 1 root root 812 10月 8 2016 README
drwxr-xr-x. 3 root root 4096 8月 28 03:21 src

执行

./make.sh
./make.sh install


[root@localhost libfastcommon-master]# ./make.sh
make: Nothing to be done for `all'.    //说明已经编译好了

[root@localhost libfastcommon-master]# ./make.sh install
mkdir -p /usr/lib64
mkdir -p /usr/lib
install -m 755 libfastcommon.so /usr/lib64
install -m 755 libfastcommon.so /usr/lib
mkdir -p /usr/include/fastcommon
install -m 644 common_define.h hash.h chain.h logger.h base64.h shared_func.h pthread_func.h ini_file_reader.h _os_define.h sockopt.h sched_thread.h http_func.h md5.h local_ip_func.h avl_tree.h ioevent.h ioevent_loop.h fast_task_queue.h fast_timer.h process_ctrl.h fast_mblock.h connection_pool.h fast_mpool.h fast_allocator.h fast_buffer.h skiplist.h multi_skiplist.h flat_skiplist.h skiplist_common.h system_info.h fast_blocked_queue.h php7_ext_wrapper.h id_generator.h /usr/include/fastcommon
[root@localhost libfastcommon-master]# 

如果出错就得先清理在重新安装

./make.sh clean
./make.sh 
./make.sh install

查看状态

[root@localhost FastDFS]# ll /etc/init.d/ | grep fdfs
-rwxr-xr-x. 1 root root   918 8月  28 22:18 fdfs_storaged
-rwxr-xr-x. 1 root root   920 8月  28 22:18 fdfs_trackerd

说明安装成功

3 配置并启动tracker服务

FastDFS的tracker和storage在刚刚的安装过程中,都已经被安装了,因此我们安装这两种角色的方式是一样的。不同的是,两种需要不同的配置文件。

我们要启动tracker,就修改刚刚看到的tarcker.conf,并且启动fdfs_trackerd脚本即可。

1)首先将模板文件复制

cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

2)修改复制后的配置文件:

vim /etc/fdfs/tracker.conf 

# 修改的内容如下:

base_path=/nc/tracker                 # 存储日志和数据的根目录

3)新建目录:

mkdir -p /nc/tracker

注意:关闭防火墙:

chkconfig iptables off

4)启动和停止

启动tracker服务器: /etc/init.d/fdfs_trackerd start

停止tracker服务器: /etc/init.d/fdfs_trackerd stop

不过安装过程中,fdfs已经被设置为系统服务,我们可以采用熟悉的服务启动方式:

service fdfs_trackerd start # 启动fdfs_trackerd服务,停止用stop

检查FastDFS Tracker Server是否启动成功:

ps -ef | grep fdfs_trackerd

设置tracker服务开机启动:

chkconfig fdfs_trackerd on

启动了

[root@localhost nc]# ps -ef | grep fdfs
root      2031     1  0 19:11 ?        00:00:02 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
root      2045     1  0 19:11 ?        00:00:01 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root      3364  2176  0 22:37 pts/0    00:00:00 grep fdfs
[root@localhost nc]#

4安装fastdfs-nginx-module

4.2.1.解压

tar -zxvf fastdfs-nginx-module_v1.16.tar.gz

4.2.2.修改config

1)进入src目录

cd fastdfs-nginx-module/src/

2)编辑config

vim config

使用以下底行命令:

:%s+/usr/local/+/usr/+g

将所有的/usr/local替换为 /usr,这个才是正确的目录:

[外链图片转存失败(img-e6tKTGux-1566974338655)(assets/1528192579209.png)]

4.2.3.配置nginx与FastDFS关联配置文件

复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改

cp /usr/local/nc/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

vi /etc/fdfs/mod_fastdfs.conf

修改以下配置:

connect_timeout=10                       # 客户端访问文件连接超时时长(单位:秒)

tracker_server=192.168.83.11:22122    # tracker服务IP和端口

url_have_group_name=true                # 访问链接前缀加上组名

store_path0=/nc/storage            # 文件存储路径

复制 FastDFS 的部分配置文件到/etc/fdfs 目录

cd /usr/local/nc/FastDFS/conf/
cp http.conf mime.types /etc/fdfs/

2.2.3.配置nginx与FastDFS关联配置文件

复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改

cp /usr/local/nc/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

vi /etc/fdfs/mod_fastdfs.conf

修改以下配置:

connect_timeout=10                       # 客户端访问文件连接超时时长(单位:秒)

tracker_server=192.168.63.129:22122    # tracker服务IP和端口

url_have_group_name=true                # 访问链接前缀加上组名

store_path0=/nc/storage            # 文件存储路径

复制 FastDFS 的部分配置文件到/etc/fdfs 目录

cd /usr/local/nc/FastDFS/conf/
cp http.conf mime.types /etc/fdfs/

2.3.安装Nginx的插件

2.3.1.如果没有安装过nginx

  • 安装nginx的依赖库
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
  • 解压安装包
tar -zxvf nginx-1.10.0.tar.gz
  • 配置nginx安装包,并指定fastdfs-nginx-model
cd nginx-1.10.0

./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/usr/local/nc/fastdfs-nginx-module/src

注意:在执行./configure配置nginx参数的时候,需要将fastdfs-nginx-moudle源码作为模块编译进去。

  • 编译并安装
make && make install

2.3.2.如果已经安装过nginx

1) 进入nginx目录:

cd /usr/local/nc/nginx-1.10.0/

2) 配置FastDFS 模块

./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/usr/local/nc/fastdfs-nginx-module/src

注意:这次配置时,要添加fastdfs-nginx-moudle模块

3) 编译,注意,这次不要安装(install)

make

4) 替换nginx二进制文件:

备份:

mv /usr/bin/nginx /usr/bin/nginx-bak

用新编译的nginx启动文件替代原来的:

cp objs/nginx /usr/bin/

2.3.3.启动nginx

配置nginx整合fastdfs-module模块

我们需要修改nginx配置文件,在/opt/nginx/config/nginx.conf文件中:

vim  /opt/nginx/conf/nginx.conf

将文件中,原来的server 80{ ...} 部分代码替换为如下代码:

    server {
        listen       80;
        server_name  image.nc.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是否已启动成功
在这里插入图片描述

2.3.4.设置nginx开机启动

创建一个开机启动的脚本:

vim /etc/init.d/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
版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_39205129/article/details/100115870
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢