cd /usr/local/bin/
wget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip
unzip
cd /root/consul-ui/
wget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_web_ui.zip
unzip
vim /etc/consul.d/server/config.json
{
"bootstrap": true,
"server": true,
"log_level": "DEBUG",
"datacenter": "dc1",
"addresses": {
"http": "0.0.0.0"
},
"bind_addr": "172.16.16.92",
"node_name": "172.16.16.92",
"data_dir": "/root/consuldata",
"ui_dir": "/root/consul-ui",
"acl_datacenter": "dc1",
"acl_master_token": "",
"acl_default_policy": "deny"
}
consul agent -config-dir=/etc/consul.d/server -ui-dir=/root/consul-ui -bootstrap true -client=0.0.0.0
Good example
===============
CONSUL SERVER 172.16.16.92
===============
mkdir /etc/consul.d
vim config.json
{
"bootstrap": true,
"server": true,
"datacenter": "use1",
"data_dir": "/var/consul",
"ui_dir": "/usr/local/consul-webui",
"enable_syslog": true
}
vim common_checks.json
{
"checks": [
{
"id": "cpu-load",
"name": "Load Avg",
"script": "/usr/lib64/nagios/plugins/check_load -w 6,6,6 -c 10,10,10",
"interval": "10s",
"timeout": "1s"
},
{
"id": "procs",
"name": "Procs",
"script": "/usr/lib64/nagios/plugins/check_procs",
"interval": "10s",
"timeout": "1s"
},
{
"id": "disk-usage",
"name": "Disk Usage",
"script": "/usr/lib64/nagios/plugins/check_disk -w 15% -c 10% -r /",
"interval": "10s",
"timeout": "1s"
},
{
"id": "memory",
"name": "Memory",
"script": "/usr/lib64/nagios/plugins/check_mem -w 85 -c 90",
"interval": "10s",
"timeout": "1s"
}
]
}
vim check_consul-alerts.json
{
"check": {
"id": "consul-template-alerts",
"name": "Consul-Alerts",
"script": "/usr/lib64/nagios/plugins/check_systemd_service.sh consul-alerts",
"interval": "10s",
"timeout": "1s"
}
}
for this,
systemctl enable consul
systemctl enable consul-alerts
*******
cd /usr/bin/
wget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip
unzip *.zip
wget https://github.com/AcalephStorage/consul-alerts/releases/download/v0.5.0/consul-alerts-0.5.0-linux-amd64.tar
tar -xvf *.tar
******
mkdir /usr/local/consul-webui
wget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_web_ui.zip
unzip *.zip
******
copy nagios plugins to /usr/lib64/nagios/plugins/
https://drive.google.com/open?id=0B_HG6_iDrJyDQUdQNjJyRV9udWM
******
vim /usr/lib64/nagios/plugins/check_systemd_service.sh
#!/bin/bash
# Copyright (C) 2016 Mohamed El Morabity <melmorabity@fedoraproject.com>
#
# This module is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This software is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
PLUGINDIR=$(dirname $0)
. $PLUGINDIR/utils.sh
if [ $# -ne 1 ]; then
echo "Usage: ${0##*/} <service name>" >&2
exit $STATE_UNKNOWN
fi
service=$1
status=$(systemctl is-enabled $service 2>/dev/null)
r=$?
if [ -z "$status" ]; then
echo "ERROR: service $service doesn't exist"
exit $STATE_CRITICAL
fi
if [ $r -ne 0 ]; then
echo "ERROR: service $service is $status"
exit $STATE_CRITICAL
fi
systemctl --quiet is-active $service
if [ $? -ne 0 ]; then
echo "ERROR: service $service is not running"
exit $STATE_CRITICAL
fi
echo "OK: service $service is running"
exit $STATE_OK
********
vim /usr/lib64/nagios/plugins/utils.sh
#! /bin/sh
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
print_revision() {
echo "$1 v$2 (nagios-plugins 2.1.4)"
printf '%b' "The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\ncopies of the plugins under the terms of the GNU General Public License.\nFor more information about these matters, see the file named COPYING.\n"
}
support() {
printf '%b' "Send email to help@nagios-plugins.org if you have questions regarding use\nof this software. To submit patches or suggest improvements, send email to\ndevel@nagios-plugins.org. Please include version information with all\ncorrespondence (when possible, use output from the --version option of the\nplugin itself).\n"
}
#
# check_range takes a value and a range string, returning successfully if an
# alert should be raised based on the range. Range values are inclusive.
# Values may be integers or floats.
#
# Example usage:
#
# Generating an exit code of 1:
# check_range 5 2:8
#
# Generating an exit code of 0:
# check_range 1 2:8
#
check_range() {
local v range yes no err decimal start end cmp match
v="$1"
range="$2"
# whether to raise an alert or not
yes=0
no=1
err=2
# regex to match a decimal number
decimal="-?([0-9]+\.?[0-9]*|[0-9]*\.[0-9]+)"
# compare numbers (including decimals), returning true/false
cmp() { awk "BEGIN{ if ($1) exit(0); exit(1)}"; }
# returns successfully if the string in the first argument matches the
# regex in the second
match() { echo "$1" | grep -E -q -- "$2"; }
# make sure value is valid
if ! match "$v" "^$decimal$"; then
echo "${0##*/}: check_range: invalid value" >&2
unset -f cmp match
return "$err"
fi
# make sure range is valid
if ! match "$range" "^@?(~|$decimal)(:($decimal)?)?$"; then
echo "${0##*/}: check_range: invalid range" >&2
unset -f cmp match
return "$err"
fi
# check for leading @ char, which negates the range
if match $range '^@'; then
range=${range#@}
yes=1
no=0
fi
# parse the range string
if ! match "$range" ':'; then
start=0
end="$range"
else
start="${range%%:*}"
end="${range#*:}"
fi
# do the comparison, taking positive ("") and negative infinity ("~")
# into account
if [ "$start" != "~" ] && [ "$end" != "" ]; then
if cmp "$start <= $v" && cmp "$v <= $end"; then
unset -f cmp match
return "$no"
else
unset -f cmp match
return "$yes"
fi
elif [ "$start" != "~" ] && [ "$end" = "" ]; then
if cmp "$start <= $v"; then
unset -f cmp match
return "$no"
else
unset -f cmp match
return "$yes"
fi
elif [ "$start" = "~" ] && [ "$end" != "" ]; then
if cmp "$v <= $end"; then
unset -f cmp match
return "$no"
else
unset -f cmp match
return "$yes"
fi
else
unset -f cmp match
return "$no"
fi
}
***********
vim /etc/systemd/system/consul-alerts.service
[Unit]
Description=consul-alerts
Requires=network-online.target
After=network-online.target consul.service vault.service
[Service]
Restart=on-failure
ExecStart=/usr/bin/consul-alerts $OPTIONS start --consul-dc=use1 --watch-checks --watch-events --log-level=info
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
******
vim /etc/systemd/system/consul.service****
[Unit]
Description=consul server agent
Requires=network-online.target
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/bin/consul agent $OPTIONS -client=0.0.0.0 -bind=172.16.16.92 -config-dir=/etc/consul.d
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=/bin/consul leave
[Install]
WantedBy=multi-user.target
service consul-alerts restart
service consul restart
consul members
========
CLIENT 172.16.16.88
========
vim /etc/systemd/system/consul.service
[Unit]
Description=consul server agent
Requires=network-online.target
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/bin/consul agent -client=0.0.0.0 -bind=172.16.16.88 -config-dir=/etc/consul.d
ExecReload=/bin/kill -HUP
KillSignal=/bin/consul leave
[Install]
WantedBy=multi-user.target
********
mkdir /etc/consul.d/
vim common_checks.json{
"checks": [
{
"id": "cpu-load",
"name": "Load Avg",
"script": "/usr/lib64/nagios/plugins/check_load -w 6,6,6 -c 10,10,10",
"interval": "10s",
"timeout": "1s"
},
{
"id": "procs",
"name": "Procs",
"script": "/usr/lib64/nagios/plugins/check_procs",
"interval": "10s",
"timeout": "1s"
},
{
"id": "disk-usage",
"name": "Disk Usage",
"script": "/usr/lib64/nagios/plugins/check_disk -w 15% -c 10% -r /",
"interval": "10s",
"timeout": "1s"
},
{
"id": "memory",
"name": "Memory",
"script": "/usr/lib64/nagios/plugins/check_mem -w 85 -c 90",
"interval": "10s",
"timeout": "1s"
}
]
}
*********
vim config.json
{
"server": false,
"datacenter": "use1",
"data_dir": "/var/consul",
"enable_syslog": true,
"start_join": [ "172.16.16.92" ]
}
********
vim service_check.json
{
"service": {
"name": "Ansible",
"address": "172.16.16.88",
"port": 8080,
"checks": [
{
"script": "/usr/lib64/nagios/plugins/check_tcp -H 172.16.16.88 -p 8080",
"interval": "10s"
}
]
}
}
*********
cd /usr/bin
wget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip
unzip *.zip
*********
copy nagios plugins to /usr/lib64/nagios/plugins/
https://drive.google.com/open?id=0B_HG6_iDrJyDQUdQNjJyRV9udWM
*********
service consul restart
%%%%%%%%%%%%%%%%%%%
consul centos 6
mv plugins /usr/lib64/nagios/
chmod 775 /usr/lib64/nagios/ -R
mkdir /etc/consul.d/
cd /bin/
wget https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_linux_amd64.zip
unzip consul_0.7.5_linux_amd64.zip
rm -rf consul_0.7.5_linux_amd64.zip
cd /etc/init.d/
vim consul
#!/bin/bash
#
# consul Manage the consul agent
#
# chkconfig: 2345 95 95
# description: Consul is a tool for service discovery and configuration
# processname: consul
# config: /etc/consul.conf
# pidfile: /var/run/consul.pid
### BEGIN INIT INFO
# Provides: consul
# Required-Start: $local_fs $network
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage the consul agent
# Description: Consul is a tool for service discovery and configuration
### END INIT INFO
# source function library
. /etc/rc.d/init.d/functions
prog="consul"
user="root"
exec="/bin/$prog"
pidfile="/var/run/$prog.pid"
lockfile="/var/lock/subsys/$prog"
logfile="/var/log/$prog.log"
confdir="/etc/consul.d"
bindip="172.16.1.05" ///////client server address
# pull in sysconfig settings
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
export GOMAXPROCS=${GOMAXPROCS:-2}
start() {
[ -x $exec ] || exit 5
[ -f $conffile ] || exit 6
[ -d $confdir ] || exit 6
umask 077
touch $logfile $pidfile
chown $user:$user $logfile $pidfile
echo -n $"Starting $prog: "
## holy shell shenanigans, batman!
## daemon can't be backgrounded. we need the pid of the spawned process,
## which is actually done via runuser thanks to --user. you can't do "cmd
## &; action" but you can do "{cmd &}; action".
daemon \
--pidfile=$pidfile \
--user=$user \
" { $exec agent -bind=$bindip -config-dir=$confdir $1 &>> $logfile & } ; echo \$! >| $pidfile "
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $lockfile
sleep 2
return $RETVAL
}
stop() {
echo -n $"Shutting down $prog: "
## graceful shutdown with SIGINT
killproc -p $pidfile $exec -INT
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
return $RETVAL
}
restart() {
stop
sleep 2
start
}
reload() {
echo -n $"Reloading $prog: "
killproc -p $pidfile $exec -HUP
echo
}
force_reload() {
restart
}
rh_status() {
status -p "$pidfile" -l $prog $exec
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
bootstrap)
rh_status_q && exit 0
start -bootstrap
;;
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {bootstrap|start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?
cd /etc/consul.d/
vim config.json
vim common_checks.json
service consul restart
%%%%%%%%%%%%%%%%%%%
add mail alerts via web interface
.
.
.
===================================
Grafana / influxdb / telegraf client
http://foxutech.com/setup-influxdb-grafana-and-telegraf-on-ubuntu/
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.3.1-1.x86_64.rpm
yum install initscripts fontconfig
rpm -Uvh grafana-4.3.1-1.x86_64.rpm
726 service grafana-server start
730 wget https://s3.amazonaws.com/influxdb/influxdb-0.10.0-1.x86_64.rpm
731 rpm -Uvh influxdb-0.10.0-1.x86_64.rpm
732 service influxdb restart
.
.
.working --> wget https://dl.influxdata.com/telegraf/releases/telegraf-1.3.2-1.x86_64.rpm
yum localinstall telegraf-1.3.2-1.x86_64.rpm
%%%%%%%%%%%
telegraf client on centos 6
wget https://dl.influxdata.com/telegraf/releases/telegraf-1.3.2-1.x86_64.rpm
yum localinstall telegraf-1.3.2-1.x86_64.rpm
rm -rf telegraf-1.3.2-1.x86_64.rpm
cd /etc/telegraf/
> telegraf.conf
vim telegraf.conf
[global_tags]
[agent]
interval = "30s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "30s"
flush_jitter = "0s"
precision = ""
debug = false
quiet = false
logfile = ""
hostname = ""
omit_hostname = false
###############################################################################
# OUTPUT PLUGINS #
###############################################################################
[[outputs.influxdb]]
urls = ["http://172.55.1.1:8086"] # required grafana server ip
database = "telegraf" # required
retention_policy = ""
write_consistency = "any"
timeout = "5s"
###############################################################################
# INPUT PLUGINS #
###############################################################################
[[inputs.cpu]]
percpu = false
totalcpu = true
collect_cpu_time = false
[[inputs.disk]]
mount_points = ["/"]
[[inputs.diskio]]
#[[inputs.kernel]]
[[inputs.mem]]
service telegraf start
mkdir /etc/telegraf/plugins
vim /etc/telegraf/plugins/postgres.sh
chmod 775 /etc/telegraf/plugins/postgres.sh
service telegraf restart
%%%%%%%%%%%%
- Networking
- Windows
- පලමු පාඩම (Windows Server 2003)
- දෙවන පාඩම (Windows Server 2008)
- තෙවන පාඩම(Replica dc එකක් ස්ථාපනය කිරීම)
- හතර වන පාඩම (File server, Printer server)
- පස් වන පාඩම (web server)
- හය වන පාඩම (Group Policy)
- හත් වන පාඩම (Windows Server Backup)
- Outlook2010 for gmail
- Windows Server 2012
- Internet proxy
- Comodo Firewall
- Linux
- Programming
- Softwares
- Research/Project
- About
No comments:
Post a Comment