f7b600f710
1. devstack script 2. cassandra driver It is the first step on support of Cassandra. The driver is implemented by CQL statements. Change-Id: If2f9d37b1410ceaa09de2555397f1a21d2a1db4b Implements: blueprint cassandra-support
173 lines
5.8 KiB
Bash
173 lines
5.8 KiB
Bash
#!/bin/bash
|
|
#
|
|
#
|
|
# ``plugin.sh`` calls the following methods in the sourced driver:
|
|
#
|
|
# - nb_db_driver_install_server
|
|
# - nb_db_driver_install_client
|
|
# - nb_db_driver_start_server
|
|
# - nb_db_driver_stop_server
|
|
# - nb_db_driver_clean
|
|
# - nb_db_driver_configure
|
|
|
|
REDIS_VERSION=3.0.6
|
|
RUBY_VERSION=2.3
|
|
REDIS_SERVER_LIST=$REMOTE_DB_IP
|
|
REMOTE_PORT_START=$REMOTE_DB_PORT
|
|
NODE_COUNT_END=5
|
|
REMOTE_PORT_END=`expr $REMOTE_PORT_START + $NODE_COUNT_END`
|
|
REDIS_PORT=`seq $REMOTE_PORT_START $REMOTE_PORT_END`
|
|
|
|
function _configure_redis {
|
|
pushd /opt/redis3/conf
|
|
sudo sh -c "grep -q ulimit /etc/profile ||
|
|
echo ulimit -SHn 40960 >> /etc/profile"
|
|
sudo sh -c "echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse"
|
|
sudo sh -c "echo never > /sys/kernel/mm/transparent_hugepage/enabled"
|
|
sudo sh -c "echo 2048 > /proc/sys/net/core/somaxconn"
|
|
sudo sh -c "grep -q vm.overcommit_memory /etc/sysctl.conf ||
|
|
echo vm.overcommit_memory = 1 >> /etc/sysctl.conf"
|
|
sudo sh -c "sysctl -p"
|
|
for redisserver in $REDIS_SERVER_LIST; do
|
|
for port in $REDIS_PORT; do
|
|
echo "shutdown redis: "$redisserver:$port
|
|
cp redis.conf /opt/redis3/conf/redis-$port.conf
|
|
sed -i "s/6379/$port/g" redis-$port.conf
|
|
sed -i "s/daemonize no/daemonize yes/g" redis-$port.conf
|
|
sed -i "s/dump.rdb/dump-$port.rdb/g" redis-$port.conf
|
|
sed -i "s/# cluster-enabled yes/cluster-enabled yes/g" redis-$port.conf
|
|
sed -i "s/# cluster-config-file/cluster-config-file/g" redis-$port.conf
|
|
sed -i "s/pubsub 32mb 8mb 60/pubsub 0 0 0/g" redis-$port.conf
|
|
done
|
|
done
|
|
popd
|
|
}
|
|
|
|
function nb_db_driver_install_server {
|
|
if [ "$DF_REDIS_INSTALL_FROM_RUBY" == "True" ]; then
|
|
echo "Installing Redis cluster"
|
|
if [ ! -f "$DEST/redis/redis-$REDIS_VERSION/redis" ]; then
|
|
mkdir -p $DEST/redis
|
|
if [ ! -f "$DEST/redis/redis-$REDIS_VERSION.tar.gz" ]; then
|
|
wget http://download.redis.io/releases/redis-$REDIS_VERSION.tar.gz -O $DEST/redis/redis-$REDIS_VERSION.tar.gz
|
|
fi
|
|
tar xzvf $DEST/redis/redis-$REDIS_VERSION.tar.gz -C $DEST/redis
|
|
pushd $DEST/redis/redis-$REDIS_VERSION
|
|
make
|
|
|
|
cd src
|
|
sudo make PREFIX=/opt/redis3 install
|
|
sudo mkdir -p /opt/redis3/conf
|
|
sudo cp $DEST/redis/redis-$REDIS_VERSION/redis.conf /opt/redis3/conf
|
|
|
|
sudo ln -sf /opt/redis3/conf /etc/redis3
|
|
sudo cp $DEST/redis/redis-$REDIS_VERSION/src/redis-trib.rb /opt/redis3/bin/
|
|
|
|
sudo chown -hR $STACK_USER /opt/redis3/
|
|
if is_ubuntu || is_fedora; then
|
|
_configure_redis
|
|
fi
|
|
|
|
mkdir -p $DEST/ruby
|
|
if [ ! -f "$DEST/ruby/ruby-$RUBY_VERSION.0.tar.gz" ]; then
|
|
wget https://cache.ruby-lang.org/pub/ruby/$RUBY_VERSION/ruby-$RUBY_VERSION.0.tar.gz -O $DEST/ruby/ruby-$RUBY_VERSION.0.tar.gz
|
|
fi
|
|
tar xzvf $DEST/ruby/ruby-$RUBY_VERSION.0.tar.gz -C $DEST/ruby
|
|
cd $DEST/ruby/ruby-$RUBY_VERSION.0
|
|
sudo ./configure
|
|
sudo make
|
|
sudo make install
|
|
|
|
if ! sudo gem list redis | grep -q redis; then
|
|
sudo gem source -a https://rubygems.org/
|
|
sudo gem install redis
|
|
fi
|
|
|
|
popd
|
|
fi
|
|
else
|
|
if is_ubuntu; then
|
|
install_package -y redis-server
|
|
elif is_fedora; then
|
|
install_package -y redis
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function nb_db_driver_install_client {
|
|
sudo pip install "redis>=2.10.0"
|
|
sudo pip install "hiredis>=0.2.0"
|
|
}
|
|
|
|
function nb_db_driver_start_server {
|
|
create=
|
|
if is_service_enabled df-redis-server ; then
|
|
if is_ubuntu || is_fedora; then
|
|
# to acquire if should recreate cluster
|
|
for redisserver in $REDIS_SERVER_LIST; do
|
|
for port in $REDIS_PORT; do
|
|
test -f /opt/redis3/conf/nodes-$port.conf || { create=true; break 2 ; }
|
|
done
|
|
done
|
|
# start redis
|
|
for redisserver in $REDIS_SERVER_LIST; do
|
|
for port in $REDIS_PORT; do
|
|
echo $redisserver:$port
|
|
pushd /opt/redis3/
|
|
[ "$create" ] && {
|
|
|
|
sudo rm nodes* -rf
|
|
}
|
|
|
|
./bin/redis-server ./conf/redis-$port.conf &
|
|
redis_cluster="$redis_cluster"" ""$redisserver:$port"
|
|
popd
|
|
done
|
|
done
|
|
# create cluster
|
|
[ "$create" ] && {
|
|
echo "Create the Redis cluster: "$redis_cluster
|
|
pushd /opt/redis3/bin/
|
|
echo "yes" | sudo ./redis-trib.rb create --replicas 1 $redis_cluster
|
|
popd
|
|
}
|
|
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function nb_db_driver_stop_server {
|
|
if is_service_enabled df-redis-server ; then
|
|
if is_ubuntu || is_fedora; then
|
|
for redisserver in $REDIS_SERVER_LIST; do
|
|
for port in $REDIS_PORT; do
|
|
echo "Shutshow Redis: "$redisserver:$port
|
|
sudo /opt/redis3/bin/redis-cli -p $port shutdown
|
|
pushd /opt/redis3/
|
|
sudo rm -rf nodes*.conf
|
|
sudo rm -rf dump*.rdb
|
|
sudo netstat -apn | grep $port | awk '{print $7}' | cut -d '/' -f1 | xargs sudo kill -9
|
|
popd
|
|
done
|
|
done
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function nb_db_driver_clean {
|
|
sudo rm -rf /opt/redis3
|
|
if [ "$DF_REDIS_INSTALL_FROM_RUBY" == "True" ]; then
|
|
sudo gem uninstall redis
|
|
else
|
|
if is_ubuntu; then
|
|
uninstall_package -y redis-server
|
|
elif is_fedora; then
|
|
uninstall_package -y redis
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function nb_db_driver_configure {
|
|
:
|
|
}
|