之前个人笔记本装的是 Linux Mint, 用了一段时间但是体验不佳, 所以打算换成 Ubuntu . 作为一个 Linux 小白, 当时配置一些软件环境费了不少时间. 这次打算简单记录下, 和大家分享一下我的踩坑记录.
安装 Ubuntu 18.04 LTS
截止发文前, Ubuntu 18.04 LTS 是官方目前最新长期支持的版本. 其安装非常简单, 整个过程只用到如下几项工具, 请提前准备好.
Ubuntu 18.04 LTS https://www.ubuntu.com/download/desktop 镜像
镜像刻录工具 Etcher https://github.com/balena-io/etcher
一个存储容量 4G 以上的 U 盘
简单讲一下流程吧, 说多了也是废话. 首先到 Ubuntu 官网下载 Ubuntu 18.04 LTS 系统镜像, 然后使用 Etcher 这个超级简单的工具把下载好的系统镜像刻录到准备好的 U 盘中.
重启电脑, 根据自己的电脑型号进入 BIOS 设置 U 盘为第一启动项, 如果没问题, 再次重启就会进入 Ubuntu 系统安装引导页面, 根据提示选择安装即可, 具体细节可以参考官方文档 Install Ubuntu Desktop.
安装 Google Chrome
浏览器我偏好 Google Chrome, 因为其运行速度快, 界面简洁. 所装好系统第一件事就是装一个衬手的浏览器.
按下 Ctrl+Alt+T 组合键开启一个终端窗口开始安装吧.
Step 1: 下载 Google 签名密钥并进行安装.
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
Step 2: 设置 Google Chrome 存储库.
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google-Chrome.list
Step 3: 安装 Google Chrome.
先更新存储库索引.
sudo apt-get update
如果安装 Google Chrome 稳定版, 请使用如下命令.
sudo apt-get -y install google-Chrome-stable
如果安装 Google Chrome 测试版, 请使用如下命令.
sudo apt-get -y install google-Chrome-beta
最后, 输入如下命令, 正常打开 Google Chrome 即安装成功.
google-Chrome
安装 OpenVPN Client
搜索引擎我偏好 Google, 我想这也是大多数软件开发人员的选择. 但是在大天朝使用 Google 需要使用点手段, 没错, 就是 FQ.
VPN 原来是用来在公网上连接进企业内网的系统, 后来也发展成为一种 FQ 手段, 而 OpenVPN 又是 VPN 中一种方案, 具有加密强度高等特点. 一般大学也都有提供 VPN 服务, 方便老师同学查阅资料, 当然也可以购买付费 VPN, 有条件的也可以在 VPS 上自行搭建.
Ubuntu 下如何安装使用 OpenVPN 客户端连接 VPN 服务呢?
Step 1: 通过 apt-get 下载 OpenVPN 客户端.
sudo apt-get -y install openvpn
下载完成, 最终程序根目录是 / etc/openvpn.
Step 2: 获取 OpenVPN 服务提供的 client.ovpn 客户端配置文件, 并将其复制到 / etc/openvpn 程序根目录.
sudo cp /download/client.ovpn /etc/openvpn/client.ovpn
Step 3: 启动 OpenVPN 客户端
sudo openvpn --config /etc/openvpn/client.ovpn
输入账号密码, 认证通过, 日志输出正常, 快乐 Google.
多么完美的三步走, 但是我在操作过程遇到新的问题: 连接后所有的站点均无法访问, 从终端输出的日志看不出任何问题, 后来一番查阅得知 是 DNS 没有更改的问题, 后来在 client.ovpn 客户端配置文件中追加如下三行代码得以解决.
- script-security 3
- up /etc/openvpn/update-resolv-conf
- down /etc/openvpn/update-resolv-conf
大概意思是, 在启动 OpenVPN 的时候自动更改 DNS 服务.
如果没有 resolvconf 命令, 需要提前安装下.
sudo apt-get -y install resolvconf
不出意外, 这时再重复操作上述 Step 2,Step 3, 就可以真正的快乐 Google 了.
为了避免每次都需要连接都需要输入认证信息, 我们可以这样做:
先根据用户名 < username > 密码 < password > 生成一个认证文件:
sudo echo -e '<username>\n<password>'>> pass.txt
然后将包含认证信息的文本复制到 OpenVPN 根目录.
sudo cp pass.txt /etc/openvpn/pass.txt
修改 / etc/openvpn/client.ovpn, 指定 auth-user-pass 配置节点.
auth-user-pass /etc/openvpn/pass.txt
这样, 我们每次连接 openvpn 就不用 输入认证信息了.
要想再简单点, 可以在自己的~/.bashrc 中给启动命令设置个别名.
VIM ~/.bash_profile
键入如下内容, 调成命令模式,:wq 保存并退出 VIM 编辑器.
alias VPN='sudo openvpn /etc/openvpn/client.ovpn'
最后输入如下命令更新 bash 配置.
source ~/.bash_profile
这样, 在终端键入 VPN 就可以启动 OpenVPN 客户端了, 不需要再指定配置文件.
当然, FQ 的方法还有很多, 这里推荐另外三种工具, 原理及使用方法请自行研究.
- https://github.com/xx-net/xx-net https://note.youdao.com/
- https://github.com/shadowsocks/shadowsocks https://note.youdao.com/
- https://www.wireguard.com https://note.youdao.com/
安装 Docker CE
卸载旧版本
较旧版本的 Docker 被称为 docker 或 docker-engine. 如果之前安装过, 请先通过如下命令卸载.
sudo apt-get remove docker docker-engine docker.io
设置存储库
在新机器上首次安装 Docker CE, 需要设置 Docker 存储库. 之后, 就可以从存储库安装和更新 Docker 了.
Step 1: 更新 APT 包索引.
sudo apt-get update
Step 2: 确保 APT 以 HTTPS 方式工作.
- sudo apt-get install \
- apt-transport-https \
- ca-certificates \
- curl \
- software-properties-common
Step 3: 为了确保下载有效, 添加 Docker 的官方 GPG 密钥.
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Step 4: 将 Docker 存储库添加到 APT 源.
- sudo add-apt-repository \
- "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
- $(lsb_release -cs) \
- stable"
注意, 更换这个官方源后下载时可能需要 FQ, 不然会出现下载中断的情况.
从存储库安装
更新 APT 包索引.
sudo apt-get update
安装最新版本的 Docker CE.
sudo apt-get install docker-ce
安装指定版本的 Docker CE, 需要先列出您的仓库中可用的版本, 然后选择并安装.
apt-cache madison docker-ce
然后根据完全限定版本字符串 < VERSION > 安装指定版本的 Docker CE.
sudo apt-get install docker-ce=<VERSION>
安装完成后, Docker 守护进程应该会自动启动.
最后, 可以通过运行 hello-world 映像验证是否正确安装了 Docker CE .
sudo docker run hello-world
正常情况下, 容器运行, 终端应该会有类似如下信息输出.
- esofar@Ubuntu:~$ docker run hello-world
- Hello from Docker!
- This message shows that your installation appears to be working correctly.
- To generate this message, Docker took the following steps:
- 1. The Docker client contacted the Docker daemon.
- 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
- (amd64)
- 3. The Docker daemon created a new container from that image which runs the
- executable that produces the output you are currently reading.
- 4. The Docker daemon streamed that output to the Docker client, which sent it
- to your terminal.
- ...
但是我的机器在运行时有如下信息输出, 大概是说客户端连接不到 Docker 的守护进程.
- esofar@Ubuntu:~$ sudo docker run hello-world
- docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
- See 'docker run --help'.
通过 systemctl status docker 确认我的机器是因为 Docker 守护进程拒绝启动导致的.
esofar@Ubuntu:~$ systemctl status docker
● docker.service - Docker Application Container Engine
- Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
- Active: failed (Result: exit-code) since Sun 2018-12-16 15:35:37 CST; 10min ago
- Docs: https://docs.docker.com
- Process: 21333 ExecStart=/usr/bin/dockerd -H unix:// (code=exited, status=1/FAILURE)
- Main PID: 21333 (code=exited, status=1/FAILURE)
- ...
后面在这个 Issues 中找到了问题答案, 竟然是是因为我挂了 VPN, 干扰了 Docker 守护进程默认监听的 Unix 域套接字, 而容器中的进程是通过它与 Docker 守护进程进行通信. 关掉 VPN,systemctl restart docker 重启服务, 解决.
最后再补充一点, 可以通过如下命令将当前用户添加到 Docker 组, 避免每次敲命令都需要在 docker 前加 sudo.
sudo usermod -aG docker ${USER}
即时应用修改, 避免重启机器.
su - ${USER}
如果您在安装过程中遇到其他问题, 请参考 官方文档 和 Issues For Linux https://github.com/docker/for-linux 解决.
安装 MySQL Server
既然已经安装了 Docker , 也就用不着传统方式安装 MySQL 数据库了.
第一步, 通过 docker search 命令搜索 Docker Hub https://hub.docker.com/ 中的 MySQL 镜像.
- esofar@Ubuntu:~$ docker search MySQL
- NAME DESCRIPTION STARS OFFICIAL AUTOMATED
- MySQL MySQL is a widely used, open-source relation... 7611 [OK]
- mariadb MariaDB is a community-developed fork of MyS... 2472 [OK]
- MySQL/MySQL-server Optimized MySQL Server Docker images. Create... 573 [OK]
- zabbix/zabbix-server-MySQL Zabbix Server with MySQL database support 156 [OK]
- hypriot/rpi-MySQL RPi-compatible Docker Image with MySQL 102
- ......
我们选择第一个 Stars 数最多的官方镜像, 拉取到本地.
docker pull MySQL
上述命令默认下载 MySQL 最新版, 下载指定版本可以指定: tag,MySQL 镜像具体有哪些: tag 可用, 请参阅
- https://hub.docker.com/_/mysql?tab=tags .
- docker pull MySQL:5.6
等待下载完成后, 我们可以通过 docker images 命令确认本地镜像列表是否已经存在 MySQL 镜像.
- esofar@Ubuntu:~$ docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- MySQL latest f991c20cb508 5 weeks ago 486MB
- hello-world latest 4ab4c602aa5e 3 months ago 1.84kB
镜像下载完毕, 接下来就可以开启一个 MySQL 服务实例.
docker run --name esofar-MySQL -e MYSQL_ROOT_PASSWORD=sql2018 -d MySQL:tag
esofar-MySQL 是您要分配给容器的名称; sql2018 是为 MySQL 实例 root 用户设置的密码;:tag 是指定所需 MySQL 版本的标记, 最新版可忽略.
使用 docker ps 命令查看本地容器的启用情况, 确认有我刚创建的容器 esofar-MySQL.
- esofar@Ubuntu:~$ docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- a182d96cb996 MySQL "docker-entrypoint.s..." 18 minutes ago Up 18 minutes 3306/tcp, 33060/tcp esofar-MySQL
命令 docker exec 允许您在 Docker 容器内运行命令. 如下命令会在 esofar-MySQL 容器中为您提供一个 bash shell:
docker exec -it esofar-MySQL bash
输入 MySQL -u root -p, 然后键入密码就连接上 MySQL 服务了.
- esofar@Ubuntu:~$ docker exec -it esofar-MySQL bash
- root@a182d96cb996:/# MySQL -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 8
- Server version: 8.0.13 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.
- MySQL>
exit 退出 MySQL 连接, exit 退出容器.
关于 MySQL 更多配置内容请直接参考 Docker Hub MySQL 官方镜像说明 https://hub.docker.com/_/mysql?tab=description .
来源: https://www.cnblogs.com/esofar/p/10124884.html