Nginx的安装及负载均衡配置、开机启动( 二 )


开机启动Tracker
在两台Tracker Server机器上,创建服务启动文件:
vi/etc/rc.d/init.d/fdfs trackerd输入如下内容:
#!/bin/bash##fdfs trackerd Starts fdfs trackerd###chkconfig: 234599 01#description: FastDFS tracker server### BEGIN INIT INFO# Provides: $fdfs trackerd###END INIT INFO#Source function library.. /etc/init.d/functionsPRG=/usr/bin/fdfs trackerdCONF=/etc/fdfs/tracker.confif[!-f $PRG ];thenecho "file $PRG does not exist!"exit 2fiif[!-f $CONF ]; thenecho "file $CONF does not exist! "exit 2fiCMD="$PRG $CONF"RETVAL=0start( {echo -n $"Starting FastDFS tracker server: "$CMD &RETVAL=$?echoreturn $RETVAL}stop () {$CMD stopRETVAL=$?return $RETVAL}rhstatus() {status fdfs trackerd}restart({$CMD restart &case "$1" instart)start;;stop)stop;;status)rhstatus;;restart|reload)restart;;condrestart)restart;;* )echo $"Usage: $0 {start IstopIstatus|restart l.condrestart}"exit 1esacexit $?按顺序执行下列命令,把 Tracker设置为开机启动:
chmod 755 /etc/rc.d/init.d/fdfs trackerdchkconfig --add fdfs_trackerdchkconfig fdfs_trackerd on开机启动 Storage
在两台Storage机器上,创建服务启动文件:
vi /etc/init.d/fdfsstoraged输入如下内容:
#!/bin/bash##fdfs storaged Starts fdfs storaged###chkconfig:2345 99 01# description: FastDFS storage server### BEGIN INIT INFO# Provides: $fdfs storaged### END INIT INFO#Source function library../etc/init.d/ functionsPRG=/usr/bin/fdfs_storagedCONF=/etc/fdfs/storage.confif [!-f $PRG ];thenecho "file $PRG does not exist! "exit 2fiif [!-f $CONF J;thenecho "file $CONF does not exist! "exit 2fiCMD="SPRG $CONF"RETVAL=0start({echo -n "Starting FastDES storage server: "$CMD &RETVAL=$?echoreturn $RETVALstop(){$CMD stopRETVAL-$?return $RETVALrhstatus() {status fdfs_storaged}restart({$CMD restart &}case "$1" instart)start;;stop)stopstatus)rhstatus;;restartlreload)restart;;condrestart)restart;;*)echo "Usage: $0{startlstoplstatus| restartl condrestart}"exit 1esacexit $?按顺序执行下列命令,把 Storage设置为开机启动:
chmod 755 /etclrc.d/init.d/fdfs storagedchkconfig --add fdfs storagedchkconfig fdfs storaged on开机启动Nginx
在四台机器中各创建一个Nginx启动文件:
vi /etc/init.d/nginx输入如下内容:#!/bin/bash
# chkconfig: -8515PATH=/data/nginxDESC="nginx daemon"NAME=nginxDAEMON=$PATH/sbin/$NAMECONFIGFILE=$PATH/conf/$NAME.confPIDFILE=$PATH/logs/$NAME.pidSCRIPTNAME=/etc/init.d/$NAMEset -e[-x "$DAEMON" 1llexit 0do start( {$DAEMON -c $CONFIGFILE I echo -n "nginx already running"}do_stop ({$DAEMON -s stop ll echo -n "nginx not running"}do reload() {$DAEMON-s reload ll echo -n "nginx can't reload")case "$1" instart)echo -n "Starting $DESC: $NAME"do_startecho ".";;stop)echo -n "Stopping $DESC:$NAME""do_stopecho ".";;reloadl graceful)echo -n "Reloading $DESC configuration. . ."do reloadecho ".";restart)echo -n "Restarting $DESC:$NAME"do stopdo_startecho ".";;*)echo "Usage: $SCRIPTNAME {startlstopl reloadlrestart}">&2exit 3;;esacexit 0按顺序执行下列命令,把 Nginx设置为开机启动:chmod 755 /etc/rc.d/init.d/nginx
chkconfig --add nginxchkconfig nginx on小结本章使用开源的FastDFS搭建了一个高可用的分布式文件系统,并通过Nginx为文件的访问设置了负载均衡服务,从而为微服务应用提供一个高性能的文件服务器 。
在完成安装并测试正常之后,即可在库存管理项目中配置分布式文件系统的链接地址,使用微服务与分布式文件系统进行联调 。




推荐阅读