1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | install_redis-php.sh install_redis.sh [root@blog_site data]# cat install_redis.sh #!/bin/bash redis_data_dir="/data/redis" redis_port="9998" DownloadFileDir="$(pwd)" InstallLogFile="$(pwd)/install.log" tmp="n" fun_failed() { printf "%-59s" "$1" echo -e "[\033[31mFAILED\033[0m]" echo -e "\033[31msee ./install.log for detail\033[0m" exit 1 } fun_ok() { printf "%-59s" "$1" echo -e "[\033[32m OK \033[0m]" } while [[ $# != 0 ]];do case $1 in -y) tmp="y" shift 1 ;; -p) redis_port=$2 shift 2 ;; -d) redis_data_dir=$2 shift 2 ;; -h) echo "usage: script that auto install redis srv" echo " -y :answer to any question which would be asked is yes" echo " -p <port> :set port that redis to listen [default: $redis_port]" echo " -d <data dir> :set data dir that redis save data [default: $redis_data_dir]" exit ;; *) echo "wrong option" exit esac done echo "=========================" echo "datadir: $redis_data_dir" echo "listen port: $redis_port" if [[ $tmp = "n" ]];then read -p "Confirm set is right [y/n]: " tmp [[ $tmp != "y" ]] && exit 2 fi echo useradd -r redis -s /sbin/nologin &>> $InstallLogFile [[ $? -ne 0 && $? -ne 9 ]] && fun_failed "useradd redis:" fun_ok "useradd redis:" ss -tnl | grep -q $redis_port [[ $? -eq 0 ]] && fun_failed "port is listenning:" yum -y install gcc gcc-c++ tcl jemalloc-devel &>> $InstallLogFile || fun_failed "install rpm:" fun_ok "install rpm:" #[[ -e redis-3.2.9.tar.gz ]] && mv redis-3.2.9.tar.gz redis-3.2.9.tar.gz.bak-$(date +%M) #wget http://download.redis.io/releases/redis-3.2.9.tar.gz -O redis-3.2.9.tar.gz &>> $InstallLogFile || fun_failed "wget redis:" #wget https://andyblog.org/files/20170727-9878347298.gz -O redis-3.2.9.tar.gz &>> $InstallLogFile || fun_failed "wget redis:" #fun_ok "wget redis:" [[ -e redis-3.2.9 ]] && mv redis-3.2.9 redis-3.2.9.bak-$(date +%M) tar xf redis-3.2.9.tar.gz &>> $InstallLogFile || fun_failed "tar xf redis:" fun_ok "tar xf redis:" [[ -e /usr/local/redis-${redis_port} ]] && fun_failed "bin dir has exist:" mkdir -p /usr/local/redis-${redis_port}/conf mkdir -p /usr/local/redis-${redis_port}/run/lock mkdir -p /var/log/redis mkdir -p $redis_data_dir chown -R redis /usr/local/redis-${redis_port}/run/ chown -R redis /var/log/redis chown -R redis $redis_data_dir cd redis-3.2.9 CpuCount=$(cat /proc/cpuinfo| grep "processor"| wc -l) make -j $CpuCount &>> $InstallLogFile || fun_failed "make redis:" fun_ok "make redis:" make PREFIX=/usr/local/redis-${redis_port} install &>> $InstallLogFile || fun_failed "make install:" fun_ok "make install:" cp ./redis.conf /usr/local/redis-${redis_port}/conf cp ./redis.conf /usr/local/redis-${redis_port}/conf/redis.conf.default cd /usr/local/redis-${redis_port}/conf sed -i "s#^daemonize.*#daemonize yes#g" ./redis.conf &>> $InstallLogFile sed -i "s#^pidfile.*#pidfile /usr/local/redis-${redis_port}/run/redis.pid#g" ./redis.conf &>> $InstallLogFile sed -i "s#^port.*#port ${redis_port}#g" ./redis.conf &>> $InstallLogFile sed -i "s#^timeout.*#timeout 300#g" ./redis.conf &>> $InstallLogFile sed -i "s#^loglevel.*#loglevel notice#g" ./redis.conf &>> $InstallLogFile sed -i "s#^logfile.*#logfile \"/var/log/redis/redis-${redis_port}.log\"#g" ./redis.conf &>> $InstallLogFile sed -i "s#^dir.*#dir ${redis_data_dir}#g" ./redis.conf &>> $InstallLogFile sed -i "s#^dbfilename.*#dbfilename redis-${redis_port}.rdb#g" ./redis.conf &>> $InstallLogFile cd $redis_data_dir [[ -e ${redis-${redis_port}.rdb} ]] && fun_failed "data file exist:" cat > /etc/profile.d/redis.sh<< EOF PATH=/usr/local/redis-${redis_port}/bin:\$PATH export PATH EOF source /etc/profile.d/redis.sh \cp $DownloadFileDir/file/redis.init /etc/init.d/redis-${redis_port} sed -i "s#/usr/local/redis#/usr/local/redis-${redis_port}#" /etc/init.d/redis-${redis_port} chmod +x /etc/init.d/redis-${redis_port} chkconfig --add redis-${redis_port} chkconfig redis-${redis_port} on \cp $DownloadFileDir/file/redis.logrotate /etc/logrotate.d/redis fun_ok "config redis:" service redis-${redis_port} start &>> $InstallLogFile &>> $InstallLogFile || fun_failed "start redis:" fun_ok "start redis:" sleep 1 /usr/local/redis-${redis_port}/bin/redis-cli -h localhost -p ${redis_port} ping | grep PONG &>> $InstallLogFile || fun_failed "get pong from redis:" fun_ok "get pong from redis:" cd $DownloadFileDir rm -rf redis-3.2.9* &>> $InstallLogFile || fun_failed "rm download file:" fun_ok "rm download file:" echo -e "\033[32mservice redis started \033[0m" echo #下面是sentinel安装 echo "install sentinel..." cd /usr/local/redis-${redis_port}/conf \cp $DownloadFileDir/file/redis.sentinel.conf ./sentinel.conf sed -i "s#redis-9998#redis-${redis_port}#g" ./sentinel.conf &>> $InstallLogFile || fun_failed "set sentinel file:" sed -i "s#^port.*#port 2${redis_port}#g" ./sentinel.conf &>> $InstallLogFile || fun_failed "set sentinel file:" chown redis ./sentinel.conf #进程会修改此文件 fun_ok "set sentinel file:" \cp $DownloadFileDir/file/redis.master_failover.sh ./master_failover.sh sed -i "s#redis-9998#redis-${redis_port}#g" ./master_failover.sh &>> $InstallLogFile || fun_failed "set failover file:" chmod +x ./master_failover.sh fun_ok "set failover file:" \cp $DownloadFileDir/file/redis.redis-9998-sentinel /etc/init.d/redis-${redis_port}-sentinel sed -i "s#redis-9998#redis-${redis_port}#g" /etc/init.d/redis-${redis_port}-sentinel &>> $InstallLogFile || fun_failed "set init file:" chmod +x /etc/init.d/redis-${redis_port}-sentinel chkconfig --add redis-${redis_port}-sentinel #chkconfig redis-${redis_port}-sentinel on fun_ok "set init file:" cat >> /etc/sudoers <<EOF #redis用户拥有ip命令权限 #Defaults requiretty Defaults:redis !requiretty redis ALL=(root) NOPASSWD:/sbin/ip, /sbin/arping, /bin/sendEmail EOF echo echo "redis " echo "listen port: $redis_port" echo "bindir: /usr/local/redis-${redis_port}" echo "service: /etc/init.d/redis-${redis_port}" echo "datadir: $redis_data_dir/redis-${redis_port}.rdb" echo "logdir: /var/log/redis/redis-${redis_port}.log" echo echo "sentinel" echo "listen port: 2${redis_port}" echo "service: /etc/init.d/redis-${redis_port}-sentinel" echo "logdir: /var/log/redis/redis-${redis_port}-sentinel.log" echo "redis sentinel is not started, you need change config file" |
---|
安装php-redis扩展
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #!/bin/bash php_bin_dir="/usr/local/php" php_data_dir="/data/web" DownloadFileDir="$(pwd)" InstallLogFile="$(pwd)/install.log" tmp="n" fun_failed() { printf "%-59s" "$1" echo -e "[\033[31mFAILED\033[0m]" echo -e "\033[31msee ./install.log for detail\033[0m" exit 1 } fun_ok() { printf "%-59s" "$1" echo -e "[\033[32m OK \033[0m]" } while [[ $# != 0 ]];do case $1 in -y) tmp="y" shift 1 ;; -b) php_bin_dir=$2 shift 2 ;; -d) php_data_dir=$2 shift 2 ;; -h) echo "usage: script that auto install redis-php extension" echo " -y :answer to any question which would be asked is yes" echo " -b <data dir> :set php bin dir [default: $php_bin_dir]" echo " -d <data dir> :set php web dir [default: $php_data_dir]" exit ;; *) echo "wrong option" exit esac done echo "=========================" echo "php_bin_dir: $php_bin_dir" echo "php_data_dir: $php_data_dir" if [[ $tmp = "n" ]];then read -p "Confirm set is right [y/n]: " tmp [[ $tmp != "y" ]] && exit 2 fi echo [[ -e $php_bin_dir ]] || fun_failed "$php_bin_dir not exist:" [[ -e $php_data_dir ]] || fun_failed "$php_data_dir not exist:" yum -y install unzip &>> $InstallLogFile || fun_failed "install rpm:" fun_ok "install rpm:" #[[ -e phpredis-develop.zip ]] && mv phpredis-develop.zip phpredis-develop.zip.bak-$(date +%M) #wget https://github.com/phpredis/phpredis/archive/develop.zip -O phpredis-develop.zip &>> $InstallLogFile || fun_failed "wget redis-php:" #wget https://andyblog.org/files/20170625-7398869242.zip -O phpredis-develop.zip &>> $InstallLogFile || fun_failed "wget redis-php:" #fun_ok "wget redis-php:" [[ -e phpredis-develop ]] && mv phpredis-develop phpredis-develop.bak-$(date +%M) unzip phpredis-develop.zip &>> $InstallLogFile || fun_failed "unzip:" fun_ok "unzip:" cd phpredis-develop $php_bin_dir/bin/phpize &>> $InstallLogFile || fun_failed "create configure file:" fun_ok "create configure file:" ./configure --with-php-config=$php_bin_dir/bin/php-config &>> $InstallLogFile || fun_failed "configure:" fun_ok "configure:" make &>> $InstallLogFile || fun_failed "make:" fun_ok "make:" make install &>> $InstallLogFile tmp=$(ls /usr/local/php/lib/php/extensions) ExtFile=/usr/local/php/lib/php/extensions/$tmp sed -i "s#^; extension_dir.*#extension_dir=\"${ExtFile}\"#g" $php_bin_dir/conf/php.ini sed -i "s#^; On windows:#extension = redis.so#g" $php_bin_dir/conf/php.ini \cp $DownloadFileDir/file/php-fpm.redis.php $php_data_dir/redis.php cd $DownloadFileDir rm -rf phpredis-develop* &>> $InstallLogFile || fun_failed "rm download file:" fun_ok "rm download file:" service php-fpm restart &>> $InstallLogFile || fun_failed "restart php-fpm:" fun_ok "restart php-fpm:" echo -e "\033[32mredis-php installed \033[0m" echo echo "php_bin_dir: $php_bin_dir" echo "php_data_dir: $php_data_dir" echo "restart the php-fom service" echo "change the redis.php " echo "visit http://localhost/redis.php" echo |
---|
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有