在Ubuntu 18.04 上安装 Pigeon

在Ubuntu 18.04 上安装 Pigeon

之前在 V2EX 上搜索关于记录短信息的工具,有人推荐 Google Keep,但是身在墙国,腐朽资本主义的东西怎么能用呢!有人推荐 Pigeon ,然后搜索了一下,项目官网:https://github.com/kasuganosoras/Pigeon 看着挺简单轻便的,所以在自己的 VPS 上搭建下。

安装 Pigeon 之前

作为一个菜鸟,安装之前的配置花了我三天时间😭,人蠢果然没救了。

apt-get update

apt-get install nginx php-fpm php-mysql php7.2-mbstring mysql-server -y

nginx , php-fpm php.ini的配置参考之前关于gitblog的文章,重点是开启短标签支持

配置MySQL

就是这个东西花了我三天时间,后来换了一个关键词搜索立马就解决了,所以,关键词,特别是英文关键词在搜索方面是很重要的

For fresh installations, recommend to run the included security script. This changes some of the less secure default options for things like remote root logins and sample users. On older versions of MySQL, you needed to initialize the data directory manually as well, but this is done automatically now.

对于新安装来说,推荐运行内置的安全脚本

mysql_secure_installation

按照提示来操作

# 验证密码强度
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: Y
---------------------------------------------------------------
# 三种等级的密码强度验证
There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
---------------------------------------------------------------
# 按照你选择的密码强度设置密码
Please set the password for root here.

New password: 
Re-enter new password:
---------------------------------------------------------------
# 检测你刚刚输入的密码强度
# 刚刚输入的密码强度是50
# 是否使用刚刚输入的密码?
Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :
---------------------------------------------------------------
# 是否移除匿名用户
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) :
---------------------------------------------------------------
# 是否禁用root用户远程登录
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
---------------------------------------------------------------
# 是否移除测试数据库
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
---------------------------------------------------------------
# 是否将上述设置立刻生效
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

完成后 MySQL 会禁止 root 远程登录

mysql -h 127.0.0.1 -u root -p -P 3306

会提示

ERROR :'Access denied for user 'root'@'localhost'

这就导致我花了大量时间来解决这个错误,找遍了 stackoverflow 也没有好的解决方法,后来在 digitalocean 上找到了一篇 How To Install MySQL on Ubuntu 18.04 的文章,按照文章里的方法解决了,不得不说 digitalocean 的有些文章教程还是很好用的,下面引用下文章中的内容

In Ubuntu systems running MySQL 5.7 (and later versions), the root MySQL user is set to authenticate using the auth_socket plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program (e.g., phpMyAdmin) to access the user.

就是说 MySQL 5.7 版本之后,数据库的 root 账号是通过 auth_socket 这个插件来验证而不是通过密码,这样做更安全,但是如果你需要在外部程序(例如 phpMyAdmin)这样的工具访问就会使情况变得复杂

解决方法:

  • In order to use a password to connect to MySQL as root, you will need to switch its authentication method from auth_socket to mysql_native_password

  • 或者创建一个专属用户
CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'sammy'@'localhost' WITH GRANT OPTION;

使用 sammy 登录MySQL进行操作

设置MySQL

MySQL的配置文件默认存放在/etc/my.cnf或者/etc/mysql/my.cnf

[client]
default-character-set = utf8

[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
skip-character-set-client-handshake
default-storage-engine = INNODB

[mysql]
default-character-set = utf8

重启MySQL服务

安装 Pigeon

请参考作者Github的wiki

https://github.com/kasuganosoras/Pigeon/wiki/Install

按照提示进行安装

git clone https://github.com/kasuganosoras/Pigeon
cd Pigeon/
php install.php

参考资料:

How To Install MySQL on Ubuntu 18.04

Github·Pigeon

Ubuntu 18.04 (LTS) LAMP server tutorial with Apache, PHP 7.2, and MySQL