1.把启动命令写到rc.local里面

chmod a+x /etc/rc.d/rc.loca
echo '/usr/local/memcached/bin/memcached -u memcached -p 11211 -m 1500 -c 1024' >> /etc/rc.d/rc.local
systemctl enable rc-local
#! /bin/sh
# chkconfig: - 55 45
# description: The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/sysconfig/memcached
# Source function library - for other linux
#. /etc/rc.d/init.d/functions
# Source function library - for SUSE linux

. /lib/lsb/init-functions
PORT=11211
USER=root
#最大连接数,根据实际需求修改
MAXCONN=1024
#最大内存量,单位M
CACHESIZE=128
OPTIONS=""

if [ -f /etc/sysconfig/memcached ];then
. /etc/sysconfig/memcached
fi

# Check that networking is up.
if [ "$NETWORKING" = "no" ]
then
exit 0
fi

RETVAL=0
prog="memcached"

start () {
echo -n $"Starting $prog: "
# insure that /usr/local/memcached has proper permissions
chown $USER /usr/local/memcached

/usr/local/memcached/bin/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /usr/local/memcached/memcached.pid $OPTIONS

RETVAL=$?

echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}

stop () {
echo -n $"Stopping $prog: "
killproc memcached
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f /var/lock/subsys/memcached
rm -f /usr/local/memcached/memcached.pid
fi
}

restart () {
stop
start
}

# See how we were called.
case "$1" in

start)
start
;;
stop)
stop
;;
status)
status memcached
;;
restart|reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/memcached ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
exit 1
esac

exit $?