secure连不上远程地址_[笔记]Mariadb安装并配置远程访问
引言
熟悉的小伙伴都知道我自用有一臺NAS,并為此折騰了不少內(nèi)容:
西蒙宮:折騰,用J3455搭建家庭nas
西蒙宮:讓家庭NAS走向世界,兼談Zerotier
西蒙宮:折騰——組裝NAS編譯安裝ffmpeg
在NAS上部署了Nextcloud與Seafile文件服務,以及Jellyfin影音服務等內(nèi)容,其中不少服務都依賴mysql數(shù)據(jù)庫,然而這臺nas總是命途多舛,最近又一次意外斷電,導致mysql服務又掛了。
原因挺容易理解,mysql對數(shù)據(jù)的操作非常精密,一旦斷電,內(nèi)存中的數(shù)據(jù)來不及寫入硬盤就容易發(fā)生錯誤。
于是,我陷入了沉思...
忽然腦中電光一閃,能不能在閑置VPS上部署一個數(shù)據(jù)庫,讓家庭NAS的所有服務都使用遠程數(shù)據(jù)庫呢?因為VPS不會斷電,所以上面的數(shù)據(jù)庫比較安全。
開源Mariadb是oracle的mysql數(shù)據(jù)庫的有力替代品,而且mariadb對mysql的各個api兼容非常好,所以考慮使用Mariadb咯。
數(shù)據(jù)庫的部署
Mariadb的安裝在ubuntu 18.04上可以參考這里。
簡要步驟如下:
首先更新庫信息
sudo apt update官方庫里就有mariadb,直接安裝
sudo apt install mariadb-server數(shù)據(jù)庫服務會自動開始,可以通過以下命令查看:
sudo systemctl status mariadb可以使用下面的命令查看mariadb的版本:
mysql -V接下來有個重要步驟關系到服務器的安全
sudo mysql_secure_installation命令執(zhí)行后需要回復一些問題,并設置數(shù)據(jù)庫root密碼,各位按需回答yes或no就可以了,這里略過。
安裝完成后,可以嘗試連接數(shù)據(jù)庫
mysql -u root -p至此,mariadb的安裝過程結(jié)束。
配置遠程訪問
一般的mysql的配置文件是在/etc/mysql/my.cnf,mariadb也可找到這個文件,仔細閱讀該文件的注釋內(nèi)容,可以知道m(xù)ariadb的配置項集中于另一文件,其路徑如下,使用vi打開:
vi /etc/mysql/mariadb.conf.d/50-server.cnf將綁定ip地址從127.0.0.1改為0.0.0.0
同時更改綁定端口號從3306改為你想要的一個數(shù)值,例如33606,注意不要使用被防火墻保護的端口。
更改完畢后,重啟數(shù)據(jù)庫,應用配置文件
service mysql restart創(chuàng)建數(shù)據(jù)庫和用戶,配置權限
接下來就很正常的配置新用戶、數(shù)據(jù)庫和配置權限。
1.登錄Mysql
[root@xufeng Desktop]# mysql -u root -p Enter password:2.添加新的用戶
允許本地 IP訪問localhost的Mysql數(shù)據(jù)庫
MariaDB [(none)]> create user 'editest'@'localhost' identified by 'editest123456'; Query OK, 0 rows affected (0.06 sec)允許外網(wǎng)IP訪問數(shù)據(jù)庫editest,本命令包含上面的命令,是所有的IP都可以訪問該數(shù)據(jù)庫
MariaDB [(none)]> create user 'editest'@'%' identified by 'editest123456'; Query OK, 0 rows affected (0.00 sec)用戶創(chuàng)建完成后,刷新授權
MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)3.創(chuàng)建一個新的數(shù)據(jù)庫,并使用show databases命令查看數(shù)據(jù)庫是否創(chuàng)建OK
MariaDB [(none)]> create database editestdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.01 sec)MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | confluence | | editestdb | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.00 sec)4.將改用戶editest賦權給數(shù)據(jù)庫editestdb,并刷新授權
MariaDB [(none)]> grant all privileges on `editestdb`.* to 'editest'@'localhost' identified by 'editest123456' with grant option; Query OK, 0 rows affected, 1 warning (0.00 sec)MariaDB [(none)]> grant all privileges on `editestdb`.* to 'editest'@'%' identified by 'editest123456' with grant option; Query OK, 0 rows affected, 1 warning (0.01 sec)MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)5.退出 root 重新登錄,使用editest登錄檢查本地登錄是否正常,輸入密碼后,正常登錄,并使用show databases命令查看數(shù)據(jù)庫賦權是否正常。
[root@xufeng Desktop]# mysql -u editest -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 7 Server version: 5.7.22 MySQL Community Server (GPL)Copyright (c) 2000, 2018, 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.MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | editestdb | +--------------------+ 2 rows in set (0.00 sec)6.驗證遠程IP地址登錄是否正常,使用MySQL Workbench配置數(shù)據(jù)庫并進行驗證OK
至此結(jié)束。
歡迎交流討論~
總結(jié)
以上是生活随笔為你收集整理的secure连不上远程地址_[笔记]Mariadb安装并配置远程访问的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ajax背景、ajax对象、ajax状态
- 下一篇: solr5.0mysql_ik扩展支持S