Windows 10 Series – Ubuntu Server Service


内容纲要

Windows 10 Series – Ubuntu Server Service

上一篇文章中讲到了如何在 Windows 10 下开启 Ubuntu 子系统,本章将讲解 Ubuntu 如何配置系统更新源以及常用的一些工具和服务的安装配置。

系统镜像源配置

本章里用到的是清华大学的tuna镜像,速度快也稳定,还是很不错的。

替换为tuna

#### 常用软件安装
## 首先修改镜像源配置
# 备份镜像源 <== 万事先备份,安全操作第一重要
sudo cp /etc/apt/sources.list /etc/apt/sources.list.default

# 修改镜像源为tuna
sudo vim /etc/apt/sources.list
#-- 以下命令从第一个:开始往后是需要输入的批量替换命令,
#-- 在vim的normal模式下输入:开始输入后续命令进行替换
#-- :%s#://archive.ubuntu.com#s://mirrors.tuna.tsinghua.edu.cn#g
#-- :%s#://security.ubuntu.com#s://mirrors.tuna.tsinghua.edu.cn#g

# 更新系统到最新
sudo apt -y update
sudo apt -y upgrade

Install manpages

# 帮助文档安装
sudo apt -y install manpages manpages-zh manpages-dev

Install vim

# 编辑神器 很强大 很好用
sudo apt -y install vim

Install wget

# 网络下载器,可以做到的事情很多,
# 比如静态网站整站clone、自动化脚本爬取指定网站的某些资源等等
# 我曾经就写过两个小脚本,扒Maven中央仓库的jar包扒了170GB+  :)
sudo apt -y install wget

Install curl

# 这个工具也很强大,平时可以用作开发时的API测试工具
sudo apt -y install curl

Install git

# 目前主流的源码版本管理工具
sudo apt -y install git

Install screen

# Linux 终端的分屏神器,在一个终端下可以同时操作多个任务,哪怕ssh断开,任务照样可以跑
sudo apt -y install screen

Install aria2

# 支持最多16线程下载的命令行工具
sudo apt -y install aria2

Server Service

开发的过程中经常会用到的一些服务,比如: MySQL、Redis、Apache、PhpMyAdmin等等。

MySQL

Install

## 查找当前可安装的MySQL
apt search mysql | egrep -A 2 ^mysql | egrep -A 2 "server|client"

### 安装
sudo apt -y install mysql-server-5.7 mysql-source-5.7 mysql-client-5.7

Start

#### Win10下的Ubuntu只能通过service启动服务
### 查看服务
sudo service --status-all

### 直接启动报错
sudo service mysql start
#--  * Starting MySQL database server mysqld
#-- No directory, logging in with HOME=/
#-- mkdir: cannot create directory ‘//.cache’: Permission denied
#-- -su: 19: /etc/profile.d/wsl-integration.sh: cannot create //.cache/wslu/integration: Directory nonexistent
#--                                                              [ OK ]

### 根据报错提示创建文件夹
sudo mkdir /.cache
sudo chown mysql. /.cache

### 再次启动服务
sudo service mysql start
#-- * Starting MySQL database server mysqld                      [ OK ]

Modify MySQL root password

自5.7开始,MySQL在ubutun安装时默认使用空密码,仅可通过本地scoket修改密码,故通过操作系统的root权限可用空密码登录,操作系统的普通用户则无法登录。

# root 用户本地 scoket 登录
sudo mysql -u root

登录成功后开始修改 MySQL 的 root 用户密码:

-- 设置密码并刷新使之生效
-- 此法无效 原因: 默认安装时未设置密码,默认使用 auth_socket 插件进行登录验证
-- 故修改密码需要指明插件
ALTER user 'root'@'localhost' IDENTIFIED BY 'mysql';
FLUSH PRIVILEGES;
-- 此法有效
ALTER user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysql';
FLUSH PRIVILEGES;

-- 查看插件
show variables like '%plugin%';
+-------------------------------+------------------------+
| Variable_name                 | Value                  |
+-------------------------------+------------------------+
| default_authentication_plugin | mysql_native_password  |
| plugin_dir                    | /usr/lib/mysql/plugin/ |
+-------------------------------+------------------------+
2 rows in set (0.00 sec)

-- 改表法-修改密码
UPDATE user SET authentication_string=PASSWORD('mysql'), plugin='mysql_native_password' WHERE user='root' AND host='localhost';
FLUSH PRIVILEGES;

-- 查询用户
select host, user, plugin from mysql.user where user='root';
+-----------+------+-----------------------+
| host      | user | plugin                |
+-----------+------+-----------------------+
| localhost | root | mysql_native_password |
+-----------+------+-----------------------+
1 row in set (0.00 sec)

Apache

安装 Apache 主要是为了使用 phpMyAdmin 来操作数据库,这是一款开源免费的基于PHP开发的B/S架构的数据库管理软件。

# 安装 apache2
sudo apt -y install apache2

# 启动服务
sudo service apache2 start
#-- [Sat May 02 23:06:21.394783 2020] [core:warn] [pid 4733] (92)Protocol not available: AH00076: Failed to enable APR_TCP_DEFER_ACCEPT

### 解决办法
## See: https://lms.im/os/win10-subsystem-apache2-problem.html
# 备份 <== 万事先备份,安全操作第一重要
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.default
sudo vim /etc/apache2/apache2.conf
#-- 最后面添加如下配置然后重启服务即可解决
AcceptFilter http none

phpMyAdmin

Install

# 安装
sudo apt -y install phpmyadmin

#-- 安装过程中跳过db的配置
#-- 后面将配置多数据库支持

Deploy

### 部署到apache
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
### 重启apache
sudo service apache2 start
某些高级功能未开启
#### 安装时没有配置数据库,在访问时出现提示
### 修改如下配置文件,将$dbname的值改为mysql即可
# 备份 <== 万事先备份,安全操作第一重要
sudo cp /etc/phpmyadmin/config-db.php /etc/phpmyadmin/config-db.php.default
sudo vim /etc/phpmyadmin/config-db.php

Multi-Database Support

#### 多数据库支持
### 配置修改
## 配置备份 <== 万事先备份,安全操作第一重要
sudo cp /etc/phpmyadmin/config.inc.php /etc/phpmyadmin/config.inc.php.default

## 配置修改
sudo vim /etc/phpmyadmin/config.inc.php

sudo vim /etc/phpmyadmin/config.inc.php:

#### 
#-- 找到如下行
#-- /* Advance to next server for rest of config */
#-- 在上一行注释下方 $i++; 行下方添加如下配置即可完成多数据支持
    /* Advance to next server for rest of config */
    $i++;
    $connection_hosts = array(
        '1' => array(
                "host"      => "localhost",  # 数据库服务器IP/域名,默认端口号3306
                "user"      => "mysql",      # 数据库用户名
                "password"  => "mysql"       # 数据库用户密码
        ),
        '2' => array(
                "host"      => "192.168.1.101",
                "user"      => "mysql",
                "password"  => "mysql"
        )
    );
    for ($i = 1; $i <= count($connection_hosts); $i++) {
            $cfg['Servers'][$i]['auth_type'] = 'cookie';
            $cfg['Servers'][$i]['host'] = $connection_hosts[$i]['host'];
            $cfg['Servers'][$i]['connect_type'] = 'tcp';
            $cfg['Servers'][$i]['compress'] = false;
            $cfg['Servers'][$i]['user'] = $connection_hosts[$i]['user'];
            $cfg['Servers'][$i]['password'] = $connection_hosts[$i]['password'];
            $cfg['Servers'][$i]['AllowNoPassword'] = true;
            $cfg['Servers'][$i]['extension'] = 'mysqli';
            $cfg['Servers'][$i]['bs_grabage_threshold'] = 50;
            $cfg['Servers'][$i]['bs_repository_threshold'] = '32M';
            $cfg['Servers'][$i]['bs_temp_blog_timeout'] = 600;
            $cfg['Servers'][$i]['bs_temp_log_threshold'] = '32M';
    }

下一篇将讲解Windows 10下的Linux子系统的服务自启动配置

Reference

  1. tuna – 清华大学开源软件镜像站
  2. Mysql5.7忘记root密码及mysql5.7修改root密码的方法
  3. 使用“plugin:auth_socket”更改MySQL 5.7中的用户密码
  4. Win10 子系统 Ubuntu 安装 Apache2 的 Failed to enable APR_TCP_DEFER_ACCEP 问题

声明:
  未经特别说明,本站Blog均采用署名-非商业性使用-禁止演绎 2.5 中国大陆授权。任何违反本协议的行为均属于非法行为。如需非商业性转载,请保留署名。如需商业性转载出版,请直接和联系。


《“Windows 10 Series – Ubuntu Server Service”》 有 2 条评论

回复 Windows 10 Series – Working with Ubuntu LTS – Rtfsc8 取消回复

您的电子邮箱地址不会被公开。