1. 程式人生 > >zabbix4.2安裝以及4.0升級4.2

zabbix4.2安裝以及4.0升級4.2

1.5 devel shadow libev 重啟nginx install ges libxml2 adb

一、添加Zabbix存儲庫

1.安裝存儲庫配置包。

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

2.在將運行Zabbix前端的系統中啟用可選rpms的存儲庫

yum-config-manager --enable rhel-7-server-optional-rpms

3.安裝支持MySQL的Zabbix服務

yum install zabbix-server-mysql

4.安裝支持MySQL的Zabbix前端

yum install zabbix-web-mysql

二、安裝MySQL5.7數據庫

1.卸載mariadb包

rpm -qa |grep mariadb    #查看當前安裝的mariadb的包
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64     #卸載mariadb的包

2.下載並解壓MySQL源碼包

wget https://dev.mysql.com/get/archives/mysql-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz  #從官網下載源碼包
tar -xzvf  mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz     #解壓源碼包
mv  mysql-5.7.21-linux-glibc2.12-x86_64  /usr/local/mysql

3.創建MySQL用戶並對MySQL文件進行授權

groupadd mysql                   --創建mysql用戶組組
useradd -r -g mysql mysql     --創建mysql用戶並添加到mysql用戶組中
chown -R mysql.mysql mysql/         --將mysql目錄訪問權限賦為myql用戶

4.創建MySQL配置文件

cat >>/etc/my.cnf  <<EOF     #寫入配置文件
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character_set_server=utf8
init_connect=‘SET NAMES utf8‘
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#不區分大小寫
lower_case_table_names = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = ‘+8:00‘
EOF

5.初始化數據庫

touch /var/log/mysqld.log    #創建日誌文件並授權
chmod 777 /var/log/mysqld.log
chown mysql.mysql mysqld.log
/usr/local/mysql/bin/mysqld   --initialize --user=mysql   --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

6.查看初始化密碼

cat /var/log/mysqld.log|grep [email protected]

7.執行如下操作開啟MySQL服務,並設置相應權限

mkdir /var/run/mysqld
touch /var/run/mysqld/mysqld.pid
chmod -R 777 /var/run/mysqld
chown -R mysql.mysql /var/run/mysqld
/usr/local/mysql/support-files/mysql.server start  #啟動MySQL

8.修改MySQL密碼

vim /etc/my.cnf   #修改配置文件
skip-grant-tables    #跳過密碼認證
default_password_lifetime=360    #修改密碼超時時間
不然修改密碼之後密碼會過期,會提示讓你重新設置密碼
You must reset your password using ALTER USER statement before executing this statement.
/usr/local/mysql/bin/mysql -uroot -p        #登錄MySQL
use mysql    #切換MySql數據庫
update mysql.user set authentication_string =password(‘root‘), host = ‘%‘ where user = ‘root‘;   #修改MySQL密碼
flush privileges;

9.將MySQL加入環境變量

echo ‘PATH=/usr/local/mysql/bin:$PATH‘ >>/etc/profile      #將MySQL二進制文件加入環境變量
ln -s usr/local/mysql/support-files/mysql.server /usr/local/mysql/bin/    將MySQL的啟動文件軟連接到MySQL的環境變量中

10.進入數據庫並創建zabbix數據庫以及創建授權用戶

mysql>  create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to [email protected] identified by ‘zabbix‘;
mysql> flush privileges;

11.編輯zabbix-server配置文件,修改以下參數為創建數據庫時的信息,並重啟zabbix-server

vim /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBHost=192.168.179.132
DBUser=zabbix
DBPassword=zabbix

創建pid文件

touch /var/run/zabbix/zabbix_server.pid
chmod 777 /var/run/zabbix/zabbix_server.pid

啟動zabbix-server

systemctl enable zabbix-server
systemctl start zabbix-server

12.將初始數據導入MySQL中

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

三、安裝Nginx

1.關掉防火墻和selinux

systemctl stop firewalld
systemctl disable firewalld
sed -i ‘s/SELINUX=enforcing/SELINUX=disable/g‘ /etc/selinux/config

2.安裝依賴

yum -y install wget vim lsof lrzsz pcre-devel zlib-devel make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel libmcrypt libmcrypt-devel mcrypt mhash net-snmp-devel
yum -y install gcc bison bison-devel openssl-devel readline-devel libedit-devel sqlite-devel freetype freetype-devel libevent-devel mysql-devel

3.配置Nginx的yum倉庫

cat >>/etc/yum.repos.d/nginx.repo <<EOF
[nginx]
name=nginx.repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
skip_if_unavailable = 1
keepcache = 0
EOF

4.安裝並啟動Nginx

yum install nginx -y
systemctl start nginx
systemctl enable nginx

四、安裝PHP

1.添加PHP用戶

useradd -s /sbin/nologin php-fpm

2.安裝PHP依賴庫

yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

3.編譯安裝php

wget http://mirrors.sohu.com/php/php-7.2.6.tar.gz
tar zxvf php-7.2.6.tar.gz
cd php-7.2.6
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd  --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-libxml-dir=/usr/local --with-gettext
make && make install
echo $? #每執行完上條命令就運行一下,如果返回0,則執行成功
cp php.ini-production /usr/local/php/etc/php.ini

4.更改PHP配置文件

sed -i ‘s/post_max_size = 8M/post_max_size = 32M/g‘ /usr/local/php/etc/php.ini
sed -i ‘s/upload_max_filesize = 2M/upload_max_filesize = 50M/g‘ /usr/local/php/etc/php.ini
sed -i ‘s/;date.timezone =/date.timezone =PRC/‘ /usr/local/php/etc/php.ini
sed -i ‘s/max_execution_time = 30/max_execution_time = 600/g‘ /usr/local/php/etc/php.ini
sed -i ‘s/max_input_time = 60/max_input_time = 600/g‘ /usr/local/php/etc/php.ini
sed -i ‘s/memory_limit = 128M/memory_limit = 256M/g‘ /usr/local/php/etc/php.ini
sed -i ‘s/; max_input_vars = 1000/max_input_vars = 10000/g‘ /usr/local/php/etc/php.ini

5.啟動php-fpm

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default  /usr/local/php/etc/php-fpm.d/www.conf
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf

五、安裝zabbix-agent

yum install zabbix-agent
vim /etc/zabbix/zabbix-agentd.conf

Server和ServerActive分別代表zabbix的被動模式和主動模式,這裏都填server端的IP
最後一行是開啟腳本采集數據
技術分享圖片

六、安裝zabbix-web

1.將zabbix的php源文件拷貝到網站目錄上

cp -r /usr/share/zabbix/.* /usr/share/nginx/html/

2.修改nginx配置

egrep -v ‘(^.*#|^$)‘ /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  192.168.179.133;
    access_log  /var/log/nginx/host.access.log  main;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }
    location /zabbix {
    root    /usr/share/nginx/html;
    index   index.html index.htm index.php;
    }
    error_page  404              /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    }
}

技術分享圖片

3.授予zabbix-web目錄權限並重啟nginx

chmod -R 777 /etc/zabbix/web.
chmod -R 777 /usr/share/nginx/html/zabbix
systemctl restart nginx

4.在瀏覽器上訪問192.168.179.133/zabbix開始安裝zabbix-web

技術分享圖片
技術分享圖片
技術分享圖片
技術分享圖片
技術分享圖片
技術分享圖片
技術分享圖片

七、升級zabbix

1.停止zabbix-server和zabbix-proxy

由於我是本地測試環境,沒裝proxy,所以只停server

systemctl stop zabbix-server

2.備份4.0配置數據

mysqldump -uzabbix -p --single-transaction --master-data=2 --databases zabbix > olddata.sql

3.更新存儲庫配置包

rpm -Uvh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm

4.升級Zabbix組件

yum upgrade zabbix-server-mysql zabbix-web-mysql zabbix-agent

5.啟動Zabbix-server進程

systemctl start zabbix-server

6.授予zabbix-web權限

chmod 777 -R /etc/zabbic/web

7.將生成的前端文件放在網站目錄下

當時這裏做了三次才想到,之前一直以為是數據庫的問題,後來一想數據庫是4020000,而前端是4000000,說明數據庫是4.2的了,有問題的應該是前端,又想到前端已經生成好了,只不過沒拷貝到網站目錄下而已

技術分享圖片

cp -r /usr/share/zabbix/.* /usr/share/nginx/html/

至此,zabbix4.0升級到4.2完成


歡迎各位關註本人公眾號“沒有故事的陳師傅”
技術分享圖片

zabbix4.2安裝以及4.0升級4.2