Linux 安装配置Redis

下载安装

wget http://download.redis.io/releases/redis-4.0.1.tar.gz
解压tar zxvf redis-4.0.1.tar.gz
make && make install

用cp命令复制到usr目录下运行

cp redis-server /usr/local/bin/
cp redis-cli /usr/local/bin/

新建目录,存放配置文件

mkdir /etc/redis
mkdir /var/redis
mkdir /var/redis/log
mkdir /var/redis/run
mkdir /var/redis/6379

在redis解压根目录中找到配置文件模板,复制到如下位置。

cp redis.conf /etc/redis/6379.conf

通过vim命令修改

daemonize yes
pidfile /var/redis/run/redis_6379.pid
logfile /var/redis/log/redis_6379.log
dir /var/redis/6379

最后运行redis:

$ redis-server /etc/redis/6379.conf

添加到系统服务并配置开机启动

进入到redis源码的utils目录,执行 ./install_server.sh ,所有选项默认即可。
修改 /etc/init.d/redis_6379 为 redis : mv /etc/init.d/redis_6379 /etc/init.d/redis

添加到系统服务:chkconfig --add redis
开机启动:chkconfig redis on
这样执行 service redis start|restart|stop 就可以控制redis的启动、重启、停止了。

参考:redis安装部署维护备份

Tomcat配置启动脚本和服务

vim /etc/init.d/tomcat

#!/bin/bash
#
# chkconfig: - 95 15
# description: Tomcat start/stop/status script

#Location of JAVA_HOME (bin files)

export JAVA_HOME=/usr/local/jdk.1.8.0_144

#Add Java binary files to PATH
export PATH=$JAVA_HOME/bin:$PATH

#CATALINA_HOME is the location of the configuration files of this instance of Tomcat
CATALINA_HOME=/usr/local/apache-tomcat-8.5.13

#TOMCAT_USER is the default user of tomcat
TOMCAT_USER=www

#TOMCAT_USAGE is the message if this script is called without any options
TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"

#SHUTDOWN_WAIT is wait time in seconds for java proccess to stop
SHUTDOWN_WAIT=20

tomcat_pid() {
echo `ps -ef | grep $CATALINA_HOME | grep -v grep | tr -s " "|cut -d" " -f2`
}

start() {
pid=$(tomcat_pid)
if [ -n "$pid" ];then
echo -e "\e[00;31mTomcat is already running (pid: $pid)\e[00m"
else
echo -e "\e[00;32mStarting tomcat\e[00m"
if [ `user_exists $TOMCAT_USER` = "1" ];then
su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
else
$CATALINA_HOME/bin/startup.sh
fi
status
fi
return 0
}

status(){
pid=$(tomcat_pid)
if [ -n "$pid" ];then
echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
else
echo -e "\e[00;31mTomcat is not running\e[00m"
fi
}

加入服务列表

chkconfig --add tomcat

启动停止tomcat

service tomcat start/stop