Skip to content

Instantly share code, notes, and snippets.

@yudai09
Last active June 23, 2017 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yudai09/6580d38853300da423696e030458089f to your computer and use it in GitHub Desktop.
Save yudai09/6580d38853300da423696e030458089f to your computer and use it in GitHub Desktop.
#!/bin/sh
# TODO: error handling
if [ ${EUID:-${UID}} != 0 ]; then
echo 'root can exec this script.'
exit 1
fi
bk_suffix=.bk$(date +%Y%m%d%H%M)
# setup http(s) proxy
export http_proxy=172.22.16.250:8080
export https_proxy=172.22.16.250:8080
# backup td-agent conf dir
if [ -d /etc/init.d/td-agent${bk_suffix} ];then
echo 'skip backup td-agent''s config dir'
else
cp -pr /etc/td-agent/ /etc/td-agent${bk_suffix}
fi
####################
# intall td-agent
####################
echo 'install td-agent'
service td-agent stop
# add GPG key
rpm --import https://packages.treasuredata.com/GPG-KEY-td-agent
# add treasure data repository to yum
cat >/etc/yum.repos.d/td.repo <<'EOF';
[treasuredata]
name=TreasureData
baseurl=http://packages.treasuredata.com/2/redhat/\$releasever/\$basearch
gpgcheck=1
gpgkey=https://packages.treasuredata.com/GPG-KEY-td-agent
EOF
# update your sources
yum check-update
# install the toolbelt
yes | yum install -y td-agent
####################
# install ruby gems
####################
echo 'install ruby gems'
export PATH=$PATH:/opt/td-agent/embedded/bin/
gem install fluent-plugin-datacounter -v 0.4.5
gem install fluent-plugin-elasticsearch
gem install fluent-plugin-file-sprintf
gem install fluent-plugin-forest
gem install fluent-plugin-record-reformer
####################
# setup td-agent
####################
echo 'setup td-agent'
# first installation may fails to install td-agent's initrc
# reinstall restore and install initrc
yum reinstall -y td-agent
if [ -f /etc/init.d/td-agent${bk_suffix} ];then
echo 'skip backup td-agent''s initrc'
else
sed -i${bk_suffix} -e 's|^TD_AGENT_USER=.*$|TD_AGENT_USER=root|' /etc/init.d/td-agent
fi
sed -i -e 's|^TD_AGENT_GROUP=.*$|TD_AGENT_GROUP=root|' /etc/init.d/td-agent
diff /etc/init.d/td-agent${bk_suffix} /etc/init.d/td-agent
####################
# install fluent-plugin from git
####################
echo 'install fluent-plugin from git'
cat >/etc/yum.repos.d/cent-vm-kernel.repo <<'EOF';
[base-kernel]
name=CentOS-$releasever - Base
baseurl=http://172.16.170.30/centos/6.4_kernel/os/$basearch/
gpgcheck=0
EOF
yum install -y ruby-devel gcc git
cd /tmp
git clone https://github.com/yudai09/fluent-plugin-sendmail.git
cd fluent-plugin-sendmail
# rake test
rake install
service td-agent start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment