Private cloud server building tutorial (nanny level) - desktop computer + ubuntu + docker + nextcloud + mysql + peanut shell intranet penetration

Article Directory


foreword

With the development of the mobile Internet, more and more people use cloud storage to store their documents, photos, videos and other files. I don't know when, we unknowingly began to pay for cloud storage services. Uploading once and accessing from anywhere has increasingly become a daily requirement of people. Followed by the regular monthly charges of each cloud network disk, and the cruel reality of forcing users to be divided into free users, ordinary members, intermediate members, and senior members; at the same time,
with the increasingly stringent network civilization environment construction. Some audio and video resources are harmonized. For example, a certain country, a strange talk about a song, a certain explosion in life, etc. These resources may be deleted if they are placed on a certain cloud network disk. The over-identification of some AI algorithms also caused certain losses to users.
Compared with cloud network disks, private network disks have obvious advantages: free, large capacity (just buy your own hard disk), security, and stability.
This article will introduce the process of setting up a private cloud network disk.
Because I have a desktop computer idle in the study at home, I recently decided to connect it to the Internet and make it a personal cloud server. It can just be used as a private cloud network disk service.
This tutorial mainly explains: home personal desktop computer + Ubuntu 22.04.1 LTS + Docker + Nextcloud + Mysql + peanut shell intranet penetration


1. What is Nextcloud?

Nextcloud is a set of client-server software for creating network drives. Its function is similar to Dropbox, but Nextcloud is free and open source software, and everyone can install and execute it on a private server.
Compared with proprietary services such as Dropbox, Nextcloud's open architecture allows users to use applications to add additional functions to the server, and allows users to fully control their data.
Advantages of Nextcloud:

  • Security: Sensitive and important personal privacy data. You don't have to worry about your private data being leaked or even sold by others. For example, if I have surveillance installed at home, I am worried about putting the surveillance video on a certain cloud network disk hh.
  • Multi-client support: IOS, Android, Windows, MacOS, Linux, Web browser
  • Meet general offline download needs
  • Support basic online audio and video playback functions
  • Multi-application support: online office, note, synchronized contacts, calendar, online collaboration, voice and video calls, mailbox
  • In fact, Nextcloud is more suitable for internal use in enterprises.

2. Installation steps

My home computer operating system is ubuntu.
Docker can greatly simplify application software installation and configuration. Compared with installing software directly under Linux, using Docker containers can reduce your installation and configuration time costs. In this article, we install Nextcloud and Mysql containers in Docker.
After the software is installed and configured, we need to use intranet penetration technology to enable devices on the Internet (external network) to access the Nextcloud service on the home computer.

1. Install docker

1.1 Update apt

sudo apt-get update

insert image description here

1.2 Allow apt to use the repository over HTTPS

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

insert image description here

1.3 Add Docker's official GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

insert image description here
Set up a stable repository (x86_64/amd64 here)
echo
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux /ubuntu
$(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

insert image description here

1.4 install docker

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

1.5 Verify that docker is installed successfully

sudo docker run hello-world

insert image description here

2.docker installs the nextcloud container

2.1 Pull nextcloud

sudo docker pull nextcloud

insert image description here

2.2 docker running nextcloud

sudo docker run --name nextcloud -p 9001:80 -v /home/workSpace/nextcloud/data:/var/www/html/data -d nextcloud

insert image description here
–name: set the container name to nextcloud
-p 9001:80: port mapping, map host port 9001 to port 80 in the container
-v /home/workSpace/nextcloud/data:/var/www/html/data will container The data directory of the project in the project is mapped to the local /home/workSpace/nextcloud/data directory to facilitate configuration
-d nextcloud, the image name to pull

2.3 View running containers

sudo docker ps

insert image description here

2.4 Enter nextcloud for the first time

Enter the IP address + port 9001 in the browser (9001 is the port we configured above).
The first time you enter nextcloud, you will be asked to create an administrator account.
[Storage and database options] The database selects SQLlite by default. If you are using a file sync client, SQLite is strongly discouraged. Here I choose Mysql
insert image description here
insert image description here
mysql has not been installed yet, I need to install mysql again

2.5 docker set the nextcloud container to start automatically

sudo docker update --restart=always nextcloud

insert image description here

3 docker install mysql container

3.1 docker pull mysql container

sudo docker pull mysql:latest

insert image description here

3.2 Configure mysql container

3.2.1 mysql initial configuration

sudo docker run -itd --name mysql -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
  • -p 3307:3306 : Map port 3306 of the container service to port 3307 of the host, and the external host can directly access the MySQL service through the host ip:3307

  • MYSQL_ROOT_PASSWORD=123456: Set the password of the MySQL service root user

insert image description here

3.2.2 Enter the mysql container

sudo docker exec -it mysql bash
  • -it provides an interactive environment

  • bash Start the bash program after entering the instance

insert image description here

3.2.3 Login to mysql

mysql -u root -p
Enter password:123456

insert image description here

3.2.4 Create a database for nextcloud

create database nextcloud charset=utf8;

insert image description here

3.3 docker set the mysql container to start automatically

sudo docker update --restart=always mysql

insert image description here

4 Configure nextcloud to connect to mysql database

The browser returns to the nextcloud configuration page, the database selects the mysql
host name and must fill in the ip:port (it is said that if it is localhost+port, an error will be reported, the reason is unknown)
after configuration, click Install

insert image description here
Choose to install recommended apps.
insert image description here
insert image description here

At this point Nextcloud has been installed successfully

5 Intranet access to nextcloud

5.1 In the LAN environment, the intranet ip accesses nextcloud

After nextcloud is installed, we can access nextcloud through the intranet ip in the LAN
insert image description here

5.2 Set nextcloud to add trusted domain names (white list)

All URLs used to access the Nextcloud server must be whitelisted under the trusted_domains setting in your config.php file. Users are only allowed to log into Nextcloud if they point their browser to the URLs listed in the trusted_domains setting.

ps: The following method mainly describes the method of adding a domain name to nextcloud in the case of a graphical user interface.
You can refer to the article through vim operation under the terminal: [Docker] build a nextcloud private network disk and map the external network

5.2.1 ubuntu global search nextcloud configuration file config.php

Because we don’t know where config.php is stored, we search for the config.php file on the computer through the search command

sudo find / -name "config.php"

insert image description here
Preliminary judgment, this path should be correct
/var/lib/docker/volumes/58fa050d3863d3128837d86707d0b1f92050f7bf40bfdbf3fa38cbfc3350e2cc/_data/config

5.2.2 Use the root authority to open the file manager through the graphical user interface and enter the docker installation directory

Enter /var/lib/docker through the file manager in the graphical user interface, and find that there is a red cross in the lower right corner of the docker folder, indicating that the current account cannot be viewed without root privileges.
insert image description here
We use the root privilege account to open the file manager

Open the file manager through the root account in the terminal

sudo nautilus

insert image description here

Ok, now you can enter in the pop-up file manager

/var/lib/docker/volumes/58fa050d3863d3128837d86707d0b1f92050f7bf40bfdbf3fa38cbfc3350e2cc/_data/config

insert image description here
Right-click config.php - open it with a text editor, and you can edit it . You can
insert image description here
see that "localhost:9001" is added to trusted_domains. Explain that this config.php file is the file we want to find. We add nextcloud's intranet address (mine is 192.168.31.31:9001) under trusted_domains.

insert image description here
After the addition is successful, we visit nextcloud again through the browser in the LAN (intranet).
insert image description here
Intranet access successful!

6. Intranet penetration

After the software is installed and configured, we can only use Nextcloud in the local area network (intranet), and we need to use the intranet penetration technology to connect our home computer to the Internet (external network). Intranet penetration can be achieved in three ways:

  • Contact your bandwidth operator and ask them to provide you with a public network ip
  • Purchase a cloud server with a public network IP + reverse proxy FRP implementation (for the configuration method, please refer to my other article: Alibaba Cloud Linux builds Frp intranet penetration service (compatible with Centos) )
  • Purchase peanut shell intranet penetration service
    Here I use peanut shells for intranet penetration. For other methods, you can refer to related online tutorials.

6.1 Install peanut shell on ubuntu

For detailed tutorials, please refer to: Peanut Shell 5.0 for Linux tutorial

6.1.1 Install weget

update software list

sudo apt-get update

insert image description here

Download the wget tool

sudo apt-get install wget

insert image description here
Check the downloaded and installed successful wget version

wget --version

insert image description here

6.1.2 Download the peanut shell installation package

Download address: Peanut shell client official download
insert image description here

wget "https://down.oray.com/hsk/linux/phddns_5.2.0_amd64.deb" -O phddns_5.2.0_amd64.deb

insert image description here
insert image description here
You can see that the installation package has been downloaded to the [main directory].

6.1.3 Installation

Let's run the installer.

sudo dpkg -i phddns_5.2.0_amd64.deb

insert image description here
Successful installation.

6.2 Set Peanut Shell to start automatically

sudo phddns enable

insert image description here

6.3 Set Peanut Shell Intranet Penetration

Use the ubuntu browser to access the peanut shell website http://b.oray.com
insert image description here
and select [SN login]; enter the peanut shell Linux generated SN code during installation and the default login password admin to log in.
insert image description here
The first time you log in, you need to activate it first. It provides two ways of scanning code activation and password activation, which can be flexibly selected. I choose to scan the code to activate this type.
insert image description here
Use the Peanut Shell APP on the mobile phone to scan the code to activate.

After the activation is successful, enter the peanut shell management platform. If the account bound to the SN code only has the dynamic domain name resolution function, and you need to use the intranet penetration function, you can click "Activate for free", or directly upgrade the account to the service version with the intranet penetration function.

insert image description here
When adding intranet penetration mapping, click the "Add Mapping" button on the page.
insert image description here
Fill in the information required for mapping according to the prompts on the page. Here is an example of mapping the SSH service (port 22) of the Ubuntu system:

① Application Name: Custom

②App icon: choose by yourself

③Mapping Type: Select TCP

④Mapping Template: Do not choose a template for now

⑤ Extranet domain name: select the domain name used for extranet access (the domain name here needs to be purchased)
purchase link: https://hsk.oray.com/parts-center/domain.html

⑥Internet port: select dynamic port

⑦Intranet host: the mapped Ubuntu system intranet IP address

⑧Intranet port: the mapped service type corresponds to port 22

⑨Bandwidth: After purchasing mapping bandwidth, you can support allocating extra bandwidth to mapping, save the default here.

After confirming that the mapping content is correct, click OK.

insert image description here
After clicking [OK], intranet penetration is successful.
insert image description here

We are on an external network computer. Open a browser to access Nextcloud through the domain name. You can see:
insert image description here
Entering this page shows that our intranet penetration has been successful. The domain name has been successfully pointed to the home computer.
However, you need to add a whitelist of access domain names to Nextcloud to allow the ip corresponding to the current device to access the Nexcloud service on your home computer.

6.4 Set nextcloud to add trusted external network domain names (white list)

For the method of setting nextcloud to add a trusted domain name, please refer to 5.2, so I won’t go into details here.
insert image description here
docker restart nextcoud

sudo docker restart nextcloud

insert image description here
After the setting is complete, enter the domain name in the browser, and the page will be opened as follows.
insert image description here
To tell the truth, but when I got to this step, my heart was broken.
insert image description here
Then it occurred to me that it might be a problem with the domain name purchased by Peanut Hull. Then I checked and found that the domain name uses the https protocol, and nextcoud does not allow https by default. You need to set up nectcoud again.

6.5 Set nextcloud to allow https domain names

Refer to step 5.2 and enter
/var/lib/docker/volumes/58fa050d3863d3128837d86707d0b1f92050f7bf40bfdbf3fa38cbfc3350e2cc/_data/config
to open the file config.php
and add a sentence:

'overwriteprotocol' => 'https',

insert image description here
docker restart nextcoud

sudo docker restart nextcloud

insert image description here
Open the external domain name again, and you can access it normally~
insert image description here
insert image description here

7. Use nextcloud

Each client app download website: https://nextcloud.com/install/#install-clients
How to use it, you can refer to the nextcoud official website , and I will not expand it in detail here.

Summarize

At this point, we can easily use nextcloud's cloud storage service.
Of course, nextcloud also has other cloud services such as: cloud notes, mailboxes, etc. It can also be used through configuration.
Since I am not very familiar with linux, I have compiled this article intermittently for 3 weeks. If you think it is useful, please give me a one-click triple link. Haha~
Writing is not easy, please indicate the source for reprinting~.
insert image description here

Reference article:

ubuntu20.04 install docker docker install nextcloud

docker creates mysql install nextcloud

Three ways to teach you how to modify the port mapping of a running docker container

[Docker] build a nextcloud private network disk and map the external network

Peanut shell 5.0 for Linux tutorial

View image information in Docker

https://github.com/nextcloud/server/issues

Guess you like

Origin blog.csdn.net/guigenyi/article/details/126692747