Friday, June 30, 2017

Mariadb 10.2.6 installation and playing

mariadb

installation

apt-get install software-properties-common
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

root@mariadbn:~# cat /etc/apt/sources.list.d/mariadb.list
deb [arch=amd64,i386] http://mirror.jmu.edu/pub/mariadb/repo/10.2/ubuntu trusty main
deb-src http://mirror.jmu.edu/pub/mariadb/repo/10.2/ubuntu trusty main


apt-get update
apt install mariadb-server

Edit Config

/etc/mysql/my.cnf

[mysqld]
.
bind-address            = 0.0.0.0
.
.

and

[galera]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so

# Galera Cluster Configuration
wsrep_cluster_name="gggggcluster"
wsrep_cluster_address="gcomm://172.16.155.182,172.16.155.183?pc.wait_prim=no"

# Galera Synchronization Configuration
wsrep_sst_method=rsync

# Galera Node Configuration
wsrep_node_address="172.16.155.182"
wsrep_node_name="mariadbn"
[mysqldump]
quick
quote-names
max_allowed_packet      = 16M

you might edit different attribute on different node

wsrep_node_address="host ip"
wsrep_node_name="hostname"

Modify remote access

GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'password';

Modify debian-sys-maint

root@mariadbn:~# cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = root
password = password
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = root
password = password
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr

Start Clustering

in first node

service mysql start --wsrep-new-cluster

in sendong node

service mysql start

Check result

mysql -uroot -ppassword

MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 2     |
+--------------------+-------+
1 row in set (0.00 sec)

Add database

create database aa;

You might check the new created database in another node.

Set up Bootstrap

It Seems Maraidb solve the boot sequence problem temporarily

Adding ?pc.wait_prim=no to wsrep_cluster_address to each node.

wsrep_cluster_address="gcomm://172.16.155.182,172.16.155.183?pc.wait_prim=no"

And connect to one of node and into mariadb with the following command.

set global wsrep_provider_options="pc.bootstrap=true";

It works well, while system reboot. If we set pc.bootstrap=true to node1,

Reboot Problem

It still have some problem in version 10.2.6 but it's better than old version. Sometimes it works, but sometimes it failed.

If you cannot restart mariadb, at any node

 root@mariadbnn:~# cat /var/lib/mysql/grastate.dat
# GALERA saved state
version: 2.1
uuid:    e1b56403-5d49-11e7-8b80-06dac255d854
seqno:   -1
safe_to_bootstrap: 0

change safe_to_bootstrap: 1 and restart it with

service mysql start --wsrep-new-cluster

Reboot test

Trouble Shooting

Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)

Method1

/etc/mysql/debian.cnf

[client]
host     = localhost
user     = debian-sys-maint
password = 5aULtSThxY8iKQf2
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = 5aULtSThxY8iKQf2
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr
mysql> GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '[debian-sys-maint password]';

Method2

replace /etc/mysql/debian.cnf

[client]
host     = localhost
user     = root
password = [password]
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = root
password = [password]
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr

Change [password] to root password that is accessing to db's password.

Master wrong sequence

Nov  5 16:12:04 mariadb3 mysqld: } joined {
Nov  5 16:12:04 mariadb3 mysqld: } left {
Nov  5 16:12:04 mariadb3 mysqld: } partitioned {
Nov  5 16:12:04 mariadb3 mysqld: })
Nov  5 16:12:04 mariadb3 mysqld: 161105 16:12:04 [Note] WSREP: New COMPONENT: primary = no, bootstrap = no, my_idx = 0, memb_num = 3
Nov  5 16:12:04 mariadb3 mysqld: 161105 16:12:04 [Note] WSREP: Flow-control interval: [28, 28]
Nov  5 16:12:04 mariadb3 mysqld: 161105 16:12:04 [Note] WSREP: Received NON-PRIMARY.
Nov  5 16:12:04 mariadb3 mysqld: 161105 16:12:04 [Note] WSREP: New cluster view: global state: c3069ad9-a23e-11e6-a5ff-cbf732092ea0:6, view# -1: non-Primary, number of nodes: 3, my index: 0, protocol version -1
Nov  5 16:12:04 mariadb3 mysqld: 161105 16:12:04 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
Nov  5 16:12:06 mariadb3 mysqld: 161105 16:12:06 [Note] WSREP: (30fec36f, 'tcp://0.0.0.0:4567') turning message relay requesting off
Nov  5 16:43:24 mariadb3 ntpdate[840]: step time server 91.189.94.4 offset 1877.225237 sec
Nov  5 16:43:39 mariadb3 ntpdate[1735]: adjust time server 91.189.94.4 offset -0.046589 sec
Nov  5 16:43:48 mariadb3 /etc/init.d/mysql[1912]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
Nov  5 16:43:48 mariadb3 /etc/init.d/mysql[1912]: #007/usr/bin/mysqladmin: connect to server at 'localhost' failed
Nov  5 16:43:48 mariadb3 /etc/init.d/mysql[1912]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111 "Connection refused")'
Nov  5 16:43:48 mariadb3 /etc/init.d/mysql[1912]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
Nov  5 16:43:48 mariadb3 /etc/init.d/mysql[1912]:
Nov  5 16:43:49 mariadb3 kernel: [   38.395295] init: plymouth-upstart-bridge main process ended, respawning

Slave Wrong Sequence

ov  5 16:43:21 mariadb2 mysqld: } joined {
Nov  5 16:43:21 mariadb2 mysqld: } left {
Nov  5 16:43:21 mariadb2 mysqld: } partitioned {
Nov  5 16:43:21 mariadb2 mysqld: })
Nov  5 16:43:21 mariadb2 mysqld: 161105 16:43:21 [Note] WSREP: New COMPONENT: primary = no, bootstrap = no, my_idx = 1, memb_num = 3
Nov  5 16:43:21 mariadb2 mysqld: 161105 16:43:21 [Note] WSREP: Flow-control interval: [28, 28]
Nov  5 16:43:21 mariadb2 mysqld: 161105 16:43:21 [Note] WSREP: Received NON-PRIMARY.
Nov  5 16:43:21 mariadb2 mysqld: 161105 16:43:21 [Note] WSREP: New cluster view: global state: c3069ad9-a23e-11e6-a5ff-cbf732092ea0:6, view# -1: non-Primary, number of nodes: 3, my index: 1, protocol version -1
Nov  5 16:43:21 mariadb2 mysqld: 161105 16:43:21 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
Nov  5 16:43:23 mariadb2 mysqld: 161105 16:43:23 [Note] WSREP: (52092468, 'tcp://0.0.0.0:4567') turning message relay requesting off

Slave Wrong Sequence

Nov  5 16:43:21 mariadb1 mysqld: } joined {
Nov  5 16:43:21 mariadb1 mysqld: } left {
Nov  5 16:43:21 mariadb1 mysqld: } partitioned {
Nov  5 16:43:21 mariadb1 mysqld: })
Nov  5 16:43:21 mariadb1 mysqld: 161105 16:43:21 [Note] WSREP: New COMPONENT: primary = no, bootstrap = no, my_idx = 2, memb_num = 3
Nov  5 16:43:21 mariadb1 mysqld: 161105 16:43:21 [Note] WSREP: Flow-control interval: [28, 28]
Nov  5 16:43:21 mariadb1 mysqld: 161105 16:43:21 [Note] WSREP: Received NON-PRIMARY.
Nov  5 16:43:21 mariadb1 mysqld: 161105 16:43:21 [Note] WSREP: New cluster view: global state: c3069ad9-a23e-11e6-a5ff-cbf732092ea0:6, view# -1: non-Primary, number of nodes: 3, my index: 2, protocol version -1
Nov  5 16:43:21 mariadb1 mysqld: 161105 16:43:21 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
Nov  5 16:43:23 mariadb1 mysqld: 161105 16:43:23 [Note] WSREP: (666a866f, 'tcp://0.0.0.0:4567') turning message relay requesting off

Wednesday, June 28, 2017

OpenTSDB Installation and Playing

opentsdb

Install OpenTSDB in Ubuntu 16.04

Preinstall

apt-get update && sudo apt-get upgrade -y && sudo reboot 

Install Java8

apt-get install -y default-jdk

Get Hbase and Install It

wget http://apache.claz.org/hbase/stable/hbase-1.2.6-bin.tar.gz
tar xzvf hbase-*.tar.gz
cd hbase*

Export Java Home

echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' >> conf/hbase-env.sh

Create Hbase and Zookeeper

for system to store data(hbase), and management data(zookeeper)

mkdir /root/hbase
mkdir /root/zookeeper

You might change above directory to other directory with large capacity drive.

edit conf/hbase-site.xml

<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>file:///root/hbase</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.dataDir</name>
    <value>/root/zookeeper</value>
  </property>
</configuration>

Execute Hbase and Test Hbase

bin/start-hbase.sh
or /root/hbase-1.2.6/bin/start-hbase.sh

Test bash shell and port enabling


./bin/hbase shell
2017-06-29 07:50:18,366 WARN  [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017

hbase(main):001:0>

and testing the port enabling

nc -v localhost 2181

Install Necessary Package

apt-get install -y gnuplot build-essential python autoconf

Install OpenTSDB

cd /root/.
git clone http://github.com/OpenTSDB/opentsdb.git
cd opentsdb 
./build.sh
cd build
make install
export HBASE_HOME=/root/hbase-1.2.6
env COMPRESSION=NONE ./src/create_table.sh
mkdir /tmp/tsd
./build/tsdb tsd --port 14242 --staticroot=/root/hbase-1.2.6/opentsdb/build/staticroot --cachedir=/tmp/tsd --auto-metric

.
.
.
quested-With, If-Modified-Since)
2017-06-28 15:22:32,580 INFO  [main] ConnectionManager: TSD concurrent connection limit set to: 0
2017-06-28 15:22:32,583 WARN  [main] PluginLoader: Unable to locate any plugins of the type: net.opentsdb.tsd.HttpSerializer
2017-06-28 15:22:32,604 INFO  [main] TSDMain: Ready to serve on /0.0.0.0:14242

Playing with OpenTSDB

This example is playing with two-dimenstinoal data.
No idea if a better way to deal with it?

upload data

edit realgps.json

[
    {
        "metric": "rrrrealgps",
        "timestamp": 1435716527,
        "value": "23.1234",
        "tags": {
           "id": "jonah",
           "loc":"x"
                   }    },
    {
        "metric": "rrrrealgps",
        "timestamp": 1435716527,
        "value": "123.2222",
        "tags": {
           "id": "jonah",
           "loc":"y"
                   }    },
    {
        "metric": "rrrrealgps",
        "timestamp": 1435716627,
        "value": "23.3333",
        "tags": {
           "id": "jonah",
           "loc":"x"
                   }    },
    {
        "metric": "rrrrealgps",
        "timestamp": 1435716627,
        "value": "123.6666",
        "tags": {
           "id": "jonah",
           "loc":"y"
                   }    }
]

put data

curl -i -H "Content-Type: application/json; charset=UTF-8" -X POST -d @realgps.json http://172.16.155.181:14242/api/put?details

Qeury data

edit grealgps.json

{
    "start": 1435716526,
    "queries": [
        {
            "metric": "rrrrealgps",
            "aggregator": "avg",
            "tags": {
                "id": "jonah",
                "loc":"*"
                           }        }
    ]}

query data

curl -i -H "Content-Type: application/json; charset=UTF-8"  -d @grealgps.json http://172.16.155.181:14242/api/query



[{"metric":"rrrrealgps","tags":{"loc":"x","id":"jonah"},"aggregateTags":[],"dps":{"1435716527":23.12339973449707,"1435716627":23.33329963684082}},{"metric":"rrrrealgps","tags":{"loc":"y","id":"jonah"},"aggregateTags":[],"dps":{"1435716527":123.22219848632812,"1435716627":123.6666030883789}}]

You might need to change the grealgps.json with "loc":"x", and you will see the different result.

[{"metric":"rrrrealgps","tags":{"loc":"x","id":"jonah"},"aggregateTags":[],"dps":{"1435716527":23.12339973449707,"1435716627":23.33329963684082}}]

Tuesday, June 27, 2017

VMware Fusion Port Forwarding in MacOS

vmwareportforward

VMware Fusion Port Forwarding in MacOS

Edit nat.conf in MacOS

sudo vim /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf

Modify the section with adding =vmip:vmport

[incomingtcp]

# Use these with care - anyone can enter into your VM through these...
# The format and example are as follows:
#<external port number> = <VM's IP address>:<VM's port number>
#8080 = 172.16.3.128:80
2222=192.168.2.143:22

Restart the system

sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --start

Result

unmeinde-MacBook-Pro:Test junmein$ ssh root@192.168.0.100 -p 2222
root@192.168.0.100's password:

You need to enter the vm's password.

Saturday, June 24, 2017

Gomobile in MAC

gomobile

Gomobile Installed in Mac

Download pkg

You might download golang's latest release in Mac.

https://storage.googleapis.com/golang/go1.8.3.darwin-amd64.pkg

And intall it by double click it.

Environment

It will install package under /Users/xxx/go

junmeinde-MacBook-Pro:src junmein$ pwd
/Users/junmein/go/src

Adding GOPATH

junmeinde-MacBook-Pro:src junmein$ export GOPATH=/Users/junmein/go

Install Gomobile and Build Framework In Mac

Get gomobile

go get golang.org/x/mobile/cmd/gomobile

Binding You golang code to IOS

junmeinde-MacBook-Pro:src junmein$ /Users/junmein/go/bin/gomobile bind -target=ios golang.org/x/mobile/example/bind/hello

You will get Hello.framework for IOS

junmeinde-MacBook-Pro:src junmein$ ls
Hello.framework golang.org

Compile Hello.Framework in Xcode

Put Hello.Framework in xcode

drag and drop hello.framework to xcode project

Adding code to existed code

import Hello
.
.
.
let msg = HelloGreetings("golang haha")

Disable Bitcode check

Project -> search -> bicode -> no

If you ignore this steps, it will case the errors

error 
link comand failed xcode framework

Thanks for this blog, it really help me a lot

https://medium.com/@fzambia/going-mobile-adapting-centrifugo-go-websocket-client-to-be-used-for-ios-and-android-app-e72dc2736f01

Result

You can download the result from my github

https://github.com/jonahwu/gomobile

More

Gomobile Installed in Ubuntu

It failed and with this exception.

/root/golang/bin/gomobile: exec: "xcrun": executable file not found in $PATH

More Reference

https://medium.com/@fzambia/going-mobile-adapting-centrifugo-go-websocket-client-to-be-used-for-ios-and-android-app-e72dc2736f01

http://blog.csdn.net/win_lin/article/details/48265493
http://blog.csdn.net/win_lin/article/details/60956485

Wednesday, June 21, 2017

Set Up Nginx Loadbalancer with Sticky Session in Kubernetes

K8S NGINX LB Controller Service

Sticky Session Setting

Edit nl.yaml

---
################################################################################
## K8S Default Backend for Nginx if no endpoint is available e.g. 404 servers
###############################################################################
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-default-backend
  namespace: kube-system
  labels:
    app: nginx-default-backend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-default-backend
  template:
    metadata:
      labels:
        app:  nginx-default-backend
        group: lb
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name:  defaultbackend
        image: 172.16.155.136:5000/uwebserverv6
        imagePullPolicy: IfNotPresent
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8000
            scheme: HTTP
          initialDelaySeconds: 30
          timeoutSeconds: 5
        ports:
        - containerPort: 8000
        resources:
          limits:
            cpu: 10m
            memory: 20Mi
          requests:
            cpu: 10m
            memory: 20Mi

---
################################################################################
## K8S Service configuration default backend. in NGINX Deployment config
## use arg --default-backend-service=$(POD_NAMESPACE)/nginx-default-backend
################################################################################
apiVersion: v1
kind: Service
metadata:
  name: nginx-default-backend
  namespace: kube-system
  labels:
    app: nginx-default-backend
    group: lb
spec:
  type: NodePort
  ports:
  - port: 8000
    targetPort: 8000
  selector:
    app: nginx-default-backend

---
##################################################################################################
## K8S config map for NGINX LB Controller. supply as arg in deployment config
## - --nginx-configmap=$(POD_NAMESPACE)/nginx-ingress-lb-cfg
## See link below for all config options
## https://github.com/kubernetes/contrib/blob/master/ingress/controllers/nginx/configuration.md
###################################################################################################
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-ingress-lb-cfg
  namespace: kube-system
  labels:
    app: nginx-ingress-lb
    group: lb
data:
  enable-sticky-sessions: 'true'   ## use ROUTE cookie to provide session affinity
  enable-vts-status: 'true'   ## Allows the replacement of the default status page nginx-module-vts

---
############################################################################################
## K8S deplox config for NGINX LB gcr.io/google_containers/nginx-ingress-controller
## https://github.com/kubernetes/contrib/tree/master/ingress/controllers/nginx
#########################################################################################
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: kube-system
  labels:
    app: nginx-ingress-lb
    group: lb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-ingress-lb
  template:
    metadata:
      labels:
        app: nginx-ingress-lb
        name: nginx-ingress-lb
        group: lb
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name: nginx-ingress-lb
        image: gcr.io/google_containers/nginx-ingress-controller:0.8.3
        imagePullPolicy: IfNotPresent
        readinessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
        livenessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
          initialDelaySeconds: 10
          timeoutSeconds: 1
        # use downward API
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        ports:
        - containerPort: 80
          hostPort: 80
        ## if you terminate SSL at the AWS ELB you don't need port 443 here
        - containerPort: 18080 ## we expose 18080 to access nginx stats in url /nginx-status
          hostPort: 18080
        ## https://github.com/kubernetes/contrib/issues/1662 --watch-namespace  to limit on one namespace
        args:
        - /nginx-ingress-controller
        - --default-backend-service=$(POD_NAMESPACE)/nginx-default-backend
        - --nginx-configmap=$(POD_NAMESPACE)/nginx-ingress-lb-cfg
---
#######################################
# K8S NGINX LB Controller Service
#######################################
apiVersion: v1
kind: Service
metadata:
  name: nginx-ingress-lb
  namespace: kube-system
  labels:
    app: nginx-ingress-lb
    group: lb
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
    service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "YOUR_AWS_CERT_ID"
    service.beta.kubernetes.io/aws-load-balancer-ssl-ports: https
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http
spec:
  type: LoadBalancer
  ports:
  - port: 443
    targetPort: 80 ## terminate ssl
    name: https
    protocol: TCP
  #- port: 80   ### disable unless you have http->https redirect or really want to support http besides https
  #  targetPort: 80
  #  name: http
  #  protocol: TCP
  - port: 18080
    targetPort: 18080
    name: nginxstatus
    protocol: TCP
  selector:
    app: nginx-ingress-lb
---
############################################################
## K8S Ingress to access Nginx status page from LB
############################################################
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: nginx-ingress-lb-stats
 namespace: kube-system
 labels:
  app: nginx-ingress-lb
  group: lb
  stage: kube-system
 annotations:
  kubernetes.io/ingress.class: nginx
spec:
 rules:
 - host: your.host.com
   http:
    paths:
    - path: /nginx_status
      backend:
       serviceName: nginx-ingress-lb
       servicePort: 18080

Create Pod with above yaml file.

kubectl create -f nl.yaml

To get loadbalancer address

root@kuberm:~/kube1.6config/deploy/nginxlb2# kubectl get ing --all-namespaces
NAMESPACE     NAME                     HOSTS           ADDRESS          PORTS     AGE
kube-system   nginx-ingress-lb-stats   your.host.com   172.16.155.160   80        1h

Client test, and with cookie setting, sticky session.

Create cookie and stor to file a.txt

curl -v  -c a.txt http://172.16.155.160

Use a.txt as cookie source.

curl -v  --cookie a.txt http://172.16.155.160

.
.
nginx-default-backend-1891278369-dwwft

You will get the result of sticky session.

Zabbix and Grafana

zabbix

Install Zabbix 3.0 and Grafana in Ubuntu 14.04

I cannot install Zabbix 3.0 in Ubuntu16.04, since some package dependency problem. So I install Zabbix 3.0 in Ubuntu 14.04.

Pre-Install

apt-get update
apt-get install apache2
apt-get install mysql-server   ## input password
apt-get install php5 php5-cli php5-common php5-mysql

Install Mariadb

If you prefer mariadb db instead of mysql, you can use the following commands.

apt-get install software-properties-common
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
add-apt-repository 'deb http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu trusty main'
apt-get update
apt-get install galera mariadb-galera-server-10.0

Edit apache2

edit /etc/php5/apache2/php.ini

[Date]
; http://php.net/date.timezone
date.timezone = 'Asia/Taipei'
echo "ServerName localhost" | tee /etc/apache2/conf-available/fqdn.conf
a2enconf fqdn
wget http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.0-1+trusty_all.deb
dpkg -i zabbix-release_3.0-1+trusty_all.deb
apt-get update
apt-get install zabbix-server-mysql zabbix-frontend-php

Setup Database

mysql -u root -ppassword
mysql> CREATE DATABASE zabbixdb;
mysql> GRANT ALL on zabbixdb.* to zabbix@localhost IDENTIFIED BY 'password';
mysql> FLUSH PRIVILEGES;
mysql> quit;
cd /usr/share/doc/zabbix-server-mysql
zcat create.sql.gz | mysql -u root -p zabbixdb    ##enter password

Setup Zabbix-Server

edit /etc/zabbix/zabbix_server.conf

 DBHost=localhost
 DBName=zabbixdb
 DBUser=zabbix
 DBPassword=password
service apache2 restart
service zabbix-server restart

Connect to Zabbix Server

connect to Zabbix from Browser

http://172.16.155.167/zabbix

SetUp auto Registration

For Linux

Set up AutoRegistration and its Action

Configuration->Action->Event source->Auto registration-> Create Action
Name: Linux host autoregistration
Conditions: Host metadata like Linux
Operations: Link to templates: Template OS Linux

You might add more Roles of Action likes DB in Zabbix Server, and adding DB to Clinet, see later.

Name: Linux host autoregistration
Conditions: Host metadata like DB
Operations: Link to templates: Template App MySQL

For Windows

Name: Windows host autoregistration
Conditions: Host metadata like Windows
Operations: Link to templates: Template OS Windows

Set up Network Monitoring

Configuration->Templaes->Templte OS Linux->Discovery -> Nework interface discovery-> update interval 30 sec

Install Zabbix Agent

Quick Install

apt-get install zabbix-agent

Install current version

wget http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix/zabbix-agent_3.0.9-1+trusty_amd64.deb
dpkg -i zabbix-agent_3.0.9-1+trusty_amd64.deb
apt-get update

Edit Zabbix-agent configuration

vim /etc/zabbix/zabbix_agentd.conf

Server=172.16.155.167
ServerActive=172.16.155.167
#Hostname=inqencdir2
HostMetadata=Linux

You can disable Hostname for using system hostname

You can add more roles here, such as DB.

HostMetadata=Linux DB

Restart zabbix-agent

service zabbix-agent restart

Set up Screen

We can plot multiple server

Screen->create Screen->Name:overall->Columns:2 -> Rows:2-> Add
Edit Screen -> Change ->Resource: Data overview ->Group:Discoverd Hosts->ADD

You will see the data. And you can add more blocks with

Edit Screen -> + ->Change 

Set up Alarm

Administration ->Email-> Name:Email->SMTP server:10.60.94.110->SMTP serverport:25->SMTPhelo:company.com->
SMTP email:zabbix@inquartik.com ->Update
Administration -> Users ->Admin-> Media -> add -> jonahwu@gmail.com ->Update
Configuration->action -> EventSource:trigger->create Action -> Name:test1->Condition->New Condition->xxxx

Adding Trigger

Adding trigger to Template "Linux OS"

Configuration->Templates -> Template OS Linux->Triggers->Create Trigger->
Name: testtriggercpu-> Expression (add)->Item->Select->Group:Template->Host:Template OS Linux
->CPU user time->Function:MaxmunValue For Period T is > N ->Last of(T):1m -> N:80 -> Insert
Severity: High ->Add

To see all the Trigger

Configuration -> Templates-> Templates OS Linux ->Triggers

Result

Configuration-> Hosts

You will see the new server added to column and with Templates information. If not, it's wrong.

Download Agent

If you need agent with 3.0, you need download it from the following url.

http://repo.zabbix.com/zabbix/3.2/ubuntu/pool/main/z/zabbix/

In CentOS

http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/
 rpm -Uvh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-agent-3.0.9-1.el6.x86_64.rpm
 yum install zabbix-agent

enable zabbix-agent after reboot.

chkconfig zabbix-agent on

make sure port enable

[root@centosz ~]# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      4564/zabbix_agentd
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      2189/sshd
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1985/cupsd
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2320/master
tcp        0      0 :::10050                    :::*                        LISTEN      4564/zabbix_agentd
tcp        0      0 :::22                       :::*                        LISTEN      2189/sshd
tcp        0      0 ::1:631                     :::*                        LISTEN      1985/cupsd
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               1982/dhclient
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               1985/cupsd

Make sure remove all iptables.

iptables --flush
service iptables save

Loggin

setfacl -m u:zabbix:r-- /var/log/syslog
or
chmod 777 /var/log/syslog

Trouble Shooting

In server check client agent

where 192.168.30.131 is client IP.

/usr/bin/zabbix_get -s 192.168.30.131 -p 10050 -k "system.hostname"

vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT

adding above line after 22 port2

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW,ESTABLISHED -m tcp --dport 10050 -j ACCEPT

Install Grafana

wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_4.3.1_amd64.deb
apt-get install -y adduser libfontconfig
dpkg -i grafana_4.3.1_amd64.deb
service grafana-server start
grafana-cli plugins install alexanderzobnin-zabbix-app
service grafana-server restart
update-rc.d grafana-server defaults 95 10

Connect to Grafana

http://172.16.155.167:3000/
login: admin 
password:admin
select Plugins -> pressing enable button
add data source 

http settings:
url http://your_zabbix_server_ip_address/zabbix/api_jsonrpc.php

Zabbix API details
Username: admin
Password: zabbix

Add

Save&Test

Create Customer Zabbix Dashboard

Home->Create New->Graph
Press Panel Title -> Edit ->DataSource:Default->DataSource:Zabbix
Group->Discoverd Hosts->Host->choose your host

Ctrl+S

Grafana Host Setting

Using Templating Mechanism is necessary, since most of role is cluster. So we need rendering with group concept.

Adding Group filter

Manage Dashboard->Templating -> New
Name:Group
DataSource:zabbix
Regex:        (empty)
Query:*
Multi-value: v
include all option: v
Save

You might see the Preview of values (shows max 20) to make sure your setting is correct.

Adding Host filter.

Name:Host
Data Source: zabbix
Query:$Group.*
Regex:^zabbix.*        #if you want to show all the hostname are zabbix(*) 
Multi-value: v
include All value: v
Save

You might see the Preview of values (shows max 20) to make sure your setting is correct.

Modify Panel

Modify all Host parameter in planel with $Host

Host: $Host

$Host is defined by Host filter

Result

You can choose different host or all to render the metrics.

The Benefit of importing/export template and modify by templating

Export

Share Dashboard->Export->Save to File

Import

Main->Dashborads->imports

Quit Deployment

Using templating can speed up your deploy, you can just import a template and modify

Templating -> Host->Edit -> Regex -> ^[new host type].*

such as
Templating -> Host->Edit -> Regex -> ^mysql.*
or 
Templating -> Host->Edit -> Regex -> .*mysql.*

You then can start to monitor the joined cluster.