2019-03-01 Ubuntu 18.04安装MariaDB 及创建Cacti数据库

这个是记录了安装Cacti的一部分过程,前面还有安装apache2和php7.2的准备工作跟安装LAMP差不多,就不详细写了,需要请参考Ubuntu 16.04 安装LAMP实践。

#php-mysql和php-snmp是必须要装的,如果装LAMP的时候没装,要补上  
sudo apt install php-mysql php-snmp
#更改/etc/php/7.2/apache2/php.ini  文件里的时区,中国改成"Asia/Shanghai", 这边伦敦改成"Europe/London"
; http://php.net/date.timezone
date.timezone = "Europe/London"

1、安装MariaDB数据库
1.1 安装software-properties-common

root@nagios-cati:~# sudo apt-get install software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
software-properties-common is already the newest version (0.96.24.32.7).
The following package was automatically installed and is no longer required:
  libevent-core-2.1-6
Use 'sudo apt autoremove' to remove it.
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.

1.2 导入MariaDB gpg密钥:

root@nagios-cati:~# sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
Executing: /tmp/apt-key-gpghome.GkvgXJqsSb/gpg.1.sh --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
gpg: key F1656F24C74CD1D8: 6 signatures not checked due to missing keys
gpg: key F1656F24C74CD1D8: public key "MariaDB Signing Key " imported
gpg: Total number processed: 1
gpg:               imported: 1

1.3 添加apt库存库

root@nagios-cati:~# sudo add-apt-repository "deb [arch=amd64,arm64,ppc64el] http://mariadb.mirror.liquidtelecom.com/repo/10.4/ubuntu $(lsb_release -cs) main"
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Hit:2 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Get:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://mariadb.mirror.liquidtelecom.com/repo/10.4/ubuntu bionic InRelease [3,887 B]
Get:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:6 http://mariadb.mirror.liquidtelecom.com/repo/10.4/ubuntu bionic/main amd64 Packages [8,021 B]
Get:7 http://mariadb.mirror.liquidtelecom.com/repo/10.4/ubuntu bionic/main ppc64el Packages [7,792 B]
Get:8 http://mariadb.mirror.liquidtelecom.com/repo/10.4/ubuntu bionic/main arm64 Packages [7,792 B]
Fetched 280 kB in 1s (329 kB/s)
Reading package lists... Done

1.4 安装MariaDB Server:

root@nagios-cati:~# sudo apt -y install mariadb-server mariadb-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
... 太长,略过。中间要输密码

1.5 安装验证,装完了自动启动服务

root@nagios-cati:~# sudo systemctl status mysql
● mariadb.service - MariaDB 10.4.3 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enable
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Fri 2019-03-01 00:16:00 GMT; 1min 35s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 16454 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 31 (limit: 4915)
   CGroup: /system.slice/mariadb.service
           └─16454 /usr/sbin/mysqld
...

2、创建cacti数据库
2.1 测试使用root登录

root@nagios-cati:~# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 46
Server version: 10.4.3-MariaDB-1:10.4.3+maria~bionic mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select version();
+--------------------------------------+
| version()                            |
+--------------------------------------+
| 10.4.3-MariaDB-1:10.4.3+maria~bionic |
+--------------------------------------+
1 row in set (0.001 sec)

2.2 更改数据库配置文件,以适应Cacti需求

root@nagios-cati:~# vim /etc/mysql/mariadb.cnf
#在文件/e/etc/mysql/mariadb.cnf上的[mysqld]下添加以下设置:
max_heap_table_size=512M
tmp_table_size=128M
join_buffer_size=64M
innodb_buffer_pool_size=2048M
innodb_doublewrite=OFF
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
...
#重启mariadb服务:
$ sudo systemctl restart mysql

验证配置是否生效:

root@nagios-cati:~# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 10.4.3-MariaDB-1:10.4.3+maria~bionic mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select @@tmp_table_size;
+------------------+
| @@tmp_table_size |
+------------------+
|        134217728 |
+------------------+
1 row in set (0.000 sec)

MariaDB [(none)]> show variables like 'join_buffer_size';
+------------------+----------+
| Variable_name    | Value    |
+------------------+----------+
| join_buffer_size | 67108864 |
+------------------+----------+
1 row in set (0.001 sec)

MariaDB [(none)]> create database cacti;
Query OK, 1 row affected (0.000 sec)

2.3 创建数据库及赋权cacti_user

MariaDB [(none)]> create database cacti;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> grant all privileges on cacti.* to cactiuser@'localhost' identified by '';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> exit
Bye

验证cacti数据库

root@nagios-cati:~# mysql -u cactiuser -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 36
Server version: 10.4.3-MariaDB-1:10.4.3+maria~bionic mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| cacti              |
| information_schema |
+--------------------+
2 rows in set (0.000 sec)

MariaDB [(none)]>

后面再写Cacti的具体安装使用。

你可能感兴趣的:(2019-03-01 Ubuntu 18.04安装MariaDB 及创建Cacti数据库)