当前位置 : 主页 > 操作系统 > centos >

Nginx 实践案例(yum安装方式):利用LNMP实现可道云盘

来源:互联网 收集:自由互联 发布时间:2022-06-20
​ 可道云,原名芒果云,是基于Web技术的私有云在线文档管理解决方案。Kod,读音通code,意为“代码,编码”,中文名为“可道”。它可以在企业内部完美实现类似百度和阿里云盘的

可道云,原名芒果云,是基于Web技术的私有云在线文档管理解决方案。Kod,读音通code,意为“代码,编码”,中文名为“可道”。它可以在企业内部完美实现类似百度和阿里云盘的功能,实现企业内部的文件共享和存放。

官网: http://kodcloud.com/

1. 架构拓扑及主机说明

Nginx 实践案例(yum安装方式):利用LNMP实现可道云盘_kodcloud

# 三台主机
1 1台 Linux+Nginx+PHP (简称 LNP) 服务器 :
主机名:LNP-Server-IP37
CentOS 7.9
IP:192.168.250.37


2 1台 MySQL+Redis 服务器 :
主机名: MySQL-Redis-IP38
CentOS 8.4
IP:192.168.250.38/24


3 1台 client主机 :
WIN10-PC机

2. 准备 MariaDB 数据库

# CentOS系统的优化,可以查以前的文章;按照架构图修改好主机名
[root@CentOS84-IP38 ]#hostnamectl set-hostname MySQL-Redis-IP38
[root@CentOS84-IP38 ]#exit

# yum 安装 mariadb-server 数据库
[root@MySQL-Redis-IP38 ]#yum -y install mariadb-server
# 启动服务并开启自启
[root@MySQL-Redis-IP38 ]#systemctl enable --now mariadb
# 进入数据库
[root@MySQL-Redis-IP38 ]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 创建 kodbox 库
MariaDB [(none)]> create database kodbox;
Query OK, 1 row affected (0.001 sec)
# 创建可道云盘的数据库账户名和密码
MariaDB [(none)]> create user kodbox@'192.168.250.%' identified by '123456';
Query OK, 0 rows affected (0.001 sec)
# 数据库授权
MariaDB [(none)]> grant all on kodbox.* to kodbox@'192.168.250.%';
Query OK, 0 rows affected (0.001 sec)
# 查看数据库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| kodbox |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.002 sec)

MariaDB [(none)]> use kodbox
Database changed
MariaDB [kodbox]> show tables;
Empty set (0.001 sec)

MariaDB [kodbox]> quit
Bye

3. 准备Redis 服务

# 安装 redis
[root@MySQL-Redis-IP38 ]#yum -y install redis

# 查看版本和安装包信息,初步认识redis
[root@MySQL-Redis-IP38 ]#rpm -qi redis
Name : redis
Version : 5.0.3
....................
[root@MySQL-Redis-IP38 ]#

[root@MySQL-Redis-IP38 ]#rpm -ql redis
/etc/logrotate.d/redis
/etc/redis-sentinel.conf
/etc/redis.conf
/etc/systemd/system/redis-sentinel.service.d
/etc/systemd/system/redis-sentinel.service.d/limit.conf
/etc/systemd/system/redis.service.d
/etc/systemd/system/redis.service.d/limit.conf
/usr/bin/redis-benchmark
/usr/bin/redis-check-aof
/usr/bin/redis-check-rdb
/usr/bin/redis-cli
/usr/bin/redis-sentinel
/usr/bin/redis-server
/usr/lib/.build-id
/usr/lib/.build-id/19
/usr/lib/.build-id/19/e1e3e9c658ca7411675798da3adfb25b456626
/usr/lib/.build-id/46
/usr/lib/.build-id/46/bd1f92df23c67a27dfd80d946a0266614c818a
/usr/lib/.build-id/ac
/usr/lib/.build-id/ac/73b6f68fff8c23ad408fc848ff7ec5a954ef53
/usr/lib/systemd/system/redis-sentinel.service
/usr/lib/systemd/system/redis.service
/usr/lib64/redis
/usr/lib64/redis/modules
/usr/libexec/redis-shutdown
/usr/share/licenses/redis
/usr/share/licenses/redis/COPYING
/usr/share/licenses/redis/COPYING-hiredis
/usr/share/licenses/redis/COPYING-jemalloc
/usr/share/licenses/redis/COPYRIGHT-lua
/usr/share/man/man1/redis-benchmark.1.gz
/usr/share/man/man1/redis-check-aof.1.gz
/usr/share/man/man1/redis-check-rdb.1.gz
/usr/share/man/man1/redis-cli.1.gz
/usr/share/man/man1/redis-sentinel.1.gz
/usr/share/man/man1/redis-server.1.gz
/usr/share/man/man5/redis-sentinel.conf.5.gz
/usr/share/man/man5/redis.conf.5.gz
/var/lib/redis
/var/log/redis
/var/run/redis
[root@MySQL-Redis-IP38 ]#

# 修改 redis 配置文件,仅仅修改一行监听地址为 0.0.0.0 这样网络远程机器才能连接到这台机器的redis服务
[root@MySQL-Redis-IP38 ]#vim /etc/redis.conf
.........................
bind 0.0.0.0 .........................
# 启动 redis
[root@MySQL-Redis-IP38 ]#systemctl enable --now redis
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.
[root@MySQL-Redis-IP38 ]#ss -tln
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 511 0.0.0.0:6379 0.0.0.0:*
LISTEN 0 80 *:3306 *:*

[root@MySQL-Redis-IP38 ]#

## redis 实际生产中需要配置密码,本实验中就忽略这个环节

4. 配置 LNP 服务器

基本任务:配置好Nginx 和 安装和配置 php 支持 redis

4.1 准备 Nginx 服务

# yum 安装nginx
[root@lnp-server-ip37 <sub>]# yum list nginx
Available Packages
nginx.x86_64 1:1.20.1-9.el7 epel
[root@lnp-server-ip37 </sub>]# yum info nginx
Available Packages
Name : nginx
Arch : x86_64
Epoch : 1
Version : 1.20.1

[root@lnp-server-ip37 <sub>]# yum -y install nginx
[root@lnp-server-ip37 </sub>]# nginx -v
nginx version: nginx/1.20.1
[root@lnp-server-ip37 <sub>]#

# 创建网站PHP文件目录
[root@lnp-server-ip37 </sub>]# mkdir -pv /data/html

# 查看安装好的 Nginx 默认的目录和文件结构
[root@lnp-server-ip37 <sub>]# tree /etc/nginx/
/etc/nginx/
├── conf.d
├── default.d
├── fastcgi.conf
├── fastcgi.conf.default
├── fastcgi_params
├── fastcgi_params.default
├── koi-utf
├── koi-win
├── mime.types
├── mime.types.default
├── nginx.conf
├── nginx.conf.default
├── scgi_params
├── scgi_params.default
├── uwsgi_params
├── uwsgi_params.default
└── win-utf

2 directories, 15 files

# 在子配置文件目录内创建 可道云 的server的子配置文件
[root@lnp-server-ip37 </sub>]# vim /etc/nginx/conf.d/kod.conf
[root@lnp-server-ip37 <sub>]# cat /etc/nginx/conf.d/kod.conf
server {
listen 80;
server_name pan.shone.cn;
root /data/html;
location / {
index index.php index.html;
}
location </sub> \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

# 启动 nginx 服务
[root@lnp-server-ip37 ~]# systemctl --now enable nginx

4.2 安装和配置 php 支持 redis

简要说明:为了让php支持redis,可以通过编译安装php-redis模块,也可以利用清华大学yum 源yum直接安装相应模块,本实验采用清华大学的yum源来安装 php-redis模块。

清华大学开源软件镜像站 https://mirror.tuna.tsinghua.edu.cn/

Nginx 实践案例(yum安装方式):利用LNMP实现可道云盘_Kod_02

# 用yum安装 php-redis模块的源
[root@lnp-server-ip37 <sub>]# yum -y install https://mirror.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm

# 安装必须的依赖包
[root@lnp-server-ip37 </sub>]# yum -y install php74-php-fpm php74-php-mysqlnd php74-php-pecl-redis5 php74-php-mbstring php74-php-xml php74-php-gd

# 编辑修改 php-fpm.d/www.conf 的配置文件
[root@lnp-server-ip37 <sub>]# vim /etc/opt/remi/php74/php-fpm.d/www.conf
...................................
;user = apache #注释掉这行,添加并修改成下行内容
user = nginx
; RPM: Keep a group allowed to write in log dir.
;group = apache #注释掉这行,添加并修改成下行内容
group = nginx
...................................

; at http://php.net/session.save-path
;php_value[session.save_handler] = files #注释掉这行,添加并修改成下行内容
php_value[session.save_handler] = redis
;php_value[session.save_path] = /var/opt/remi/php74/lib/php/session #注释掉这行,添加并修改成下行内容
php_value[session.save_path] = "tcp://192.168.250.38:6379"
php_value[soap.wsdl_cache_dir] = /var/opt/remi/php74/lib/php/wsdlcache
;php_value[opcache.file_cache] = /var/opt/remi/php74/lib/php/opcache

# 启动并开机自启 php74-php-fpm.service
[root@lnp-server-ip37 </sub>]# systemctl enable --now php74-php-fpm.service

# 验证端口
[root@lnp-server-ip37 <sub>]# ss -tln
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 511 127.0.0.1:9000 *:*
LISTEN 0 511 [::]:80 [::]:*

[root@lnp-server-ip37 </sub>]#

5. 可道云程序准备及安装

简要说明:浏览可道云官网,了解其基本功能和安装环境,下载好最新的源码包

Nginx 实践案例(yum安装方式):利用LNMP实现可道云盘_nginx_03

# 在线下载 可道云最新的安装包
[root@lnp-server-ip37 <sub>]# wget https://static.kodcloud.com/update/download/kodbox.1.28.zip

# 解压到前面准备好的/data/html 目录下
[root@lnp-server-ip37 </sub>]# unzip kodbox.1.28.zip -d /data/html
Archive: kodbox.1.28.zip
............................
inflating: /data/html/data/system/desktop_app.php
[root@lnp-server-ip37 <sub>]#

# 修改目录的权属和组属性,给 nginx 授权
[root@lnp-server-ip37 </sub>]# id nginx
uid=997(nginx) gid=995(nginx) groups=995(nginx)
[root@lnp-server-ip37 <sub>]# ll /data/html
total 144
drwxr-xr-x 7 root root 99 Mar 16 18:04 app
-rw-r--r-- 1 root root 139320 Mar 16 18:04 Changelog.md
drwxr-xr-x 3 root root 91 Mar 16 18:04 config
drwxr-xr-x 3 root root 20 Mar 16 18:04 data
-rw-r--r-- 1 root root 139 Mar 16 18:04 index.php
drwxr-xr-x 15 root root 212 Mar 16 18:04 plugins
drwxr-xr-x 6 root root 58 Mar 16 18:04 static
[root@lnp-server-ip37 </sub>]# chown -R nginx.nginx /data/html
[root@lnp-server-ip37 <sub>]# ll /data/html
total 144
drwxr-xr-x 7 nginx nginx 99 Mar 16 18:04 app
-rw-r--r-- 1 nginx nginx 139320 Mar 16 18:04 Changelog.md
drwxr-xr-x 3 nginx nginx 91 Mar 16 18:04 config
drwxr-xr-x 3 nginx nginx 20 Mar 16 18:04 data
-rw-r--r-- 1 nginx nginx 139 Mar 16 18:04 index.php
drwxr-xr-x 15 nginx nginx 212 Mar 16 18:04 plugins
drwxr-xr-x 6 nginx nginx 58 Mar 16 18:04 static
[root@lnp-server-ip37 </sub>]#

6. 初始化可道云盘

# 修改WIN10的本地hosts文件,路径为 C:\Windows\System32\drivers\etc\hosts 在最后添加一行
192.168.250.37 yun.shone.cn

在浏览器内输入 yun.shone.cn 出现可道云的初始化向导,按照向导完成初始化

下图看到全部绿色勾,说明依赖包都安装齐全了,否则就需要补全相应的依赖包

Nginx 实践案例(yum安装方式):利用LNMP实现可道云盘_kodcloud_04

下图是前面数据库和redis 准备阶段的相应账号和密码信息,按照要求填好即可

Nginx 实践案例(yum安装方式):利用LNMP实现可道云盘_Kod_05

设好可道云的管理员账号和密码

Nginx 实践案例(yum安装方式):利用LNMP实现可道云盘_nginx_06

初始化完成

Nginx 实践案例(yum安装方式):利用LNMP实现可道云盘_nginx_07

7. 登录和管理可道云盘

用前面设的管理员账号和密码登录,进去就可以管理和使用可道云盘了,这个云盘的界面非常友好。

Nginx 实践案例(yum安装方式):利用LNMP实现可道云盘_nginx_08

Nginx 实践案例(yum安装方式):利用LNMP实现可道云盘_redis_09

特别说明:本文涉及的软件请遵守软件知识产权方的规定。

8. 验证数据库和redis session信息

简要说明:登录redis 和 MariaDB数据库查看运行可道安装向导后的数据库表和redis键值对应关系表

# redis键值
[root@MySQL-Redis-IP38 ]#redis-cli
127.0.0.1:6379> keys *
1) "bf8de5cde2467f4c67b3d28b0339c402"
2) "e3be3277260520036faf2dba09c0202d"
3) "75e068650fada9bfec197bd1c0c84ff9"
4) "8a62df5bb442ff055771c60d0574fa48"
5) "ebf84b3759e19fe766ddfc2b77eb7ea7"
6) "3fb9fd5d927988c39ef043a004183938"
7) "7dc8cb4b50f32d1a08932aaf51c3a1d6"
8) "695ce27c69207e2160afba88b509092a"
9) "bff77d8cec136a70cc44a09c79450291"
10) "a736e627a674842081785ef261dd7d2a"
11) "f187933f7d3e8c86e40c1f3e1c1ca4a5"
12) "ca3c05784ffc6aeaa787d9eeda77c173"
13) "62789189ff738f64b0323f067c91f6b7"
14) "22a289eddb18d549f7fc16422a9ffb94"
15) "c6e50cb480bef9fea9d65d85c230cef9"
16) "949888c0a55a7d140312407f68400591"
17) "d779b0fd6945f557d9282d49f3a48610"
18) "8df969f1f7aeadf98b3834c420954dc3"
19) "100709b6a76a46ac966f86cece77e5ee"
20) "519730f24572b8dfbf00b6e51dd59b7e"
21) "ae75ff77d4b684e4584659170bc90140"
22) "54b40c99ede1fe94fe1e463d6e007753"
23) "08f36c91af6867578ede8383a7b77d48"
24) "0ade71094b79e707658cb9fb8bb6c659"
25) "37f0178fb5b45ad2394aab8a45858b7b"
26) "133de9b6d5fdf3d5c745eab64bd1b0dc"
27) "2b35d44a46d4c34566a65385f33ff0fb"
127.0.0.1:6379> quit

# MariaDB内可道安装向导创建的库和表
[root@MySQL-Redis-IP38 ]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 115
Server version: 10.3.28-MariaDB MariaDB Server

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)]> use kodbox
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [kodbox]> show tables;
+-------------------+
| Tables_in_kodbox |
+-------------------+
| comment |
| comment_meta |
| comment_praise |
| group |
| group_meta |
| io_file |
| io_file_contents |
| io_file_meta |
| io_source |
| io_source_auth |
| io_source_event |
| io_source_history |
| io_source_meta |
| io_source_recycle |
| share |
| share_report |
| share_to |
| system_log |
| system_option |
| system_session |
| user |
| user_fav |
| user_group |
| user_meta |
| user_option |
+-------------------+
25 rows in set (0.001 sec)

MariaDB [kodbox]>
网友评论