Forked from SeonghoonKim/graylog2-bootstrap.sh
Last active
November 11, 2017 01:57
Revisions
-
PowerWagon revised this gist
Mar 21, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -153,7 +153,7 @@ echo "Installing init script of graylog2-server..." cat << 'EOF' > /etc/init.d/graylog2-server #! /bin/sh ### BEGIN INIT INFO # Provides: graylog2-server # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 -
PowerWagon revised this gist
Mar 21, 2014 . 1 changed file with 261 additions and 160 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,33 @@ #!/bin/bash # Created Fri Mar 21 2014 # This is a fork of https://gist.github.com/SeonghoonKim/4378896 # This script will download, install and start # the following items on CentOS 6.5: # MongoDB # OpenJDK 1.7.0 # ElasticSearch 0.90.1 # Graylog2 server 0.20.1 # Graylog2 web interface 0.20.1 # # This script should be safe to run more than one time. YMMV # You can change the password for graylog2-web-interface, here: PASSWD="password" # Change the root install dir for elasticsearch and graylog2, here: APP_ROOT="/opt" # If all goes well, nothing should need to be changed below here ORIG_WKDIR=$(pwd) MONGODB_REPO="/etc/yum.repos.d/10gen-mongodb.repo" CENTOS_REPO="/etc/yum.repos.d/CentOS-Base.repo" EPEL_REPO="/etc/yum.repos.d/epel.repo" [ -f "$APP_ROOT" ] || mkdir -p $APP_ROOT if [ -f ${MONGODB_REPO} ]; then echo "$MONGODB_REPO found" else cat << 'EOF' > ${MONGODB_REPO} [10gen] @@ -18,11 +36,11 @@ baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/$basearch gpgcheck=0 EOF fi if [ -f ${CENTOS_REPO} ]; then echo "$CENTOS_REPO found" else echo "Creating $CENTOS_REPO" cat << 'EOF' > ${CENTOS_REPO} # CentOS-Base.repo for RHEL6 [base] @@ -31,7 +49,7 @@ mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os #baseurl=http://mirror.centos.org/centos/6/os/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #released updates [update] name=CentOS-6 - Updates @@ -41,11 +59,11 @@ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 EOF fi if [ -f ${EPEL_REPO} ]; then echo "$EPEL_REPO found" else echo "Creating $EPEL_REPO" cat << 'EOF' > ${EPEL_REPO} [epel] name=Extra Packages for Enterprise Linux 6 - $basearch @@ -57,88 +75,94 @@ gpgcheck=0 EOF fi echo "Stopping running services..." service graylog2-server stop service graylog2-web stop service mongod stop service elasticsearch stop #killall java MYRANDOM=$RANDOM echo "Moving old files to $APP_ROOT/OLD_$MYRANDOM..." mkdir $APP_ROOT/OLD_$MYRANDOM mv $APP_ROOT/graylog2* $APP_ROOT/elasticsearch* $APP_ROOT/OLD_$MYRANDOM rmdir $APP_ROOT/OLD_$MYRANDOM >/dev/null 2>&1 echo "Checking and/or getting files..." if [ ! -d "$APP_ROOT/sources" ]; then mkdir "$APP_ROOT/sources"; fi if [ ! -f "$APP_ROOT/sources/elasticsearch-0.90.10.noarch.rpm" ]; then curl -O "$APP_ROOT/sources/elasticsearch-0.90.10.noarch.rpm" https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.10.noarch.rpm fi if [ ! -f "$APP_ROOT/sources/graylog2-server-0.20.1.tgz" ]; then curl -O "$APP_ROOT/sources/graylog2-server-0.20.1.tgz" https://github.com/Graylog2/graylog2-server/releases/download/0.20.1/graylog2-server-0.20.1.tgz fi if [ ! -f "$APP_ROOT/sources/graylog2-web-interface-0.20.1.tgz" ]; then curl -O "$APP_ROOT/sources/graylog2-web-interface-0.20.1.tgz" https://github.com/Graylog2/graylog2-web-interface/releases/download/0.20.1/graylog2-web-interface-0.20.1.tgz fi echo "installing openjdk 1.7.0 and Dev tools..." yum -y install java-1.7.0-openjdk #yum -y groupinstall "Development tools" yum -y install pwgen echo "Installing MongoDB..." yum install -y mongo-10gen mongo-10gen-server echo "Installing init script of MongoDB..." chkconfig --level 2345 mongod on echo "Starting MongoDB..." service mongod start echo "Installing ElasticSearch..." yum -y localinstall "$APP_ROOT/sources/elasticsearch-0.90.10.noarch.rpm" echo "Coniguring ElasticSearch for graylog2..." sed -i -e 's|# cluster.name: elasticsearch|cluster.name: graylog2|' /etc/elasticsearch/elasticsearch.yml sed -i '/# index.number_of_replicas: 0/a \ index.auto_expand_replicas: 0-all' /etc/elasticsearch/elasticsearch.yml echo "Starting ElasticSearch..." service elasticsearch start echo "Installing graylog2-server..." cd $APP_ROOT tar -xf "$APP_ROOT/sources/graylog2-server-0.20.1.tgz" ln -sf graylog2-server-0.20.1 graylog2-server cd graylog2-server cp graylog2.conf.example graylog2.conf cd /etc if [ ! -L /etc/graylog2.conf ]; then mv /etc/graylog2.conf $APP_ROOT/OLD_$MYRANDOM 2> /dev/null ln -sf $APP_ROOT/graylog2-server/graylog2.conf /etc/graylog2.conf fi echo "Changing graylog2 mongo db auth..." sed -i -e 's/\(mongodb_useauth\ =\ \)true/\1false/' /etc/graylog2.conf echo "Setting graylog2 password secret..." APP_SECRET=$(pwgen -s 96) sed -i -e 's|password_secret\ =|password_secret\ =\ '$APP_SECRET'|' /etc/graylog2.conf echo "Setting graylog2 app password..." APP_PASSWD=$(echo -n $PASSWD | sha256sum |awk '{ print $1 }' ) sed -i -e 's|root_password_sha2\ =|root_password_sha2\ =\ '$APP_PASSWD'|' /etc/graylog2.conf echo "Installing init script of graylog2-server..." cat << 'EOF' > /etc/init.d/graylog2-server #! /bin/sh ### BEGIN INIT INFO # Provides: gaylog2-server # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Graylog2-server init script # Description: Graylog2-server init script ### END INIT INFO ## Source function library. . /etc/init.d/functions NAME="graylog2-server" GRAYLOG2_HOME= GRAYLOG2_JAR=$GRAYLOG2_HOME/graylog2-server.jar @@ -147,132 +171,209 @@ GRAYLOG2_OUT="/var/log/graylog2.log" PID_DIR="/var/run/graylog2" PID_FILE="${PID_DIR}/${NAME}.pid" LOCK_FILE="/var/lock/subsys/${NAME}" JAVA="/usr/bin/java" JAVA_OPTS="-server -Xms512m -Xmx512m" RUN_AS_USER=root if [ ! -d "$PID_DIR" ]; then mkdir "$PID_DIR" chown $RUN_AS_USER "$PID_DIR" fi if [ ! -r "$GRAYLOG2_JAR" ]; then echo "Cannot find $GRAYLOG2_JAR" echo "${GRAYLOG2_JAR} is absent or does not have read permission" exit 1 fi touch "$GRAYLOG2_OUT" chown $RUN_AS_USER "$GRAYLOG2_OUT" start() { echo "Starting $NAME: " COMMAND="$JAVA $JAVA_OPTS -jar $GRAYLOG2_JAR -f $GRAYLOG2_CONF -p $PID_FILE >> \"$GRAYLOG2_OUT\" 2>&1 &" daemon --check=${NAME} --user=${RUN_AS_USER} --pidfile=${PID_FILE} ${COMMAND} RETVAL=$? [ $RETVAL -eq 0 ] && touch $LOCK_FILE return $RETVAL } stop() { echo "Stopping $NAME: " killproc -p ${PID_FILE} -d 5 ${NAME} RETVAL=$? [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE return $RETVAL } restart() { stop sleep 1 start } dump() { echo "Dumping $NAME: " PID=`cat $PID_FILE` kill -3 $PID RETVAL=$? [ $RETVAL -eq 0 ] && success $"Dumped $NAME." || failure $"Failed to dump $NAME." return $RETVAL } rh_status() { status -p ${PID_FILE} ${NAME} } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 start ;; stop) rh_status_q || exit 0 stop ;; restart) restart ;; status) rh_status ;; dump) rh_status_q || exit 0 dump ;; condrestart|try-restart) rh_status_q || exit 0 restart ;; *) echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|dump}" exit 1 esac exit $? EOF sed -i -e "s|GRAYLOG2_HOME=|GRAYLOG2_HOME=$APP_ROOT/graylog2-server|" /etc/init.d/graylog2-server chmod u+x /etc/init.d/graylog2-server chkconfig graylog2-server on echo "Starting graylog2-server..." service graylog2-server start echo "Installing graylog2-web-interface..." cd $APP_ROOT tar -xf "$APP_ROOT/sources/graylog2-web-interface-0.20.1.tgz" ln -s graylog2-web-interface-0.20.1 graylog2-web-interface cd graylog2-web-interface APP_SECRET=$(pwgen -s 96) sed -i -e 's|application.secret=""|application.secret="'$APP_SECRET'"|' conf/graylog2-web-interface.conf sed -i -e 's|graylog2-server.uris=""|graylog2-server.uris="http://127\.0\.0\.1:12900/"|' conf/graylog2-web-interface.conf cat << 'EOF' > /etc/init.d/graylog2-web #! /bin/sh ### BEGIN INIT INFO # Provides: graylog2-web # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Graylog2-web-interface init script # Description: Graylog2-web-interface init script ### END INIT INFO ## Source function library. . /etc/init.d/functions NAME="graylog2-web-interface" GRAYLOG2_WEB_HOME= GRAYLOG2_WEB=$GRAYLOG2_WEB_HOME/bin/graylog2-web-interface GRAYLOG2_WEB_OUT="/var/log/graylog2-web.log" PID_FILE="$GRAYLOG2_WEB_HOME/RUNNING_PID" LOCK_FILE="/var/lock/subsys/${NAME}" JAVA="/usr/bin/java" JAVA_OPTS="-Xms${mem}m -Xmx${mem}m -XX:MaxPermSize=${perm}m -XX:ReservedCodeCacheSize=${codecache}m" RUN_AS_USER=root if [ ! -r "$GRAYLOG2_WEB" ]; then echo "Cannot find $GRAYLOG2_WEB" echo "${GRAYLOG2_WEB} is absent or does not have read permission" exit 1 fi touch "$GRAYLOG2_WEB_OUT" chown $RUN_AS_USER "$GRAYLOG2_WEB_OUT" start() { echo "Starting $NAME: " COMMAND="$GRAYLOG2_WEB >> \"$GRAYLOG2_WEB_OUT\" 2>&1 &" daemon --check=${NAME} --user=${RUN_AS_USER} --pidfile=${PID_FILE} ${COMMAND} RETVAL=$? [ $RETVAL -eq 0 ] && touch $LOCK_FILE return $RETVAL } stop() { echo "Stopping $NAME: " killproc -p ${PID_FILE} -d 5 ${NAME} RETVAL=$? [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE return $RETVAL } restart() { stop sleep 1 start } dump() { echo "Dumping $NAME: " PID=`cat $PID_FILE` kill -3 $PID RETVAL=$? [ $RETVAL -eq 0 ] && success $"Dumped $NAME." || failure $"Failed to dump $NAME." return $RETVAL } rh_status() { status -p ${PID_FILE} ${NAME} } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 start ;; stop) rh_status_q || exit 0 stop ;; restart) restart ;; status) rh_status ;; dump) rh_status_q || exit 0 dump ;; condrestart|try-restart) rh_status_q || exit 0 restart ;; *) echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|dump}" exit 1 esac exit $? EOF sed -i -e "s|GRAYLOG2_WEB_HOME=|GRAYLOG2_WEB_HOME=$APP_ROOT/graylog2-web-interface|" /etc/init.d/graylog2-web chmod u+x /etc/init.d/graylog2-web echo "Starting graylog2-web..." chkconfig graylog2-web on service graylog2-web start IP_ADDR=$(ip a |grep inet\ |grep -v 127.0.0.1 |awk '{ print $2 }'| cut -d/ -f1) echo echo "Now, log into http://$IP_ADDR:9000/" echo "with user name: admin and password: $PASSWD" echo "If there were any, your old files should be in $APP_ROOT/OLD_$MYRANDOM" echo echo "You can now use the service command on:" echo "mongod, elasticsearch, graylog2-server and graylog2-web" echo "e.g. service graylog2-web restart" echo cd $ORIG_WKDIR -
SeonghoonKim revised this gist
Dec 26, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ else cat << 'EOF' > ${MONGODB_REPO} [10gen] name=10gen Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/$basearch gpgcheck=0 EOF fi -
SeonghoonKim created this gist
Dec 26, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,278 @@ #!/bin/bash MONGODB_REPO="/etc/yum.repos.d/10gen-mongodb.repo" CENTOS_REPO="/etc/yum.repos.d/CentOS-Base.repo" EPEL_REPO="/etc/yum.repos.d/epel.repo" PASSENGER_REPO="/etc/yum.repos.d/passenger.repo" APP_ROOT="/opt" [ -f "$APP_ROOT" ] || mkdir -p $APP_ROOT if [ -f ${MONGODB_REPO} ]; then echo "$MONGODB_REPO found" else cat << 'EOF' > ${MONGODB_REPO} [10gen] name=10gen Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64 gpgcheck=0 EOF fi if [ -f ${CENTOS_REPO} ]; then echo "$CENTOS_REPO found" else echo "Creating $CENTOS_REPO" cat << 'EOF' > ${CENTOS_REPO} # CentOS-Base.repo for RHEL6 [base] name=CentOS-6 - Base mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os #baseurl=http://mirror.centos.org/centos/6/os/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #released updates [update] name=CentOS-6 - Updates mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates #baseurl=http://mirror.centos.org/centos/6/updates/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 EOF fi if [ -f ${EPEL_REPO} ]; then echo "$EPEL_REPO found" else echo "Creating $EPEL_REPO" cat << 'EOF' > ${EPEL_REPO} [epel] name=Extra Packages for Enterprise Linux 6 - $basearch #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch failovermethod=priority enabled=1 gpgcheck=0 EOF fi if [ -f ${PASSENGER_REPO} ]; then echo "$PASSENGER_REPO found" else echo "Creating $PASSENGER_REPO" cat << 'EOF' > ${PASSENGER_REPO} ### Name: Phusion Passenger RPM Repository for Red Hat Enterprise 6 ### URL: http://passenger.stealthymonkeys.com/ [passenger] name = Red Hat Enterprise $releasever - Phusion Passenger baseurl = http://passenger.stealthymonkeys.com/rhel/$releasever/$basearch mirrorlist = http://passenger.stealthymonkeys.com/rhel/mirrors #mirrorlist = file:///etc/yum.repos.d/mirrors-passenger enabled = 1 gpgcheck = 0 EOF fi echo "Installing MongoDB..." yum install -y mongo-10gen mongo-10gen-server echo "Installing init script of MongoDB..." chkconfig --level 2345 mongod on echo "Starting MongoDB..." service mongod start echo "Installing ElasticSearch..." cd $APP_ROOT curl -L http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.1.tar.gz | tar -xz ln -s elasticsearch-0.20.1/ elasticsearch echo "Installing ElasticSearch service wrapper..." cd elasticsearch/bin curl -L http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz mv elasticsearch-elasticsearch-servicewrapper-*/service . rm -rf elasticsearch-elasticsearch-servicewrapper-* cd $APP_ROOT useradd elasticsearch -d $APP_ROOT/elasticsearch chown -R elasticsearch:elasticsearch elasticsearch* sed -i -e "s|# cluster.name: elasticsearch|cluster.name: graylog2|" $APP_ROOT/elasticsearch/config/elasticsearch.yml sed -i -e "s|set.default.ES_HOME=<Path to ElasticSearch Home>|set.default.ES_HOME=$APP_ROOT/elasticsearch|" $APP_ROOT/elasticsearch/bin/service/elasticsearch.conf sed -i -e "s|#RUN_AS_USER=|RUN_AS_USER=elasticsearch|" $APP_ROOT/elasticsearch/bin/service/elasticsearch echo "Installing init script of ElasticSearch..." $APP_ROOT/elasticsearch/bin/service/elasticsearch install echo "Starting ElasticSearch..." service elasticsearch start echo "Installing graylog2-server..." cd $APP_ROOT curl -L https://github.com/downloads/Graylog2/graylog2-server/graylog2-server-0.9.6p1.tar.gz | tar -xz ln -s graylog2-server-0.9.6p1 graylog2-server cd graylog2-server mv graylog2.conf.example graylog2.conf cd /etc ln -s /windmill/graylog2-server/graylog2.conf graylog2.conf sed -i -e 's|mongodb_useauth = true|mongodb_useauth = false|' /etc/graylog2.conf echo "Installing init script of graylog2-server..." cat << 'EOF' > /etc/init.d/graylog2-server #! /bin/sh ### BEGIN INIT INFO # Provides: gaylog2-server # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Graylog2-server init script # Description: Graylog2-server init script ### END INIT INFO ## Source function library. . /etc/init.d/functions NAME="graylog2-server" GRAYLOG2_HOME= GRAYLOG2_JAR=$GRAYLOG2_HOME/graylog2-server.jar GRAYLOG2_CONF="/etc/graylog2.conf" GRAYLOG2_OUT="/var/log/graylog2.log" PID_DIR="/var/run/graylog2" PID_FILE="${PID_DIR}/${NAME}.pid" LOCK_FILE="/var/lock/subsys/${NAME}" JAVA="/usr/bin/java" JAVA_OPTS="-server -Xms512m -Xmx512m" RUN_AS_USER=root if [ ! -d "$PID_DIR" ]; then mkdir "$PID_DIR" chown $RUN_AS_USER "$PID_DIR" fi if [ ! -r "$GRAYLOG2_JAR" ]; then echo "Cannot find $GRAYLOG2_JAR" echo "${GRAYLOG2_JAR} is absent or does not have read permission" exit 1 fi touch "$GRAYLOG2_OUT" chown $RUN_AS_USER "$GRAYLOG2_OUT" start() { echo "Starting $NAME: " COMMAND="$JAVA $JAVA_OPTS -jar $GRAYLOG2_JAR -f $GRAYLOG2_CONF -p $PID_FILE >> \"$GRAYLOG2_OUT\" 2>&1 &" daemon --check=${NAME} --user=${RUN_AS_USER} --pidfile=${PID_FILE} ${COMMAND} RETVAL=$? [ $RETVAL -eq 0 ] && touch $LOCK_FILE return $RETVAL } stop() { echo "Stoping $NAME: " killproc -p ${PID_FILE} -d 5 ${NAME} RETVAL=$? [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE return $RETVAL } restart() { stop sleep 1 start } dump() { echo "Dumping $NAME: " PID=`cat $PID_FILE` kill -3 $PID RETVAL=$? [ $RETVAL -eq 0 ] && success $"Dumped $NAME." || failure $"Failed to dump $NAME." return $RETVAL } rh_status() { status -p ${PID_FILE} ${NAME} } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 start ;; stop) rh_status_q || exit 0 stop ;; restart) restart ;; status) rh_status ;; dump) rh_status_q || exit 0 dump ;; condrestart|try-restart) rh_status_q || exit 0 restart ;; *) echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|dump}" exit 1 esac exit $? EOF sed -i -e "s|GRAYLOG2_HOME=|GRAYLOG2_HOME=$APP_ROOT/elasticsearch" /etc/init.d/graylog2-server chmod u+x /etc/init.d/graylog2-server chkconfig graylog2-server on echo "Starting graylog2-server..." service graylog2-server start echo "Installing graylog2-web-interface..." yum install -y ruby ruby-devel ruby-rdoc rubygems gem install bundler yum install -y httpd mod_passenger cd $APP_ROOT curl -L https://github.com/downloads/Graylog2/graylog2-web-interface/graylog2-web-interface-0.9.6p1.tar.gz | tar -xz ln -s graylog2-web-interface-0.9.6p1 graylog2-web-interface cd graylog2-web-interface bundle install chown -R apache:apache $APP_ROOT/graylog2-web-interface* cat << EOF >> /etc/httpd/conf.d/passenger.conf <VirtualHost *:80> ServerName graylog2.example.com ServerAlias graylog2.example.com DocumentRoot $APP_ROOT/graylog2-web-interface/public SetEnv MONGOID_HOST 'localhost' SetEnv MONGOID_PORT '27017' SetEnv MONGOID_DATABASE 'graylog2' <Directory $APP_ROOT/graylog2-web-interface/public> Allow from all Options -MultiViews </Directory> </VirtualHost> EOF chkconfig --level 2345 httpd on service httpd restart