Since the environment is Intranet, this paper only uses several basic dependency packages of system 1. However, various problems may occur in the process of installation and deployment, and the deployment time is long. 2 docker image method is not recommended. The image is prepared before installation and deployment. In field deployment, as long as the source docker package is installed and the image is imported, zabbix can be set up

1 the environment

Nginx +jdk1.8+php7.3+zabbix5.0+mysql8.0== #==nginx+jdk1.8+php7.3+zabbix5.0 +mysql8.0== #==nginx+jdk1.8+php7.3+zabbix5.0 +mysql8.0== #==nginx+jdk1.8+php7.3+zabbix5.0 So use this method == #==mysql8.0 directly use the official website provided mysql Docker image ==, the reason is that they may not find a good way, source installation and yum image are more than 2G, the official website provided more than 500 M

[root@demo110 ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

Copy the code

2 Package the Docker installation of the image environment

2.1 yum install

# Install yum directly on the Internet, and set up the service boot, see 2.2 second half, recommended

yum install docker
Copy the code

2.2 Source Package Installation

No good installation package in the external network environment, then decompress the installation, Intranet environment deployment can be used

The tar XZVF docker - 18.09.9. Tar. Gz# Docker download your own version
sudo cp docker/* /usr/bin/
sudo dockerd &
Copy the code

# # config service startup create service startup, save out # vim/usr/lib/systemd/system/docker. Service

[Service] 

ExecStart= 

ExecStart=/usr/bin/dockerd --graph=/var/lib/docker
Copy the code

# Reload the service and set boot on boot

systemctl daemon-reload
systemctl enable docker
systemctl start docker
Copy the code

3 Docker image packaging

3.1 Dockerfile write

#nginx: source code installation #jdk1.8: source code installation #zabbix5.0: source code installation #php73: yum installation

[root@demo110 dockerimages]# ll
total 2289976
-rw-r--r--  1 root   root         2523 Jun 11 00:24 CentOS-Base.repo
-rw-r--r--  1 root   root         3331 Jun 11 19:06 Dockerfile
drwxr-xr-x  7     10    143       4096 Dec 16  2018 jdk1.8.0_201
-rw-r--r--  1 root   root    191817140 Jun  6 00:03 jdk-8u201-linux-x64.tar.gz Unpack ahead of time
-rw-r--r--  1 root   root         1432 Jun  9 10:24 my.cnf
drwxr-xr-x  8   1001   1001       4096 Aug 13  2019 nginx-1.16.1
-rw-r--r--  1 root   root      1032630 Jun  6 00:18 nginx-1.16.1.tar.gzUnzip the JDK in advance-rw-r--r-- 1 root root 63561 Jun 9 09:40 php.ini drwxr-xr-x 13 centos 4096 May 11 17:19 zabbix-5.0.0-rw-r --r-- 1 Root root 18519888 Jun 11 01:13 zabbix-5.0.0.tar.gzUnzip the JDK in advance
Copy the code

#Dockerfile:

# setup ENV
FROM centos:7  Set the base system
MAINTAINER kkcai # the author
ENV TZ=Asia/Shanghai Set the environment time zone

# mkdir DIR create later to map folder, mainly according to their own project needs to set
RUN mkdir -p /data/logs/ Put all logs in one folder. It is recommended to do this to facilitate later troubleshooting, but each application's log should be set in advance to the log directory, which is not indicated in this article
RUN mkdir -p /home/app/zabbixui

# Install jdk1.8.0 _201
ADD jdk1.8.0_201 /opt/jdk8
ENV JAVA_HOME /opt/jdk8
ENV PATH $JAVA_HOME/bin:$PATH

# Install necessary tools
COPY CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo # update the yum package used by the system
RUN yum install -y less vim lrzsz bash-completion yum unzip zip pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel

The Setup program is hidden here

# Install Nginx The ADD nginx - 1.16.1 / nginx - 1.16.1 RUNcd/nginx-1.16.1/ &&./configure --prefix=/opt/nginx && make && make install# Install php73
RUN yum install -y https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpm
RUN yum install yum-utils -y
RUN yum install -y cmake make gcc gcc-c++ libaio ncurses ncurses-devel -y
RUN yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-recode php73-php-snmp php73-php-soap php73-php-xml
COPY php.ini /etc/opt/remi/php73/php.ini # Zabbix requires a PHP environment, so you can set it up ahead of time

# Install zabbix5.0RUN yum install -y mysql-devel fping net-snmp net-snmp-devel curl curl-devel libxml2 libxml2-devel libevent-devel.x86_64  libcurl-devel RUN mkdir -p /usr/local/zabbix # Create directory used by Zabbix
RUN groupadd zabbix # Create a group for the Zabbix user
RUN useradd -g zabbix zabbix -s /sbin/nologin
ADD zabbix-5.0.0 /zabbix-5.0.0
RUN cd/ zabbix - 5.0.0 &&. / configure -- prefix = / usr /local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 && make install
COPY zabbix_server /etc/init.d/zabbix_server Set the zabbix_server boot option
COPY zabbix_agentd /etc/init.d/zabbix_agentd Set the zabbix_agent boot optionThe ADD/zabbix - 5.0.0 / UI / / home/app/zabbixui /# Zabbix The directory used by the Web project
RUN chmod 777 /etc/init.d/zabbix_*

# Clean ALL
# RUN rm - rf/zabbix - 5.0.0
RUN rm -rf /nginx-1.16.1
RUN yum clean all

# Service Manager
#systemctl daemon-reload
#systemctl enable zhongyuan.service nginx.service php73-php-fpm.service zabbix_server.service zabbix_agentd.service
#systemctl restart zhongyuan.service nginx.service php73-php-fpm.service zabbix_server.service zabbix_agentd.service
Copy the code

# attached: PHP ini content, modify the following these items # vim/etc/opt/remi php73 / PHP. Ini

vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
Copy the code

3.2 Docker image packaging

Execute dockerfile and package the image

Docker build -t php73jdk8nginx116zabbix5:1.0.Copy the code

# After packing, view the image

[root@demo110 dockerimages]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
php73jdk8nginx116zabbix5        1.0                 f763073d4a2d        3 days ago          1.96GB
mysql                           8.0                 30f937e841c8        3 weeks ago         541MB
Copy the code

4 Onsite Intranet deployment

4.1 Preparations

# Export the image and mysql image

Docker save php73jdk8nginx116zabbix5:1.0 >. / zabbix5.0. Tar docker save mysql: 8.0 >. / mysql. The tar#mysql8.0, pull from the official website
Copy the code

The project required files to the U disk, such as: == Docker source package, JAR package, front-end package ==

4.2 == Install Docker, see 2.2==, import files in USB drive

4.3 Importing an Image

Docker load -i zabbix5.0.tar Docker load -i mysql.tarCopy the code
4.3.1 Starting mysQL8.0 image and configuring related configurations
docker run --name mysql8 -t \
-e MYSQL_DATABASE="zabbix" \ Create zabbix database
-e MYSQL_USER="zabbix" \ Create user zabbix
-e MYSQL_PASSWORD="zabbix" \ Set zabbix user password
-e MYSQL_ROOT_PASSWORD="devops" \ Mysql > set password to root
-e TZ="Asia/Shanghai" \ # Specifies the mirror time zone
-v /data/mysql/data/mysql:/var/lib/mysql \ # Store mysql data locally
-v /data/mysql/my.cnf:/etc/mysql/my.cnf \ # Map the pre-written my.cnf into the system
-v /data/logs/:/data/logs/ \ # Map logs to local
--net=host \ Use host mode, i.e. use host network adapter directly
-d mysql:8.0 \
--character-set-server=utf8 --collation-server=utf8_bin \ Set database initialization parameters
--default-authentication-plugin=mysql_native_password \ You can log in using native
--lower_case_table_names=1 # Set case insensitive
Copy the code

Mysql > check whether the mysql server is running properly

[root@demo110 ~]# ps -ef |grep mysqldpolkitd 13442 13427 2 Jun11 pts/0 02:10:43 mysqld --character-set-server=utf8 --collation-server=utf8_bin --default-authentication-plugin=mysql_native_password --lower_case_table_names=1 root 25499 15455 0 19:26 pts/0 00:00:00  grep --color=auto mysqld [root@demo110 ~]# netstat -lantp |grep mysql
tcp6       0      0 :::33060                :::*                    LISTEN      13442/mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      13442/mysqld
Copy the code

Mysql > select zabbix from zabbix

docker exec -ti mysql8 /bin/bash
root@demo110:/# mysql -h 127.0.0.1 -uroot -p
Enter password: devops# Password just setWelcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 80113 Server version: 8.0.20 MySQL Community Server -gPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type'help; ' or '\h' for help. Type '\c' to clear the current input statement.

mysql> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (1.93 sec)
Copy the code
4.3.2 Starting the Image and Configuring related Settings
docker run -it \
-v /data/logs/:/data/logs/ \ # Map logs to local
--net=host \ Use host mode, i.e. use host network adapter directly
--privileged=true \ Use privileged mode- the name myprogram php73jdk8nginx116zabbix5:1.0 / usr/sbin/initCopy the code

# Check whether it has been started normally

[root@demo110 ~]# docker ps -aThe CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 970 e51620fb7 php73jdk8nginx116zabbix5:1.0"/usr/sbin/init"         3 days ago          Up 43 hours               myprogram
ccf3c745d8f8        mysql:8.0                      "Docker - entrypoint. S..."   3 days ago          Up 3 days                                     mysql8
Copy the code

Enter the project image to continue setting

[root@demo110 ~]# docker exec -ti myprogram /bin/bash
[root@demo110 /]#
Copy the code

Select * from zabbix where zabbix = zabbix

Mysql - uzabbix - p zabbix < / zabbix - 5.0.0 / database/mysql/schema. SQL mysql - uzabbix - p zabbix < / zabbix - 5.0.0 / database/mysql/images. SQL mysql - uzabbix - p zabbix < / zabbix - 5.0.0 / database/mysql/data. SQLCopy the code

# # modified nginx configuration vim/opt/nginx/conf/nginx. Conf

        server {
        listen 8080;
        server_name localhost;
        error_log   /data/logs/nginx_zabbix_error.log; # Specifies zabbixWeb log output
        access_log  /data/logs/nginx_zabbix_access.log;
        root /home/app/zabbixui; Specifies the zabbixWeb directory
        index index.php index.html index.htm default.php default.htm default.html;
        location / {
                try_files $uri $uri/ /index.html; } location ~ .*\.(php)? $ { expires -1s; try_files$uri= 404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param PATH_INFO$fastcgi_path_info;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; Fastcgi_pass 127.0.0.1:9000; }}Copy the code

# # production of nginx start vim/usr/lib/systemd/system/nginx. Service

[Unit] Description=nginx - high performance web server After=network.target remote-fs.target nss-lookup.target [Service]  Type=forking#PIDFile=/opt/nginx/sbin/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf
ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
ExecReload=/opt/nginx/sbin/nginx -s reload
ExecStop=/opt/nginx/sbin/nginx -s stop
#ExecQuit=/opt/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Copy the code

4.3 Setting startup items related to services

systemctl daemon-reload
systemctl enable zhongyuan.service nginx.service php73-php-fpm.service zabbix_server.service zabbix_agentd.service
systemctl restart zhongyuan.service nginx.service php73-php-fpm.service zabbix_server.service zabbix_agentd.service
Copy the code

# At this point all applications are deployed

5 verify

# Browser access:http://172.16.1.138:8080/setup.php

Default user name: Admin password: zabbix

X. Problems encountered in the process (no matter the problems encountered successively)

Eg1. LC_CTYPE: cannot change locale (en_us.utf-8): No such file or directory Solution: character problem vim /etc/sysconfig/i18n# Add the following
LC_ALL=C
export LC_ALL
# Then execute the following statement to make it effective
source /etc/sysconfig/i18n

eg2.hecking for mysql_config... configure: error: MySQL library not found # Mysql source code installationSolution: yum install mysql-devel install eg3. Mysql error Errcode: 13"Permission denied"Cause: Directory permission [root@220fe8ed9040 lib]# llDrwxr-xr-x 7 root root 4096 Jun 9 02:53 mysql solution: The world-writable config file '/etc/my.cnf' is ignored because the my.cnf permission is incorrect. CNF -rwxrwxrwx 1 root root 1404 Oct 16 19:31 /etc/my.cnf  chmod 644 /etc/my.cnf systemctl start mysql eg5.configure: error: Not found Net SNMP Library solution: Yum install net-snmp-devel Eg6.[ERROR] [my-010095] [Server] Failed to access directoryfor--secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files Solution: Docker load -i No space left on device Secure_file_priv =/var/lib/mysql eg7.docker load -I No space left on device When the image is decompressed, the disk where the image is stored is full. You can use the following command: df -i to check whether the disk is full#vi /etc/systemd/system/docker.service.d/docker.conf 
```bash
[Service] 

ExecStart= 

ExecStart=/usr/bin/dockerd --graph=/var/lib/docker Change the graph position to the data disk, and then save to exit the Docker service

eg8. root@demo110:/# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'(2) add -h 127.0.0.1 root@demo110:/# mysql -h 127.0.0.1 -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 80113 Server version: 8.0.20 MySQL Community Server -gPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>Copy the code