[Up]常用資訊

[重點文章] 重點文章 [重點文章] 重點文章

2022年6月28日 星期二

[Debian] 安裝 zabbix 6.0 + mariadb-10.7 + php-8.1

[Debian] 安裝 zabbix 6.0 + mariadb-10.7 + php-8.1

[Debian] 安裝 zabbix 6.0 + mariadb-10.7 + php-8.1

 
#Step 01 – 安裝資料庫


Step 1: Update system apt index

sudo apt -y update
sudo apt -y install software-properties-common gnupg2 dirmngr
sudo apt -y upgrade
sudo reboot


Step 2: Import MariaDB gpg key and add repository.
#####$ apt install software-properties-common dirmngr -y
#
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=10.7 --skip-maxscale --skip-tools
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
## Debian 11 ###
sudo add-apt-repository 'deb [arch=amd64,i386,arm64,ppc64el] https://mariadb.mirror.liquidtelecom.com/repo/10.7/debian bullseye main'



apt update

安裝
sudo apt update
sudo apt install mariadb-server mariadb-client

## $ systemctl start mysql.service
$ sudo systemctl enable --now mysql.service

$ mysql_secure_installation

$ mariadb --version

mysql  Ver 15.1 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64) using readline EditLine wrapper

root@debian-s-1vcpu-1gb-sfo2-01:~#


Step 3: Install MariaDB 10.7 on Debian 11.2 (Buster)

Step 5. Manage MariaDB 10.7 on Debian 11 / Debian 10.

sudo systemctl start mariadb

systemctl status mariadb

sudo systemctl enable mariadb

sudo systemctl restart mariadb


Step 6. Secure MariaDB Installation on Debian

sudo mysql_secure_installation 

Step 7. Use MariaDB 10.7 on Debian 11 / Debian 10

mysql -u root -p
建立 DB

CREATE DATABASE testdb;
CREATE OR REPLACE DATABASE testdb;
MariaDB [(none)]> SHOW DATABASES;
建立使用者 和權限
#Create user mariadb
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant all privileges to the user
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant privileges to a specific database
GRANT ALL PRIVILEGES ON testdb.* TO myuser@localhost;


#Grant privileges to all databases
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost';

#Remember to refresh the privileges
FLUSH privileges;

#To check user grants in MariaDB
SHOW GRANTS FOR 'myuser'@'locahost';
SHOW GRANTS FOR myuser@localhost;

#####
建立 TABLE
USE testdb;
CREATE TABLE employees (id INT, name VARCHAR(20), email VARCHAR(20));
INSERT INTO employees (id,name,email) VALUES(01,"thor","thor@example.com");

MariaDB [testdb]> show tables;

MariaDB [testdb]> SHOW COLUMNS FROM employees;

MariaDB [testdb]> exit
Bye

# 移除 MariaDB
##Remove data from MariaDB
sudo apt purge mariadb-server
sudo rm -rf /var/lib/mysql/

Completely uninstall MariaDB on your system.

sudo apt autoremove mariadb-server mariadb-client



Step 4: Secure MariaDB server
$ sudo mysql_secure_installation 

檢查版本
MariaDB [(none)]> SELECT VERSION();
+------------------------------------------+
| VERSION()                                |
+------------------------------------------+
| 10.5.12-MariaDB-1:10.5.12+maria~bullseye |
+------------------------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]>


#
建立資料庫及給設定使用者權限

CREATE DATABASE labstack;
CREATE USER 'labstackuser'@'localhost' IDENTIFIED BY 'new_password_here';
GRANT ALL ON labstack.* TO 'labstackuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

#####
# 設定 mysql 讓PHP呼叫
'''
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';

create database argus_demo;
GRANT USAGE ON `argus_demo`.* to 'demouser'@'localhost' identified by 'gIWeWCa2k8GuMJSM61';
GRANT ALL PRIVILEGES ON `argus_demo`.* to 'demouser'@'localhost' with grant option;
flush privileges;


CREATE TABLE users (
    id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    username VARCHAR(50) NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);





create database argus_demo2;
GRANT USAGE ON `argus_demo2`.* to 'demouser2'@'localhost' identified by 'gIWeWCa2k8GuMJSM61';
GRANT ALL PRIVILEGES ON `argus_demo2`.* to 'demouser2'@'localhost' with grant option;
flush privileges;

mysql -u demouser2 -pgIWeWCa2k8GuMJSM61 -D argus_demo2 < users.sql

$link = mysqli_connect("localhost","demouser2",".98vfwL9zpLI","argus_demo2");
'''
to diable unix_socket auth (passwordless login on cli)

Mariadb config
/etc/mysql/mariadb.conf.d/50-server.cnf

MySQL config
/etc/mysql/my.cnf

add following parameter


plugin-load-add = auth_socket.so


on mysql cli


update mysql.user set password=password('GerP@ssword') where user='root';
update mysql.user set plugin=” where User='root';
or 
ALTER USER 'root'@'localhost' IDENTIFIED BY 'GerP@ssw0rd';

flush privileges;


restart MySQL server

systemctl restart mariadb.service

or

systemctl restart mysql.service


ALTER USER 'root'@'localhost' IDENTIFIED BY 'GerP@ssw0rd';

 
#Step 02 – 更新php 8.1

############ 安裝 php 8.1 #######################################
sudo apt -y install lsb-release apt-transport-https ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
apt update
apt upgrade

 
#Step 03 – 安裝 zabbix


# wget https://repo.zabbix.com/zabbix/6.0/debian/pool/main/z/zabbix-release/zabbix-release_6.0-3+debian11_all.deb
# dpkg -i zabbix-release_6.0-3+debian11_all.deb
# apt update

# apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-sql-scripts zabbix-agent

建立資料庫

# mysql -uroot -p
password
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;

匯入 zabbix sql

# zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p zabbix

vi /etc/zabbix/zabbix_server.conf

DBPassword=password

# systemctl restart zabbix-server zabbix-agent apache2
# systemctl enable zabbix-server zabbix-agent apache2


 
#Step 04 – 中文化


修改中文語系

中文化
事前準備 
設定語系
# locale -a
# dpkg-reconfigure locales (安裝語系)
# apt install xfonts-intl-chinese

修改中文語系  # 要等 zabbix 安裝完成後才能使用下列指令

sed -i '/zh_TW/s/false/true/' /usr/share/zabbix/include/locales.inc.php

上傳 中文自行檔 # 重要

修改簡體中文語系 亂碼
[root@zabbix ~]# sed -i  's/graphfont/simkai/g'  /usr/share/zabbix/include/defines.inc.php
換成繁體中文字形
[root@zabbix ~]# sed -i 's/graphfont/kaiu/g' /usr/share/zabbix/include/defines.inc.php

將 kaiu.ttf 上傳到 /usr/share/zabbix/assets/fonts

cd /usr/share/zabbix/assets/fonts
#
mv graphfont.ttf graphfont.ttf.back
#
ln -s kaiu.ttf graphfont.ttf

連接你的 
http://server_ip_or_name/zabbix

# CAT #/etc/zabbix/zabbix_server.conf
DBHost = 192.168.1.9 
DBName = zabbix
DBUser = zabbix
DBPassword = asdfsdf
DBSocket =/data/mysql/mysql.sock
StartPollers = 500 
StartPollersUnreachable = 40 
StartTrappers = 20 
StartPingers = 10 
StartDiscoverers = 10 
CacheSize = 2G
StartDBSyncers = 30 
HistoryCacheSize = 2048M
TrendCacheSize = 1024M
ValueCacheSize = 2048M
Timeout = 30 
AlertScriptsPath =/zabbixscripts
LogFile =/tmp/zabbix_server.log
LogSlowQueries = 3000 
AllowRoot = 1


 
#Step 05 – 安裝proxy


# wget https://repo.zabbix.com/zabbix/6.0/debian/pool/main/z/zabbix-release/zabbix-release_6.0-3+debian11_all.deb
# dpkg -i zabbix-release_6.0-3+debian11_all.deb
# apt update

apt install zabbix-proxy-mysql zabbix-sql-scripts zabbix-agent

mysql -uroot -p
#输入密码
create database zabbix_proxydb character set utf8 collate utf8_bin;
create user zabbixproxyuser@localhost identified by 'Stx12WsaB';
grant all privileges on zabbix_proxydb.* to zabbixproxyuser@localhost;
quit; 


cat /usr/share/doc/zabbix-sql-scripts/mysql/proxy.sql | mysql -uzabbixproxyuser -p zabbix_proxydb

匯入 zabbix proxy sql
# zcat /usr/share/doc/zabbix-sql-scripts/mysql/proxy.sql | mysql -uzabbix -p'zabbixDBpass' zabbix_proxy

匯入 zabbix sql

# zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p zabbix

vi /etc/zabbix/zabbix_proxy.conf
DBHost=localhost
DBName=zabbix_proxydb
DBUser=zabbixproxyuser
DBPassword=Stx12WsaB


systemctl restart zabbix-proxy zabbix-agent
systemctl enable zabbix-proxy zabbix-agent


# cat/etc/zabbix/zabbix_proxy.conf
Server = xxx.xxx.xxx.xxx 
Hostname =proxy.com 
LogFile =/tmp/zabbix_proxy.log
DBHost=localhost
DBName=zabbix_proxydb
DBUser=zabbixproxyuser
DBPassword=Stx12WsaB
#
StartPollers = 500 
StartTrappers = 50 
StartPollersUnreachable = 50
Timeout = 30 
CacheSize = 2048M
HistoryCacheSize = 512M
HistoryIndexCacheSize = 512M
LogSlowQueries = 3000 
ConfigFrequency = 60 
DataSenderFrequency = 60 
PidFile =/tmp/zabbix_proxy.pid
  
###

#改主機名稱
#
sed -i 's/Server=127.0.0.1/Server=192.168.88.118/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/Hostname=Zabbix proxy/Hostname=Debian11-Zabbox-Proxy01/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/DBName=zabbix_proxy/DBName=zabbix_proxydb/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/DBUser=zabbix/DBUser=DBUser=zabbix/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/# DBPassword=/DBPassword=Stx12WsaB/g' /etc/zabbix/zabbix_proxy.conf
#
sed -i 's/# ProxyLocalBuffer=0/ProxyLocalBuffer=720/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/# ProxyOfflineBuffer=1/ProxyOfflineBuffer=1/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/# ConfigFrequency=3600/ConfigFrequency=60/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/# DataSenderFrequency=1/DataSenderFrequency=1/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/# CacheSize=8M/CacheSize=3G/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/Timeout=4/Timeout=30/g' /etc/zabbix/zabbix_proxy.conf
#
sed -i 's/# StartPollers=5/StartPollers=500/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/# StartTrappers=5/StartTrappers=200/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/# StartDBSyncers=4/StartDBSyncers=100/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/# StartPingers=1/StartPingers=500/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/# StartPollersUnreachable=1/StartPollersUnreachable=500/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/# StartDiscoverers=1/StartDiscoverers=120/g' /etc/zabbix/zabbix_proxy.conf
sed -i 's/# HistoryCacheSize=16M/HistoryCacheSize=1G/g' /etc/zabbix/zabbix_proxy.conf
  
###

 
#Step 06 –


 
#Step 07 –


 
#Step 08 –


 
#Step 09 –


 
#Step 10 –


沒有留言:

張貼留言