database.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #!/bin/bash
  2. #
  3. # Configures the database server for TFB
  4. #
  5. # Note: This is not used for Travis-CI. See run-ci.py to see
  6. # how databases are configured for Travis.
  7. #
  8. # Note on Compatibility: TFB *only* supports Ubuntu 14.04 64bit
  9. # (e.g. trusty64). However, it's nice to retain 12.04 support
  10. # where possible, as it's still heavily used.
  11. #
  12. # Database setup is one core area where we can help ensure TFB
  13. # works on 12.04 with minimal frustration. In some cases we
  14. # manually install the DB version that's expected, instead of the
  15. # 12.04 default. In other cases we can use a 12.04 specific
  16. # configuration file. These patches are not intended to enable
  17. # benchmarking (e.g. there are no guarantees that
  18. # the databases will be tuned for performance correctly), but
  19. # they do allow users on 12.04 to install and run most TFB tests.
  20. # Some tests internally have 12.04 incompatibilities, we make no
  21. # concentrated effort to address these cases, but PR's for specific
  22. # problems are welcome
  23. set -x
  24. export DEBIAN_FRONTEND=noninteractive
  25. source /etc/lsb-release
  26. export TFB_DISTRIB_ID=$DISTRIB_ID
  27. export TFB_DISTRIB_RELEASE=$DISTRIB_RELEASE
  28. export TFB_DISTRIB_CODENAME=$DISTRIB_CODENAME
  29. export TFB_DISTRIB_DESCRIPTION=$DISTRIB_DESCRIPTION
  30. ##############################
  31. # Prerequisites
  32. ##############################
  33. sudo apt-get -y update
  34. # WARNING: DONT PUT A SPACE AFTER ANY BACKSLASH OR APT WILL BREAK
  35. # Dpkg::Options avoid hangs on Travis-CI, don't affect clean systems
  36. sudo apt-get -y install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
  37. build-essential \
  38. git \
  39. libev-dev \
  40. libpq-dev \
  41. libreadline6-dev \
  42. postgresql `# Installs 9.1 or 9.3, based on Ubuntu version` \
  43. redis-server `# Installs 2.4 or 2.6, based on Ubuntu version` \
  44. lsb-core `# Ensure that lsb_release can be used`
  45. sudo sh -c "echo '* - nofile 65535' >> /etc/security/limits.conf"
  46. # Create a user-owned directory for our databases
  47. sudo mkdir -p /ssd
  48. sudo mkdir -p /ssd/log
  49. sudo chown -R $USER:$USER /ssd
  50. # Additional user account (only use if required)
  51. sudo useradd benchmarkdbuser -p benchmarkdbpass
  52. ##############################
  53. # MySQL
  54. ##############################
  55. echo "Setting up MySQL database"
  56. sudo sh -c "echo mysql-server mysql-server/root_password_again select secret | debconf-set-selections"
  57. sudo sh -c "echo mysql-server mysql-server/root_password select secret | debconf-set-selections"
  58. sudo apt-get -y install mysql-server
  59. sudo stop mysql
  60. # disable checking of disk size
  61. sudo mv mysql /etc/init.d/mysql
  62. sudo chmod +x /etc/init.d/mysql
  63. sudo mv mysql.conf /etc/init/mysql.conf
  64. # use the my.cnf file to overwrite /etc/mysql/my.cnf
  65. sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.orig
  66. sudo mv my.cnf /etc/mysql/my.cnf
  67. sudo rm -rf /ssd/mysql
  68. sudo rm -rf /ssd/log/mysql
  69. sudo cp -R -p /var/lib/mysql /ssd/
  70. sudo cp -R -p /var/log/mysql /ssd/log
  71. sudo cp usr.sbin.mysqld /etc/apparmor.d/
  72. sudo /etc/init.d/apparmor reload
  73. sudo start mysql
  74. # Insert data
  75. mysql -uroot -psecret < create.sql
  76. rm create.sql
  77. ##############################
  78. # Postgres
  79. ##############################
  80. echo "Setting up Postgres database"
  81. if [ "$TFB_DISTRIB_CODENAME" == "precise" ]; then
  82. echo "WARNING: Force upgrading Postgres for Ubuntu 12.04"
  83. sudo apt-get remove -y postgresql postgresql-9.1 postgresql-client-9.1
  84. echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
  85. wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
  86. sudo apt-get update
  87. sudo apt-get install -y postgresql-9.3 postgresql-client-9.3
  88. sudo service postgresql start
  89. fi
  90. sudo service postgresql stop
  91. # Sometimes this doesn't work with postgresql
  92. sudo killall -s 9 -u postgres
  93. sudo mv postgresql.conf /etc/postgresql/9.3/main/postgresql.conf
  94. sudo mv pg_hba.conf /etc/postgresql/9.3/main/pg_hba.conf
  95. sudo rm -rf /ssd/postgresql
  96. sudo cp -R -p /var/lib/postgresql/9.3/main /ssd/postgresql
  97. sudo mv 60-postgresql-shm.conf /etc/sysctl.d/60-postgresql-shm.conf
  98. sudo service postgresql start
  99. sudo -u postgres psql template1 < create-postgres-database.sql
  100. sudo -u benchmarkdbuser psql hello_world < create-postgres.sql
  101. rm create-postgres-database.sql create-postgres.sql
  102. # Last chance to make sure postgresql starts up correctly
  103. sudo killall -s 9 -u postgres
  104. sudo service postgresql restart
  105. ##############################
  106. # MongoDB
  107. #
  108. # Note for 12.04: Using mongodb.org ensures 2.6 is installed
  109. ##############################
  110. echo "Setting up MongoDB database"
  111. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
  112. echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
  113. sudo apt-get -y update
  114. sudo apt-get -y remove mongodb-clients
  115. sudo apt-get -y install mongodb-org
  116. sudo service mongod stop
  117. sudo mv /etc/mongodb.conf /etc/mongodb.conf.orig
  118. sudo cp mongodb.conf /etc/mongodb.conf
  119. sudo mv mongodb.conf /etc/mongod.conf
  120. sudo rm -rf /ssd/mongodb
  121. sudo rm -rf /ssd/log/mongodb
  122. sudo cp -R -p /var/lib/mongodb /ssd/
  123. sudo cp -R -p /var/log/mongodb /ssd/log/
  124. sudo service mongod start
  125. for i in {1..45}; do
  126. nc -z localhost 27017 && break || sleep 1;
  127. echo "Waiting for MongoDB ($i/45}"
  128. done
  129. nc -z localhost 27017
  130. if [ $? -eq 0 ]; then
  131. mongo < create.js
  132. rm create.js
  133. mongod --version
  134. else
  135. >&2 echo "MongoDB did not start, skipping"
  136. fi
  137. ##############################
  138. # Apache Cassandra
  139. ##############################
  140. echo "Setting up Apache Cassandra database"
  141. sudo apt-get install -qqy openjdk-7-jdk
  142. export CASS_V=2.0.7
  143. wget -nv http://archive.apache.org/dist/cassandra/$CASS_V/apache-cassandra-$CASS_V-bin.tar.gz
  144. tar xzf apache-cassandra-$CASS_V-bin.tar.gz
  145. rm -rf /ssd/cassandra /ssd/log/cassandra
  146. mkdir -p /ssd/cassandra /ssd/log/cassandra
  147. mv cassandra/cassandra.yaml apache-cassandra-$CASS_V/conf
  148. mv cassandra/log4j-server.properties apache-cassandra-$CASS_V/conf
  149. nohup apache-cassandra-$CASS_V/bin/cassandra -p c.pid > cassandra.log
  150. for i in {1..45}; do
  151. nc -z localhost 9160 && break || sleep 1;
  152. echo "Waiting for Cassandra ($i/45}"
  153. done
  154. nc -z localhost 9160
  155. if [ $? -eq 0 ]; then
  156. cat cassandra/cleanup-keyspace.cql | apache-cassandra-$CASS_V/bin/cqlsh 127.0.0.1
  157. python cassandra/db-data-gen.py > cassandra/tfb-data.cql
  158. apache-cassandra-$CASS_V/bin/cqlsh -f cassandra/create-keyspace.cql 127.0.0.1
  159. apache-cassandra-$CASS_V/bin/cqlsh -f cassandra/tfb-data.cql 127.0.0.1
  160. rm -rf apache-cassandra-*-bin.tar.gz cassandra
  161. else
  162. >&2 echo "Cassandra did not start, skipping"
  163. fi
  164. ##############################
  165. # Redis
  166. ##############################
  167. echo "Setting up Redis database"
  168. if [ "$TFB_DISTRIB_CODENAME" == "precise" ]; then
  169. echo "WARNING: Downgrading Redis configuration for Ubuntu 12.04"
  170. # On 12.04, Redis 2.4 is installed. It doesn't support
  171. # some of the 2.6 options, so we have to remove or comment
  172. # those
  173. sed -i 's/tcp-keepalive/# tcp-keepalive/' redis.conf
  174. sed -i 's/stop-writes-on-bgsave-error/# stop-writes-on-bgsave-error/' redis.conf
  175. sed -i 's/rdbchecksum/# rdbchecksum/' redis.conf
  176. sed -i 's/slave-read-only/# slave-read-only/' redis.conf
  177. sed -i 's/repl-disable-tcp-nodelay/# repl-disable-tcp-nodelay/' redis.conf
  178. sed -i 's/slave-priority/# slave-priority/' redis.conf
  179. sed -i 's/auto-aof-rewrite-percentage/# auto-aof-rewrite-percentage/' redis.conf
  180. sed -i 's/auto-aof-rewrite-min-size/# auto-aof-rewrite-min-size/' redis.conf
  181. sed -i 's/lua-time-limit/# lua-time-limit/' redis.conf
  182. sed -i 's/notify-keyspace-events/# notify-keyspace-events/' redis.conf
  183. sed -i 's/hash-max-ziplist-entries/# hash-max-ziplist-entries/' redis.conf
  184. sed -i 's/hash-max-ziplist-value/# hash-max-ziplist-value/' redis.conf
  185. sed -i 's/zset-max-ziplist-entries/# zset-max-ziplist-entries/' redis.conf
  186. sed -i 's/zset-max-ziplist-value/# zset-max-ziplist-value/' redis.conf
  187. sed -i 's/client-output-buffer-limit/# client-output-buffer-limit/' redis.conf
  188. sed -i 's/hz 10/# hz 10/' redis.conf
  189. sed -i 's/aof-rewrite-incremental-fsync/# aof-rewrite-incremental-fsync/' redis.conf
  190. fi
  191. sudo service redis-server stop
  192. sudo mv redis.conf /etc/redis/redis.conf
  193. sudo service redis-server start
  194. bash create-redis.sh
  195. rm create-redis.sh