1. yum clean all
    2. yum makecache fast
    3. yum -y install gcc gcc-c++ tcl
    4. #redis 内核参数优化
    5. cat >> /etc/sysctl.conf << "EOF"
    6. net.core.somaxconn = 2048
    7. net.ipv4.tcp_max_syn_backlog = 2048
    8. vm.overcommit_memory = 1
    9. EOF
    10. sysctl -p
    11. cat > /etc/security/limits.conf << "EOF"
    12. root soft nofile 65535
    13. root hard nofile 65535
    14. * soft nofile 65535
    15. * hard nofile 65535
    16. EOF
    17. cd /usr/local/src
    18. wget http://download.redis.io/releases/redis-5.0.9.tar.gz
    19. tar xvf redis-5.0.9.tar.gz
    20. cd redis-5.0.9
    21. make
    22. make PREFIX=/usr/local/redis install
    23. mkdir -p /usr/local/redis/{etc,logs,data}
    24. egrep -v "^$|^#" ./redis.conf >/usr/local/redis/etc/redis.conf
    25. sed -i "s/bind 127.0.0.1/bind 0.0.0.0/g" /usr/local/redis/etc/redis.conf
    26. sed -i "s/daemonize no/daemonize yes/g" /usr/local/redis/etc/redis.conf
    27. sed -i "s/dir \.\//dir \/usr\/local\/redis\/data/g" /usr/local/redis/etc/redis.conf
    28. sed -i "s/logfile \"\"/logfile \"\/usr\/local\/redis\/logs\/redis.log\"/g" /usr/local/redis/etc/redis.conf
    29. #设置redis密码
    30. echo 'requirepass ysj666' >>/usr/local/redis/etc/redis.conf
    31. #PATH配置
    32. echo "export PATH=\${PATH}:/usr/local/redis/bin" >>/etc/profile
    33. source /etc/profile
    34. vim /etc/init.d/redis
    35. #!/bin/sh
    36. #
    37. # Simple Redis init.d script conceived to work on Linux systems
    38. # as it does use of the /proc filesystem.
    39. ### BEGIN INIT INFO
    40. # Provides: redis_6379
    41. # Default-Start: 2 3 4 5
    42. # Default-Stop: 0 1 6
    43. # Short-Description: Redis data structure server
    44. # Description: Redis data structure server. See https://redis.io
    45. ### END INIT INFO
    46. REDISPORT=6379
    47. EXEC=/usr/local/redis/bin/redis-server
    48. CLIEXEC=/usr/local/redis/bin/redis-cli
    49. PIDFILE=/var/run/redis_${REDISPORT}.pid
    50. CONF="/usr/local/redis/etc/redis.conf"
    51. PASSWD="ysj666"
    52. case "$1" in
    53. start)
    54. if [ -f $PIDFILE ]
    55. then
    56. echo "$PIDFILE exists, process is already running or crashed"
    57. else
    58. echo "Starting Redis server..."
    59. $EXEC $CONF
    60. fi
    61. ;;
    62. stop)
    63. if [ ! -f $PIDFILE ]
    64. then
    65. echo "$PIDFILE does not exist, process is not running"
    66. else
    67. PID=$(cat $PIDFILE)
    68. echo "Stopping ..."
    69. $CLIEXEC -p $REDISPORT -a $PASSWD shutdown
    70. while [ -x /proc/${PID} ]
    71. do
    72. echo "Waiting for Redis to shutdown ..."
    73. sleep 1
    74. done
    75. echo "Redis stopped"
    76. fi
    77. ;;
    78. *)
    79. echo "Please use start or stop as first argument"
    80. ;;
    81. esac
    82. chmod +x /etc/init.d/redis
    83. systemctl enable redis
    84. systemctl start redis
    85. /sbin/chkconfig redis on