代理服务器网络环境Ubuntu安装MariaDB和MySQL
Proxy Server IP: 10.0.0.10
Ubuntu Server IP: 10.0.0.11
Window PC IP: 10.0.0.12
一、登录Ubuntu服务器,或者使用Putty远程登录。
Last login: Mon Dec 30 04:15:26 2019 from 10.0.0.12
二、查看IP,DNS设置,确认可以联网,可以联网的直接跳到第四步。
paul@ubuntu1804:~$ ping www.163.com
ping: www.163.com: Temporary failure in name resolution
我这里因为在虚拟机网络10.0.0.0/24是通过代理服务器上网,首先得在Ubuntu里设置代理,加上配置文件的后面三条。
paul@ubuntu1804:~$ sudo vim /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
http_proxy=http://10.0.0.10:3128/
https_proxy=https://10.0.0.10:3128/
no_proxy="localhost,127.0.0.1,::1"
然后查看系统是否安装了wget。
paul@ubuntu1804:~$ sudo dpkg -s wget
Package: wget
Status: install ok installed
查询已安装,否则使用sudo apt -y install wget安装, 然后用wget测试是否能连接互联网
paul@ubuntu1804:~$ sudo wget yahoo.com
URL transformed to HTTPS due to an HSTS policy
--2019-12-30 06:01:28-- https://yahoo.com/
Connecting to 10.0.0.10:3128... connected.
Proxy request sent, awaiting response... 301 Moved Permanently
Location: https://www.yahoo.com/ [following]
--2019-12-30 06:01:29-- https://www.yahoo.com/
Connecting to 10.0.0.10:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: 'index.html'
index.html [ <=> ] 334.26K 59.0KB/s in 6.0s
2019-12-30 06:01:35 (55.4 KB/s) - 'index.html' saved [342281]
paul@ubuntu1804:~$ ls
index.html
三、可以只修改apt的代理,参考文末的写法。
paul@ubuntu1804:~$ cd /etc/apt/apt.conf.d/
paul@ubuntu1804:/etc/apt/apt.conf.d$ sudo touch proxy.conf
[sudo] password for paul:
paul@ubuntu1804:/etc/apt/apt.conf.d$ sudo vim proxy.conf
Acquire::http::Proxy "http://10.0.0.1:3128/";
Acquire::https::Proxy "http://10.0.0.1:3128/";
四、现在准备安装数据库服务器,首先查询是否有mariadb的安装包。
paul@ubuntu1804:/etc/apt/apt.conf.d$ sudo apt search mariadb
Sorting... Done
Full Text Search... Done
......
mariadb-server/bionic-updates,bionic-security 1:10.1.43-0ubuntu0.18.04.1 all
MariaDB database server (metapackage depending on the latest version)
mariadb-server-10.1/bionic-updates,bionic-security 1:10.1.43-0ubuntu0.18.04.1 amd64
MariaDB database server binaries
......
我们看到有mariadb-server和mariadb-server-10.1,开始安装mariadb-server。
paul@ubuntu1804:/etc/apt/apt.conf.d$ sudo apt -y install mariadb-server
……
五、安装完成,用默认的root账户登录数据库,初始默认没有密码。
paul@ubuntu1804:~$ sudo mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 41
Server version: 10.1.43-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04
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 |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
六、现在我们创建一个数据库demo。
MariaDB [(none)]> create database demo;
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| demo |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
然后建立一个用来管理demo数据库的账户,允许它在10.0.0.0网络远程连接,密码为Admin@123。
MariaDB [(none)]> GRANT ALL ON demo.* to sqladm@'10.0.0.%' IDENTIFIED BY 'Admin@123' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
刷新权限。
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
退出数据库root账户。
MariaDB [(none)]> exit
Bye
七、然后我们在Win10电脑安装MySQL Workbench用图形管理工具远程管理此数据库。安装完成以后用创建的用户名和密码尝试连接服务器10.0.0.11上的数据库,发现无法连接。
查看mariaDB的服务配置文件,里面有一条bind-address = 127.0.0.1,意思是只允许本机连接,我们注释掉这条。
paul@ubuntu1804:~$ cd /etc/mysql/mariadb.conf.d/
paul@ubuntu1804:/etc/mysql/mariadb.conf.d$ sudo vim 50-server.cnf
……
# bind-address = 127.0.0.1
然后重启mariadb服务,这个服务名字不是mariadb,而是mysqld,否则会提示没有服务。
paul@ubuntu1804:/etc/mysql/mariadb.conf.d$ systemctl status mysqld
八、再次尝试连接,仍然不行,我们查看ubuntu 1804的防火墙,它使用的不是iptables和firewalld,而是ufw,我们停止ufw服务。
如果使用的Redhat系7.0版以上的防火墙为firewalld,其他版本请自行查询。
注意:停止防火墙只为测试,生产服务器测试成功后需修改防火墙规则允许MySQL远程连接,并开启防火墙。
paul@ubuntu1804:/etc/mysql/mariadb.conf.d$ systemctl status ufw
● ufw.service - Uncomplicated firewall
Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor preset: enabled)
Active: active (exited) since Mon 2019-12-30 05:39:26 UTC; 54min ago
paul@ubuntu1804:/etc/mysql/mariadb.conf.d$ systemctl stop ufw
再确认一下服务状态
paul@ubuntu1804:/etc/mysql/mariadb.conf.d$ systemctl status ufw
Active: inactive (dead)
九、再次在MySQL Workbench里点击Test Connection,
连接测试成功。
十、以后可以双击这个连接进入图形界面管理MariaDB,里面能直观的看到系统状态。
=================================================================
附:APT的代理设置文件还可以这么写:
Acquire {
HTTP::proxy "http://10.0.0.10:3128";
HTTPS::proxy "http://10.0.0.10:3128";
}
https://www.serverlab.ca/tutorials/linux/administration-linux/how-to-set-the-proxy-for-apt-for-ubuntu-18-04/