Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ppabc committed Feb 23, 2017
1 parent c549ab5 commit eafcad3
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 3 deletions.
6 changes: 4 additions & 2 deletions redis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ EOF
echo vm.overcommit_memory=1 >> /etc/sysctl.conf
sysctl -p

echo "/opt/redis/bin/redis-server /opt/redis/redis.conf"
/opt/redis/bin/redis-server /opt/redis/redis.conf

echo "ok"

#sysctl vm.overcommit_memory=1
Expand All @@ -44,4 +45,5 @@ echo "ok"
#sync && echo 3 > /proc/sys/vm/drop_caches

##测试连接
#/opt/redis/bin/redis-cli -h 192.168.1.12 -p 7121 -a Msxxsdsdsfaqqqqqq
#/opt/redis/bin/redis-cli -h 127.0.0.1 -p 7121
#/opt/redis/bin/redis-cli -h 127.0.0.1 -p 7121 -a Msxxsdsdsfaqqqqqq
61 changes: 61 additions & 0 deletions redis/redis_port.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
## 2016-06-22
## http://www.aqzt.com
##email: [email protected]
##robert yu
##centos 6
##批量部署redis的脚本,输入开始端口和结束端口,自动创建文件夹,
##准备配置文件模板,批量替换配置文件端口,批量启动和停止redis

num1=$2
num2=$3
n=$2
case "$1" in

start)
### start
for ((n=$num1;n<=$num2;n++))
do
echo "port:$n ok"
/opt/redis/bin/redis-server /opt/redis/redis_$n/redis.conf
done
### start
;;

stop)
### stop
for ((n=$2;n<=$3;n++))
do
echo "port:$n ok"
ps -ef | grep redis | grep $n | grep -v grep | grep -v sh | awk '{print $2}' | xargs kill
done
echo ok
### stop
;;

restart)
echo restart
;;

install)
### install
for ((n=$num1;n<=$num2;n++))
do
echo "port:$n ok"
mkdir -p /opt/redis/redis_$n
cp /opt/redis/redis.conf /opt/redis/redis_$n/
sed -i "s/7121/$n/g" /opt/redis/redis_$n/redis.conf
/opt/redis/bin/redis-server /opt/redis/redis_$n/redis.conf
done
### install
;;

uninstall)
echo uninstall
;;

*)
echo "Usage: $SCRIPTNAME {start|stop|restart|install|uninstall}" >&2
exit 3
;;
esac
29 changes: 28 additions & 1 deletion shell/if.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,31 @@ if false; then
echo "ni"
echo "ni"
echo "ni"
fi
fi

##判断进程是否运行,运行就KILL掉,注意grep -v sh| grep -v grep
var=`ps -aef | grep $1 | grep -v sh| grep -v grep| awk '{print $2}'`
if [ !-z "$var"]
then
echo $1 process is not running
else
kill -9 $var
echo $1 process killed forcefully, process id $var.
fi


#查看指定进程是否存在
#在获取到 pid 之后,还可以根据 pid 查看对应的进程是否存在(运行),这个方法也可以用于 kill 指定的进程。
if ps -p $PID > /dev/null
then
echo "$PID is running"
# Do something knowing the pid exists, i.e. the process with $PID is running
fi

#查pid循环KILL
pids=( $(pgrep -f resque) )
for pid in "${pids[@]}"; do
if [[ $pid != $$ ]]; then
kill "$pid"
fi
done

0 comments on commit eafcad3

Please sign in to comment.