页面“Docker-compose教程”与“Zabbix 5 4 and 3 LTS安装入门教程”之间的差异

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
docker>Evan
 
 
第1行: 第1行:
 +
==站内资源==
 +
[[Zabbix 调用API 批量添加主机]]
 +
== zabbix server ==
 +
===pre ===
 +
这些是官网官方安装文档,记得一定要看
  
 +
https://www.zabbix.com/documentation/3.0/manual/installation/install
  
可以 Dockerfile 创建容器,docker-compse实现部署 或者直接用官方的img 利用docker-compse实现部署
+
https://www.zabbix.org/wiki/InstallOnCentOS_RHEL
  
=introduce=
+
<pre>wget -c https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.8/zabbix-3.0.8.tar.gz
<pre>
+
wget -c http://tenet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.13/zabbix-2.2.13.tar.gz</pre>
Compose项目来源于之前的fig项目,使用python语言编写,与docker/swarm配合度很高。
+
 
 +
===#配置php变量===
 +
<pre>vi /etc/php.ini
 +
date.timezone = Asia/Shanghai
 +
post_max_size = 32M
 +
max_execution_time = 300
 +
max_input_time = 300
 +
注:更改完之后需要重启nginx和php</pre>
 +
 
 +
===#安装zabbix所需的组件 ===
 +
<pre>yum -y install net-snmp-devel curl-devel
 +
#yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI php-gd php-xml php-bcmath
 +
groupadd zabbix && useradd -g zabbix zabbix
 +
tar xvf zabbix-3.0.8.tar.gz && cd zabbix-3.0.8
 +
#tar xvf zabbix-2.2.13.tar.gz && cd zabbix-2.2.13
 +
 
 +
#./configure –enable-server –enable-agent –with-mysql –enable-ipv6 –with-net-snmp –with-libcurl –with-libxml2
 +
 
 +
##或者默认安装路径 make是不用的
 +
./configure --sysconfdir=/etc/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2 && make install
 +
</pre>
 +
===添加zabbix服务对应的端口(可以省略,但是官方建议有)===
 +
<pre>cat >>/etc/services<< EOF
 +
zabbix-agent 10050/tcp #Zabbix Agent
 +
zabbix-agent 10050/udp #Zabbix Agent
 +
zabbix-trapper 10051/tcp #Zabbix Trapper
 +
zabbix-trapper 10051/udp #Zabbix Trapper
 +
EOF</pre>
 +
 
 +
===配置文件===
 +
<pre>##好像是这个起效果的呢 –sysconfdir=/etc/zabbix 有这个,不用下面的命令了
 +
#vim /usr/local/etc/zabbix_server.conf
 +
#cd zabbix-2.0.7
 +
 
 +
#mkdir /etc/zabbix
 +
#cp conf/*.conf /etc/zabbix
 +
 
 +
mkdir /var/log/zabbix ;chown zabbix:zabbix /var/log/zabbix;
  
Compose 是 Docker 容器进行编排的工具,定义和运行多容器的应用,可以一条命令启动多个容器,使用Docker Compose不再需要使用shell脚本来启动容器。
 
  
Compose 通过一个配置文件来管理多个Docker容器,在配置文件中,所有的容器通过services来定义,然后使用docker-compose脚本来启动,停止和重启应用,和应用中的服务以及所有依赖服务的容器,非常适合组合使用多个容器进行开发的场景。
+
#zabbix web代码
 +
mkdir -p /data/www/zabbix;
 +
cp -r frontends/php/* /data/www/zabbix
  
docker-compose默认的模板文件是 docker-compose.yml,其中定义的每个服务都必须通过 image 指令指定镜像或 build 指令(需要 Dockerfile)来自动构建。
+
修改zabbix连接的数据库的用户名和密码
 +
vi /etc/zabbix/zabbix_server.conf
  
其它大部分指令都跟 docker run 中的类似。
+
DBHost=127.0.0.1
如果使用 build 指令,在 Dockerfile 中设置的选项(例如:CMD, EXPOSE, VOLUME, ENV 等) 将会自动被获取,无需在 docker-compose.yml 中再次设置。
+
DBName=zabbix
 +
DBUser=zabbix
 +
DBPassword='123'
 +
DBPort=3306 #如果数据库是用sock文件的方式,这里可以是sock文件的路径
  
使用Compose 基本上分为三步:
+
添加数据库Lib文件位置到/etc/ld.so.conf中,并使其生效
1.Dockerfile 定义应用的运行环境
+
echo ‘/usr/local/mysql/lib/mysql/’ >> /etc/ld.so.conf
2.docker-compose.yml 定义组成应用的各服务
 
3.docker-compose up 启动整个应用
 
---------------------
 
  
Compose 项目是 Docker 官方的开源项目,负责实现对 Docker 容器集群的快速编排。
+
ldconfig
  
在日常工作中,经常会碰到需要多个容器相互配合来完成某项任务的情况。例如要实现一个 Web 项目,除了 Web服务容器本身,往往还需要再加上后端的数据库服务容器,甚至还包括负载均衡容器等。
+
为zabbix的启动、关闭和重启的脚本文件做链接,方便系统可以找得到
  
Compose 恰好满足了这样的需求。它允许用户通过一个单独的 docker-compose.yml 模板文件(YAML 格式)来定义一组相关联的应用容器为一个项目。
+
给zabbix服务端程序做软链接 我用默认的config 应该是不用的
 +
cd /usr/local/zabbix/bin/
 +
for i in *;do ln -s /usr/local/zabbix/bin/${i} /usr/bin/${i};done
 +
cd /usr/local/zabbix/sbin/
 +
for i in *;do ln -s /usr/local/zabbix/sbin/${i} /usr/sbin/${i};done
  
Compose 中有两个重要的概念:
+
拷贝zabbix服务端和客户端启动脚本到/etc/init.d目录下.
 +
cd misc/init.d/
 +
cp fedora/core/zabbix_server /etc/init.d/
 +
cp fedora/core/zabbix_agentd /etc/init.d/
 +
chmod +x /etc/init.d/zabbix_agentd
 +
chmod +x /etc/init.d/zabbix_server</pre>
  
    服务 (service):一个应用的容器,实际上可以包括若干运行相同镜像的容器实例。
+
===3 Create Zabbix database===
 +
<pre>SQL scripts are provided for creating database schema and inserting the dataset
 +
#https://www.zabbix.com/documentation/3.0/manual/appendix/install/db_scripts
 +
#https://www.zabbix.com/documentation/2.2/manual/appendix/install/db_scripts
  
    项目 (project):由一组关联的应用容器组成的一个完整业务单元,在 docker-compose.yml 文件中定义。
+
mysql>create database zabbix character set utf8 collate utf8_bin;;grant all on zabbix.* to zabbix@localhost identified by '123';flush privileges;
  
</pre>
+
将zabbix源码包中的数据导入到新建的zabbix数据库
 +
##这个和老的版本有点不同 第一个是zabbix的数据库表结构,要先导入。
  
=Docker-compose常用命令=
+
. /etc/profile
<pre>
+
cd ../..
docker-compose --help
+
mysql -uroot -p'evan' zabbix< database/mysql/schema.sql
 +
mysql -uroot -p'evan' zabbix< database/mysql/images.sql
 +
mysql -uroot -p'evan' zabbix< database/mysql/data.sql
  
docker-compose up -d nginx                    构建建启动nignx容器 # #这个是写在yml里面的server名  查看 文件, 不是容器名
+
vi /etc/init.d/zabbix_server # 的可以不改,修改一下变量的值 因为我是默认用 configure
 +
# base zabbix dir
 +
BASEDIR=/usr/local
 +
# binary file
 +
ZABBIX_SUCKERD=$BASEDIR/sbin/zabbix_server<pre>
  
docker-compose exec nginx bash            登录到nginx容器中
+
===fping的安装和使用详解===
 +
<pre>http://rickie622.blog.163.com/blog/static/2123881120121121111720941/
 +
http://netsecurity.51cto.com/art/201101/242200.htm
 +
#当然 下载zip包也是可以的
 +
git clone https://github.com/schweikert/fping.git
 +
cd fping
 +
./autogen.sh
 +
./configure
 +
make -j2 && make install
  
docker-compose down                              删除所有nginx容器,镜像
+
#修改一下配置文件
 +
vim /etc/zabbix_server.conf
 +
#vim /usr/local/etc/zabbix_server.conf
 +
FpingLocation=/usr/local/sbin/fping</pre>
  
docker-compose ps                                  显示所有容器
+
===启动zabbix,并且添加开机自启动===
 +
<pre>service zabbix_server start
 +
service zabbix_agentd start #启动服务
  
docker-compose restart nginx                  重新启动nginx容器 #这个是写在yml里面的server名  不是容器名
+
chkconfig zabbix_server on
 +
chkconfig zabbix_agentd on #开机自启动
  
docker-compose run --no-deps --rm php-fpm php -v  在php-fpm中不启动关联容器,并容器执行php -v 执行完成后删除容器
+
在Nginx服务中添加zabbix虚拟主机
 +
#vim /usr/local/nginx/conf/vhosts/monitor.conf
  
docker-compose build nginx                    构建镜像 。       
+
这些都不要,不然没有web安装向导的
 +
#cd zabbix/conf
 +
#cp zabbix.conf.php.example zabbix.conf.php ;
 +
#chmod 777 zabbix.conf.php
  
docker-compose build --no-cache nginx  不带缓存的构建。
+
iptables -I INPUT -p tcp –dport 80 -j ACCEPT
  
docker-compose logs  nginx                    查看nginx的日志
+
zabbix server is not running
 +
Zabbix Server is not running: the information displayed may not be current
 +
http://song49.blog.51cto.com/4480450/1200151</pre>
  
docker-compose logs -f nginx                  查看nginx的实时日志
+
===(4)设置zabbix服务IP和端口,name可以忽略===
+
<pre>
 +
ps:
 +
post_max_size = 16M
 +
PHP option “max_execution_time” 30 300 Fail
 +
PHP option “max_input_time” 60 300 Fail
 +
PHP option “date.timezone” unknown Fai
 +
date.timezone = Asia/Shanghai
  
docker-compose config  -q                        验证(docker-compose.yml)文件配置,当配置正确时,不输出任何内容,当文件配置错误,输出错误信息。
+
PHP option “always_populate_raw_post_data” must be set to “-1”
  
docker-compose events --json nginx      以json的形式输出nginx的docker日志
+
port 10051
  
docker-compose pause nginx                暂停nignx容器
+
Zabbix frontend is ready! The default user name is Admin, password zabbix.</pre>
 +
===超级用户密码修改 ===
 +
<pre>
 +
2.2 用户名第一个字母要大写 也就是Admin
 +
默认的用户名:admin 密码:zabbix
  
docker-compose unpause nginx            恢复ningx容器
+
哪里改登录用户和密码呢
 +
use zabbix;
 +
select userid,alias,passwd from users; #查看
  
docker-compose rm nginx                      删除容器(删除前必须关闭容器)
+
+--------+------------+----------------------------------+
 +
| userid | alias      | passwd                          |
 +
+--------+------------+----------------------------------+
 +
|      1 | Admin      | 5fce1b3e34b520afeffb37ce08c7cd66 |
  
docker-compose stop nginx                    停止nignx容器
 
  
docker-compose start nginx                    启动nignx容器
+
#如果为zabbix 3.0  直接这样就行了
 +
update users set passwd=MD5('12345') where userid=1;
  
  
note:
+
#zabbix 2.x
docker-compose  知道补充
+
重新开个终端,生成一个MD5加密的密码,这里密码设置的是redhat
  
docker-compose  ps
+
[root@localhost ~]# echo -n 12345678 |openssl md5 #-n就表示不输入回车符,不加-n,否则就不是这个结果了。
          Name                        Command              State                        Ports                     
+
(stdin)= 25d55ad283aa400af464c76d713c07ad
--------------------------------------------------------------------------------------------------------------------
 
docker4jenkins_jenkins_1  /sbin/tini -- /usr/local/b ...  Up      0.0.0.0:50000->50000/tcp, 0.0.0.0:7099->8080/tcp
 
  
docker-compose  stop  jenkins #后面是加server名  服务名称
+
接着上面的为admin用户设定一个密码
 
docker-compose.yml
 
 
services:
 
  jenkins:
 
    image: jenkins/jenkins:lts
 
  
所以
+
mysql> update users set passwd='25d55ad283aa400af464c76d713c07ad' where userid = '1';
docker-compose  start  jenkins
+
#或者直接使用update users set passwd=md5(“12345678”) where userid=’1′;
</pre>
+
Query OK, 1 row affected (0.01 sec)
 +
Rows matched: 1 Changed: 1 Warnings: 0
  
=install=
+
mysql> flush privileges;
<pre>
+
Query OK, 0 rows affected (0.01 sec)
#方法1 如果是国内网络太慢 可以把变量换成对应的值 然后先在desktop 下载回来
 
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
 
  
#方法 2  有时axel最快了
+
mysql> quit
#https://github.com/docker/compose/releases/download/1.24.0/docker-compose-linux-x86_64  -o /usr/local/bin/docker-compose
+
Bye
sudo chmod +x /usr/local/bin/docker-compose
 
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
 
$  docker-compose --version
 
docker-compose version 1.24.0, build 0aa59064</pre>
 
  
=Get started with Docker Compose=
+
zabbix登陆账户admin密码修改
==Step 1: Setup==
+
http://pvbutler.blog.51cto.com/7662323/1734003
===1.Create a directory for the project:===
 
<pre> mkdir composetest &&  cd composetest</pre>
 
===Create a file called app.py in your project directory and paste this in:===
 
<pre>import time
 
  
import redis
+
yum install ntp ntpdate -y
from flask import Flask
+
chkconfig ntpd on
 +
/etc/init.d/ntpd start
  
app = Flask(__name__)
+
*/30 * * * * /usr/sbin/ntpdate pool.ntp.org
cache = redis.Redis(host='redis', port=6379)
 
  
 +
在29行这后添加
 +
sed -i ’29a user=mysql’ /etc/my.cnf
 +
sed -i ’29a character-set-server=utf8′ /etc/my.cnf
 +
sed -i ’29ainnodb_file_per_table=1′ /etc/my.cnf
 +
重启mysqld</pre>
  
def get_hit_count():
+
===防火墙设置 ===
    retries = 5
+
<pre>这个要看一下先,尽量用严格些的防火墙设置
    while True:
 
        try:
 
            return cache.incr('hits')
 
        except redis.exceptions.ConnectionError as exc:
 
            if retries == 0:
 
                raise exc
 
            retries -= 1
 
            time.sleep(0.5)
 
  
 +
#on zabbix-agent
  
@app.route('/')
+
iptables -A INPUT -s zabbixserverip  -p tcp -m tcp --dport 10050 -m comment --comment "zabbix_server listen " -j ACCEPT
def hello():
+
#iptables -A INPUT -s zabbixserverip  -p tcp -m tcp --dport 10050 -m comment --comment "zabbix_agentd listen " -j ACCEPT
    count = get_hit_count()
 
    return 'Hello World! I have been seen {} times.\n'.format(count)
 
  
if __name__ == "__main__":
+
#这下面的防火墙rule 不要用
    app.run(host="0.0.0.0", debug=True)  </pre>
+
vi /etc/sysconfig/iptables
===3.Create another file called requirements.txt in your project directory and paste this in===
+
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
<pre>flask
+
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
redis</pre>
+
-A INPUT -m state –state NEW -m tcp -p tcp –dport 10050 -j ACCEPT
==Step 2: Create a Dockerfile==
+
-A INPUT -m state –state NEW -m tcp -p tcp –dport 10051 -j ACCEPT
<pre>
 
FROM python:3.4-alpine
 
ADD . /code
 
WORKDIR /code
 
RUN pip install -r requirements.txt
 
CMD ["python", "app.py"]</pre>
 
==Step 3: Define services in a Compose file==
 
===Create a file called docker-compose.yml===
 
<pre>
 
version: '3'
 
services:
 
  web:
 
    build: .
 
    ports:
 
    - "5000:5000"
 
  redis:
 
    image: "redis:alpine"
 
</pre>
 
==Step 4: Build and run your app with Compose==
 
<pre>docker-compose up -d# (后台运行这些containers) 还是这个好
 
#马上访问就行了 哈哈 不用一直等
 
web_1    |    Use a production WSGI server instead.
 
web_1    |  * Debug mode: on
 
web_1    |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 
web_1    |  * Restarting with stat
 
  
Enter http://0.0.0.0:5000/ in a browser to see the application running.</pre>
+
/etc/init.d/iptables restart
  
==Step 5: Edit the Compose file to add a bind mount==
+
中文在右上角的用户里面哦
Edit docker-compose.yml in your project directory to add a bind mount for the web service:
 
<pre>
 
version: '3'
 
services:
 
  web:
 
    build: .
 
    ports:
 
    - "5000:5000"
 
    volumes:
 
    - .:/code
 
  redis:
 
    image: "redis:alpine"
 
#胶布的端口是机器的5000 后面的端口是容器的5000  volumes 也是这样顺序
 
</pre>
 
The new volumes key mounts the project directory (current directory) on the host to /code inside the container, allowing you to modify the code on the fly, without having to rebuild the image 把当前目录mounts 到容器的/code
 
  
  volumes:
+
Starting php_fpm /usr/local/php/bin/php-cgi: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
    - ~/test/composetest:/code  #  将主机的当前目录映射为容器内部的 /code数据卷          把当前目录 ~/test/composetest mounts 到容器的/code
+
failed
  
 +
by default install the daemon binaries (zabbix_server, zabbix_agentd, zabbix_proxy) in /usr/local/sbin and the client binaries (zabbix_get, zabbix_sender) in /usr/local/bin.</pre>
  
 +
===4.0图像显示字体乱码的解决方法===
 
<pre>
 
<pre>
eg:
 
  
#容器
+
#传输字体
evan@latop:~/test/composetest$ docker exec -it b4f882c81522 /bin/sh
+
cp  /root/STKAITI.TTF  /usr/share/zabbix/assets/fonts
/code # pwd
+
 
/code
+
#修改 指定的字体 或者直接把你的家体改成和默认同名,而默认的那个先删除 连重启都不用 反正在docker
/code # ls
+
  grep  -rn  BX_GRAPH_FONT_NAM   /usr/share/zabbix/include/defines.inc.php
Dockerfile          app.py              app.py~              docker-compose.yml   docker-compose.yml~  requirements.txt
+
67:define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name
  
#母机
+
修改
evan@latop:~/test/composetest$ ls
+
define('ZBX_GRAPH_FONT_NAME',          'simkai'); 
app.py  app.pydocker-compose.yml  docker-compose.yml~  Dockerfile  requirements.txt
+
</pre>
 +
===zabbix-get===
 +
<pre>
 +
root@zabbix-server ~]#zabbix_get -s 10.3.10.139 -k "system.hostname"
 +
dev-hello-market
  
  
 +
不过使用zabbix_get时必须开启客户端被动模式,要求暴露客户端监听端口。
 
</pre>
 
</pre>
 +
[https://blog.csdn.net/cx55887/article/details/83818696 自动化监控--zabbix-get安装使用详解]
  
==Step 6: Re-build and run the app with Compose==
+
==第二 agent==
From your project directory, type docker-compose up to build the app with the updated Compose file, and run it.
+
<pre>
==Step 7: Update the application==
+
#4.0 #centos7 快速安装和自动配置 2019年 8月23日 星期五 11时45分01秒 CST
Because the application code is now mounted into the container using a volume, you can make changes to its code and see the changes instantly, without having to rebuild the image. 可见 有mount 后 只改变母机的不用rebuild 了
 
  
Change the greeting in app.py and save it. For example, change the Hello World! message to Hello from Docker!:
+
#国外
 +
rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
  
return 'Hello from Docker! I have been seen {} times.\n'.format(count)
+
#国内
 +
https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
  
Refresh the app in your browser. The greeting should be updated, and the counter should still be incrementing.
+
yum install zabbix-agent -y
  
=常用参数=
+
yum install ntp  -y
==links/external_links参数==
+
timedatectl set-ntp true
<pre>
 
-link  同一个物理机之前 
 
  
 +
HOSTNAME=prod-java-02
  
external_links
+
#config
Docker平台的组合功能提供了一个叫“外部链接”(“external_links”)的设置选项,能用来接连那些在不同组合文件中定义的容器:
+
sed -i "s/^Server=127.0.0.1/Server=172.16.1.9/ " /etc/zabbix/zabbix_agentd.conf
  
eg
+
sed -i "s/^ServerActive=127.0.0.1/ServerActive=172.16.1.9/" /etc/zabbix/zabbix_agentd.conf
    hostname: rabbitmq02
+
sed  -i "s/^Hostname=Zabbix server/Hostname=test-market/"  /etc/zabbix/zabbix_agentd.conf
    extra_hosts:
 
      - "rabbitmq01:10.3.10.141" #前面是hostname 后面是ip
 
  
  
</pre>
 
  
[https://blog.csdn.net/kongxx/article/details/38676917 Docker使用Link在容器之间建立连接]
+
#这个用了HOSTNAME 变量  而上面的要指定hostname
 +
sed  -i 's/127.0.0.1/23.67.81.95/g'  /etc/zabbix/zabbix_agentd.conf
 +
sed  -i "s/Hostname=Zabbix server/Hostname=${HOSTNAME}/g"  /etc/zabbix/zabbix_agentd.conf
 +
grep "^\s*[^# \t].*$" /etc/zabbix/zabbix_agentd.conf
  
[https://sdk.cn/news/7643 Docker的组合功能:如何用external_links选项连接组合文件外部定义的容器]
+
systemctl  enable  zabbix-agent.service
 +
systemctl restart zabbix-agent
  
[https://www.cnblogs.com/liyuanhong/articles/5851251.html 如何使不同主机上的docker容器互相通信]
 
  
[https://www.jianshu.com/p/aa984711df80 docker compose 中难缠的网络问题]
+
下面是老的信息 和解说
  
=trouble=
+
cat /etc/zabbix/zabbix_agentd.conf
==Question ==
+
Hostname=主机名
<pre>
+
Server=zabbix server ip
docker-compose up
+
LogFile= 可以不改
  
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
+
##最好这样3个
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable. </pre>
+
Server=10.6.1.181
 +
ServerActive=10.6.1.181
 +
Hostname=zabbix-client-1
  
  
== solve==
+
#rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
<pre>
+
#rpm -ivh http://repo.zabbix.com/zabbix/2.2/rhel/6/x86_64/zabbix-release-2.2-1.el6.noarch.rpm
Use the command  sudo systemctl edit docker.service  to open an override file for docker.service in a text editor.
+
#http://repo.zabbix.com/zabbix/2.0/rhel/5/x86_64/zabbix-release-2.0-1.el5.noarch.rpm
  
Add or modify the following lines, substituting your own values.
 
  
[Service]
+
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
ExecStart=
 
ExecStart=/usr/bin/dockerd -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock
 
Save the file.
 
  
Reload the systemctl configuration.
+
</pre>
 +
===agent on debian===
 +
<pre>
 +
#用系统的源
 +
apt-get install zabbix-agent
  
$ sudo systemctl daemon-reload
 
Restart Docker:
 
  
$ sudo systemctl restart docker.service
+
#config 其实和yum的也一样 只是启动不一样而已
Check to see whether the change was honored by reviewing the output of netstat to confirm dockerd is listening on the configured port.
+
HOSTNAME=wiki
 +
sed -i "s/^Server=127.0.0.1/Server=207.148.106.229/ " /etc/zabbix/zabbix_agentd.conf
  
$ sudo netstat -lntp | grep dockerd
+
sed -i "s/^ServerActive=127.0.0.1/ServerActive=207.148.106.229/"  /etc/zabbix/zabbix_agentd.conf
tcp        0      0 127.0.0.1:2375          0.0.0.0:*              LISTEN      3758/dockerd
+
sed  -i "s/^Hostname=Zabbix server/Hostname=wiki/"  /etc/zabbix/zabbix_agentd.conf
  
vim ~/.bashrc
+
grep "^\s*[^# \t].*$" /etc/zabbix/zabbix_agentd.conf
export DOCKER_HOST=tcp://localhost:2375
 
  
</pre>
+
service zabbix-agent start
  
https://stackoverflow.com/questions/27763340/docker-opts-do-not-work-in-config-file-etc-default-docker
 
  
https://stackoverflow.com/questions/44678725/cannot-connect-to-the-docker-daemon-at-unix-var-run-docker-sock-is-the-docker
+
zabbix_get -s 138.68.59.0 -k "system.hostname"
  
其它办法 没过过 正确的是将当前用户加入docker组
 
jing@ubuntu:/tmp/docker$ sudo gpasswd -a ${USER} docker
 
  
=see also=
+
#用zbx的源
官方文档永远是最帅的
+
  https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-3+buster_all.deb       
 +
dpkg -i zabbix-release_stretch_all.deb
 +
# apt-get update
 +
</pre>
 +
https://www.zabbix.com/documentation/3.2/manual/installation/install_from_packages/repository_installation
  
https://docs.docker.com/compose/install/#install-compose
+
https://www.zabbix.com/documentation/4.0/zh/manual/installation/install_from_packages/rhel_centos#%E5%AE%89%E8%A3%85_agent
  
[https://www.jianshu.com/p/658911a8cff3 Docker:Docker Compose 详解]
+
==docker zabbix==
  
[https://www.cnblogs.com/moxiaoan/p/9299404.html Docker-compose常用命令]
+
[https://juejin.im/entry/57be598d0a2b58006cd17c0f 用 Zabbix 和 Docker 搭建监控平台]
  
[https://blog.csdn.net/wanghailong041/article/details/52162293 Docker-compose命令详解]
+
== 故障及回顾==
 +
<pre>
 +
问题1. zabbix server 没有打开 10051端口 前端图形没显示
  
https://docs.docker.com/compose/gettingstarted/
+
版本zabbix 2.2
  
https://blog.csdn.net/zhugeaming2018/article/details/81518327
 
  
[https://www.cnblogs.com/regit/p/8309959.html docker-compose常用命令]
 
  
[https://www.jianshu.com/p/658911a8cff3 Docker:Docker Compose 详解]
+
没有看到 10051 是因为 
  
 +
DBPassword=‘123’ 改为 DBPassword=123
  
[https://beginor.github.io/2017/06/08/use-compose-instead-of-run.html 使用 docker-compose 替代 docker run]
 
  
[https://www.cnblogs.com/ee900222/p/docker_5.html Docker系列之(五):使用Docker Compose编排容器]
+
日志查看
 +
tail  /tmp/zabbix_server.log
  
 +
14659:20170525:171042.257 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES)
  
[https://blog.csdn.net/u011781521/article/details/80464826 Docker(四)----Docker-Compose 详解]
 
  
[https://blog.csdn.net/u014799292/article/details/79094015 安装docker-compose并统一拉取镜像]
+
正确如下
 +
[root@ zabbix]# netstat  -nlpt
 +
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:10051
 +
</pre>
  
[https://blog.csdn.net/zhugeaming2018/article/details/81518327 『中级篇』Docker Compose的安装和基本使用(39)]
+
==参考==
  
[https://blog.csdn.net/smartdt/article/details/78431618 Docker学习(6)Docker Compose介绍和编配]
+
[https://www.howtoforge.com/tutorial/install-zabbix-monitoring-server-and-agent-on-debian-9/ Install Zabbix Monitoring Server and Agent on Debian]
  
[https://blog.csdn.net/hujyhfwfh2/article/details/83934415 Docker-Docker Compose]
 
  
[https://blog.csdn.net/yuzhongzi81/article/details/79295672 小白学Docker之Compose]
+
[http://blog.51cto.com/guoxh/2089204 Zabbix 3.0 详解:从添加主机到发送报警通知]
  
[https://blog.csdn.net/pushiqiang/article/details/78682323 docker-compose教程安装,使用, 快速入门]
+
[https://my.oschina.net/zhouyuntai/blog/1788830 Zabbix监控系统 (3) 之 添加自定义监控项目、配置邮件告警、测试告警]
  
 +
http://blog.linuxchina.net/?p=1711
  
[http://www.cnblogs.com/sammyliu/p/5932996.html 理解Docker(8):Docker 存储之卷(Volume)]
+
[https://www.cnblogs.com/enjoycode/p/zabbix_3_installation_on_centos_7.html Zabbix 3.0  with apache安装笔记]
  
[http://dockone.io/article/128 深入理解Docker Volume(一)]
+
[https://www.cnblogs.com/zhenglisai/p/6547402.html 【zabbix】自定义监控项key值]
  
[http://www.cnblogs.com/zhengran/p/4212519.html 深入理解Docker Volume(一)]
 
  
[[Docker-compose搭建nginx+php+mysql]]
+
[https://blog.csdn.net/zhengchaooo/article/details/79499991 zabbix添加自定义py脚本]
  
[[category:容器]][[category: container]] [[category: compose]]
+
 [[category:zabbix]]

2019年12月26日 (四) 08:32的版本

站内资源

Zabbix 调用API 批量添加主机

zabbix server

pre

这些是官网官方安装文档,记得一定要看

https://www.zabbix.com/documentation/3.0/manual/installation/install

https://www.zabbix.org/wiki/InstallOnCentOS_RHEL

wget -c https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.8/zabbix-3.0.8.tar.gz
wget -c http://tenet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.13/zabbix-2.2.13.tar.gz

#配置php变量

vi /etc/php.ini
date.timezone = Asia/Shanghai
post_max_size = 32M
max_execution_time = 300
max_input_time = 300
注:更改完之后需要重启nginx和php

#安装zabbix所需的组件

yum -y install net-snmp-devel curl-devel
#yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI php-gd php-xml php-bcmath
groupadd zabbix && useradd -g zabbix zabbix
tar xvf zabbix-3.0.8.tar.gz && cd zabbix-3.0.8
#tar xvf zabbix-2.2.13.tar.gz && cd zabbix-2.2.13

#./configure –enable-server –enable-agent –with-mysql –enable-ipv6 –with-net-snmp –with-libcurl –with-libxml2

##或者默认安装路径 make是不用的
./configure --sysconfdir=/etc/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2 && make install

添加zabbix服务对应的端口(可以省略,但是官方建议有)

cat >>/etc/services<< EOF
zabbix-agent 10050/tcp #Zabbix Agent
zabbix-agent 10050/udp #Zabbix Agent
zabbix-trapper 10051/tcp #Zabbix Trapper
zabbix-trapper 10051/udp #Zabbix Trapper
EOF

配置文件

##好像是这个起效果的呢 –sysconfdir=/etc/zabbix 有这个,不用下面的命令了
#vim /usr/local/etc/zabbix_server.conf
#cd zabbix-2.0.7

#mkdir /etc/zabbix
#cp conf/*.conf /etc/zabbix

mkdir /var/log/zabbix ;chown zabbix:zabbix /var/log/zabbix;


#zabbix web代码
mkdir -p /data/www/zabbix;
cp -r frontends/php/* /data/www/zabbix

修改zabbix连接的数据库的用户名和密码
vi /etc/zabbix/zabbix_server.conf

DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword='123'
DBPort=3306 #如果数据库是用sock文件的方式,这里可以是sock文件的路径

添加数据库Lib文件位置到/etc/ld.so.conf中,并使其生效
echo ‘/usr/local/mysql/lib/mysql/’ >> /etc/ld.so.conf

ldconfig

为zabbix的启动、关闭和重启的脚本文件做链接,方便系统可以找得到

给zabbix服务端程序做软链接 我用默认的config 应该是不用的
cd /usr/local/zabbix/bin/
for i in *;do ln -s /usr/local/zabbix/bin/${i} /usr/bin/${i};done
cd /usr/local/zabbix/sbin/
for i in *;do ln -s /usr/local/zabbix/sbin/${i} /usr/sbin/${i};done

拷贝zabbix服务端和客户端启动脚本到/etc/init.d目录下.
cd misc/init.d/
cp fedora/core/zabbix_server /etc/init.d/
cp fedora/core/zabbix_agentd /etc/init.d/
chmod +x /etc/init.d/zabbix_agentd
chmod +x /etc/init.d/zabbix_server

3 Create Zabbix database

SQL scripts are provided for creating database schema and inserting the dataset
#https://www.zabbix.com/documentation/3.0/manual/appendix/install/db_scripts
#https://www.zabbix.com/documentation/2.2/manual/appendix/install/db_scripts

mysql>create database zabbix character set utf8 collate utf8_bin;;grant all on zabbix.* to zabbix@localhost identified by '123';flush privileges;

将zabbix源码包中的数据导入到新建的zabbix数据库
##这个和老的版本有点不同 第一个是zabbix的数据库表结构,要先导入。

. /etc/profile
cd ../..
mysql -uroot -p'evan' zabbix< database/mysql/schema.sql
mysql -uroot -p'evan' zabbix< database/mysql/images.sql
mysql -uroot -p'evan' zabbix< database/mysql/data.sql

vi /etc/init.d/zabbix_server # 的可以不改,修改一下变量的值 因为我是默认用 configure
# base zabbix dir
BASEDIR=/usr/local
# binary file
ZABBIX_SUCKERD=$BASEDIR/sbin/zabbix_server<pre>

===fping的安装和使用详解===
<pre>http://rickie622.blog.163.com/blog/static/2123881120121121111720941/
http://netsecurity.51cto.com/art/201101/242200.htm
#当然 下载zip包也是可以的
git clone https://github.com/schweikert/fping.git
cd fping
./autogen.sh
./configure
make -j2 && make install

#修改一下配置文件
vim /etc/zabbix_server.conf
#vim /usr/local/etc/zabbix_server.conf
FpingLocation=/usr/local/sbin/fping

启动zabbix,并且添加开机自启动

service zabbix_server start
service zabbix_agentd start #启动服务

chkconfig zabbix_server on
chkconfig zabbix_agentd on #开机自启动

在Nginx服务中添加zabbix虚拟主机
#vim /usr/local/nginx/conf/vhosts/monitor.conf

这些都不要,不然没有web安装向导的
#cd zabbix/conf
#cp zabbix.conf.php.example zabbix.conf.php ;
#chmod 777 zabbix.conf.php

iptables -I INPUT -p tcp –dport 80 -j ACCEPT

zabbix server is not running
Zabbix Server is not running: the information displayed may not be current
http://song49.blog.51cto.com/4480450/1200151

(4)设置zabbix服务IP和端口,name可以忽略

ps:
post_max_size = 16M
PHP option “max_execution_time” 30 300 Fail
PHP option “max_input_time” 60 300 Fail
PHP option “date.timezone” unknown Fai
date.timezone = Asia/Shanghai

PHP option “always_populate_raw_post_data” must be set to “-1”

port 10051

Zabbix frontend is ready! The default user name is Admin, password zabbix.

超级用户密码修改

2.2 用户名第一个字母要大写 也就是Admin
默认的用户名:admin 密码:zabbix

哪里改登录用户和密码呢
use zabbix;
select userid,alias,passwd from users; #查看

+--------+------------+----------------------------------+
| userid | alias      | passwd                           |
+--------+------------+----------------------------------+
|      1 | Admin      | 5fce1b3e34b520afeffb37ce08c7cd66 |


#如果为zabbix 3.0  直接这样就行了 
update users set passwd=MD5('12345') where userid=1;


#zabbix 2.x 
重新开个终端,生成一个MD5加密的密码,这里密码设置的是redhat

[root@localhost ~]# echo -n 12345678 |openssl md5 #-n就表示不输入回车符,不加-n,否则就不是这个结果了。
(stdin)= 25d55ad283aa400af464c76d713c07ad

接着上面的为admin用户设定一个密码

mysql> update users set passwd='25d55ad283aa400af464c76d713c07ad' where userid = '1';
#或者直接使用update users set passwd=md5(“12345678”) where userid=’1′;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

zabbix登陆账户admin密码修改
http://pvbutler.blog.51cto.com/7662323/1734003

yum install ntp ntpdate -y
chkconfig ntpd on
/etc/init.d/ntpd start

*/30 * * * * /usr/sbin/ntpdate pool.ntp.org

在29行这后添加
sed -i ’29a user=mysql’ /etc/my.cnf
sed -i ’29a character-set-server=utf8′ /etc/my.cnf
sed -i ’29ainnodb_file_per_table=1′ /etc/my.cnf
重启mysqld

防火墙设置

这个要看一下先,尽量用严格些的防火墙设置

#on zabbix-agent

iptables -A INPUT -s zabbixserverip  -p tcp -m tcp --dport 10050 -m comment --comment "zabbix_server listen " -j ACCEPT 
#iptables -A INPUT -s zabbixserverip  -p tcp -m tcp --dport 10050 -m comment --comment "zabbix_agentd listen " -j ACCEPT 

#这下面的防火墙rule 不要用 
vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 10050 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 10051 -j ACCEPT

/etc/init.d/iptables restart

中文在右上角的用户里面哦

Starting php_fpm /usr/local/php/bin/php-cgi: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
failed

by default install the daemon binaries (zabbix_server, zabbix_agentd, zabbix_proxy) in /usr/local/sbin and the client binaries (zabbix_get, zabbix_sender) in /usr/local/bin.

4.0图像显示字体乱码的解决方法


#传输字体
 cp  /root/STKAITI.TTF  /usr/share/zabbix/assets/fonts
  
 #修改 指定的字体 或者直接把你的家体改成和默认同名,而默认的那个先删除 连重启都不用 反正在docker
  grep  -rn  BX_GRAPH_FONT_NAM   /usr/share/zabbix/include/defines.inc.php
67:define('ZBX_GRAPH_FONT_NAME',		'DejaVuSans'); // font file name

修改
define('ZBX_GRAPH_FONT_NAME',           'simkai');  

zabbix-get

root@zabbix-server ~]#zabbix_get  -s 10.3.10.139 -k "system.hostname"
dev-hello-market


不过使用zabbix_get时必须开启客户端被动模式,要求暴露客户端监听端口。

自动化监控--zabbix-get安装使用详解

第二 agent

#4.0 #centos7 快速安装和自动配置 2019年 8月23日 星期五 11时45分01秒 CST

#国外
rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

#国内
https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

yum install zabbix-agent -y

yum install ntp  -y
timedatectl set-ntp true

HOSTNAME=prod-java-02

#config
sed -i "s/^Server=127.0.0.1/Server=172.16.1.9/ " /etc/zabbix/zabbix_agentd.conf

sed -i "s/^ServerActive=127.0.0.1/ServerActive=172.16.1.9/"  /etc/zabbix/zabbix_agentd.conf
sed  -i "s/^Hostname=Zabbix server/Hostname=test-market/"  /etc/zabbix/zabbix_agentd.conf



#这个用了HOSTNAME 变量  而上面的要指定hostname
sed  -i 's/127.0.0.1/23.67.81.95/g'  /etc/zabbix/zabbix_agentd.conf
sed  -i "s/Hostname=Zabbix server/Hostname=${HOSTNAME}/g"  /etc/zabbix/zabbix_agentd.conf
grep "^\s*[^# \t].*$" /etc/zabbix/zabbix_agentd.conf

systemctl  enable  zabbix-agent.service
systemctl restart zabbix-agent


下面是老的信息 和解说

cat /etc/zabbix/zabbix_agentd.conf
Hostname=主机名
Server=zabbix server ip
LogFile= 可以不改

##最好这样3个
Server=10.6.1.181
ServerActive=10.6.1.181
Hostname=zabbix-client-1


#rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
#rpm -ivh http://repo.zabbix.com/zabbix/2.2/rhel/6/x86_64/zabbix-release-2.2-1.el6.noarch.rpm
#http://repo.zabbix.com/zabbix/2.0/rhel/5/x86_64/zabbix-release-2.0-1.el5.noarch.rpm


rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

 

agent on debian

#用系统的源 
 apt-get install zabbix-agent


#config 其实和yum的也一样 只是启动不一样而已
HOSTNAME=wiki
sed -i "s/^Server=127.0.0.1/Server=207.148.106.229/ " /etc/zabbix/zabbix_agentd.conf

sed -i "s/^ServerActive=127.0.0.1/ServerActive=207.148.106.229/"  /etc/zabbix/zabbix_agentd.conf
sed  -i "s/^Hostname=Zabbix server/Hostname=wiki/"  /etc/zabbix/zabbix_agentd.conf

grep "^\s*[^# \t].*$" /etc/zabbix/zabbix_agentd.conf

service zabbix-agent start


 zabbix_get -s 138.68.59.0 -k "system.hostname"


#用zbx的源
  https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-3+buster_all.deb        
dpkg -i zabbix-release_stretch_all.deb
# apt-get update

https://www.zabbix.com/documentation/3.2/manual/installation/install_from_packages/repository_installation

https://www.zabbix.com/documentation/4.0/zh/manual/installation/install_from_packages/rhel_centos#%E5%AE%89%E8%A3%85_agent

docker zabbix

用 Zabbix 和 Docker 搭建监控平台

故障及回顾

问题1.  zabbix server 没有打开 10051端口 前端图形没显示 

版本zabbix 2.2 



没有看到 10051 是因为  

DBPassword=‘123’ 改为 DBPassword=123


日志查看 
 tail  /tmp/zabbix_server.log

14659:20170525:171042.257 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES)


正确如下 
[root@ zabbix]# netstat  -nlpt 
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:10051

参考

Install Zabbix Monitoring Server and Agent on Debian


Zabbix 3.0 详解:从添加主机到发送报警通知

Zabbix监控系统 (3) 之 添加自定义监控项目、配置邮件告警、测试告警

http://blog.linuxchina.net/?p=1711

Zabbix 3.0 with apache安装笔记

【zabbix】自定义监控项key值


zabbix添加自定义py脚本