One, foreword
During this period, I saw something called raspberry PI, which was very interesting after a preliminary understanding, so I wanted to record the whole process.
What is raspberry pie?
Raspberry Pi, short for RPi, (or RasPi/RPi for computer programming education) is a tiny computer the size of a credit card, based on Linux. With the launch of Windows 10 IoT, we’ll also be able to use raspberry PI running Windows. Since its inception, by many computer enthusiasts and makers sought after, once a “party” hard to find. Although its appearance is “petite”, inside the “heart” is very powerful, video, audio and other functions are all, it can be said that the sparrow is small, all the five organs.
1. Use my words
In my words, raspberry PI is a mainframe. You can connect external monitor, keyboard and mouse, USB disk and other peripherals, because it is small in size, and there are many serial ports and external ports, you can directly call a lot of underlying hardware.
2. Commercially available models
There are mostly third-generation B+ models on the market, and there are a lot of raspberry PI on Taobao. The price of pure motherboard (without any peripherals) is around 230+, which is a little expensive and beyond my budget. So I continue to look for cheap ones, and finally I found a raspberry PI with 100+.
Raspberry PI Zero W
Raspberry PI Zero W is a mini raspberry PI that is only 1/3 the size of the 3B +. When you actually get it, it’s super small and super cute. Here is my actual image so you can see how mini it really is.
As you can see, at the top is a plain black felt-tip pen, followed by a plug-and-play external wifi card, followed by a USB card reader, and at the bottom is today’s hero, the Zero W. It’s super small. There’s no. It’s a perfect illustration of the saying, “a sparrow may be small, but it has all the organs.”
The key parameters of the Zero W raspberry PI are as follows:
- BCM2835 processor, 1GHz main frequency, 512MB RAM
- BCM43438 WiFi/BT chip
- Micro-usb power port
- Micro – USB OTG interface
- MiniHDMI port
- Compound video and reset extension interface
- Fragile CSI camera interface
- Micro SD card holder for operating system
- 40-PIN GPIO extension port
- Size: 65 mm * 30 mm
With a CPU of 1 core and 512 MEgabytes of memory, you might think it can’t do anything, but it’s actually pretty good, so it’s a pretty small case for running a website.
4. More raspberry pie
For more raspberry PI models or tutorials you can go to the Raspberry PI Lab website, which has plenty of resources.
Raspberry PI Zero W installation system
1. Prepare
Here are some things you might want to prepare ahead of time:
- 16GB or 32GB SanDisk memory card (note that the old one on the phone, small oh)
- A most common USB Android data cable (not Type-C)
- Usb disk formatting tool (SDFormatter is recommended)
- System burn tool (Win32DiskImager)
- Raspberry PI System (download from the official website)
I used Raspbian Stretch Lite as an official system image. Lite is a deskless version with only a dark console, which is small in size and saves on performance and memory.
Name with desktop is a desktop UI, not familiar with liunx system friends may be more friendly, but the volume is very large, the occupation of performance will be higher.
2. Download the system image file
Download the system image you need, as shown below
You start with a zip package, about 360MB in size, that you need to unzip to get the folder shown above
You can then enter the folder and see an IMG image, which is about 1.7GB in size
Ps: If the official Raspbian image is from another third party, it may not be an IMG image after being decompressed. Please refer to Baidu to solve this problem
3. Use Win32DiskImager to write an image to the memory card
After inserting the memory card into the card reader, insert it into the computer. Open Win32DiskImager software, select IMG image, device select your U disk, and then click Write, write completion will pop up a successful prompt box.
Ps: I did not select the device in the picture above, because the card reader is not inserted, it is just a demonstration
4. Modify the files in the Boot partition
Don’t pull out the card reader just yet. At this point, our computer can see that there is only one partition on the USB flash drive called Boot, which is probably only about 40MB in size. Don’t worry, because Windows doesn’t recognize other partitions of the Liunx system on the memory card.
4.1 Creating an SSH File
Because our Zero W has a mini HDMI interface, but I don’t need a screen, SO I need to use SSH to connect to the system in Zero W, so I need to turn on the SSH function at the first boot. Enter the boot partition and create a new file named SSH, without the suffix !!!! Don’t write anything in it either!!
4.2 Creating the wpa_supplicant.conf file
Since SSH connection requires AN IP address, we need to automatically connect Zero W to wifi at the first startup so that it can be in the same LOCAL area network with our computer, so that we can connect to zero W system through SSH. Similarly, create a file named wpa_supplicant.conf in the boot partition and write the following information to the file and save it:
Country =CN CTRl_interface =DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ssid=" your wifi name" PSK =" Your wifi password "}Copy the code
5. Assemble and connect our smallest mainframe
Remove the memory card from the card reader, insert it into the Zero W, and use a USB Android cable to connect to the power supply (5V1A). Wait for a few minutes, during which time our Zero W light will keep flashing, which is normal. When the light is on, we go to the router and check the IP address of the raspberry PI.
You can see that the IP address of Zero W is 192.168.0.104. Then use SSH connection tool (putty is recommended) to connect to Raspberry PI. The initial account is PI and the password is Raspberry.
The connection is successful, as shown in the figure above. So our system is installed correctly.
Ps: If the mobile phone turns on the hotspot as a router, we can download an app named Android Terminal and enter IP Neigh command to check the IP information of the device connected to the mobile phone.
6. Optimize our raspberry PI system
6.1 modify source
Because of the foreign source, our domestic connection was slow in the past, so we need to modify it to the domestic source. I modified the source of UNIVERSITY of Science and Technology of China.
6.1.1 Modifying the sources.list file
Sudo nano /etc/apt/sources.list sudo nano /etc/apt/sources.list//mirrors.ustc.edu.cn/raspbian/raspbian/raspbian stretch main contrib non-free rpi
Copy the code
6.1.2 Modifying the raspi.list file
Sudo nano/etc/apt/sources list. D/raspi. Other contents list - comments, add the following: deb HTTP://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian stretch main ui
Copy the code
6.1.3 Performing the Update
sudo apt-get update
sudo apt-get upgrade
Copy the code
6.2 Changing the Time Zone
sudo dpkg-reconfigure tzdata
Copy the code
Just go to Asia Asia and choose Shanghai
6.3 Enabling SSH automatically upon Startup
The first:
sudo raspi-config
Copy the code
Select Interfacing Option, then go to SSH and press Enter to enable it
If the SSH service is started after the system is restarted or shut down, the SSH service is disabled by default. You still need to manually start the SSH service. For convenience, you can set the SSH service to automatically start after the system is started. /etc/init.d/ssh start
Try all the suggestions, whereas mine is ok.
7. Install nginx
#The installation
sudo apt-get install nginx
#Start the
sudo /etc/init.d/nginx start
#restart
sudo /etc/init.d/nginx restart
#stop
sudo /etc/init.d/nginx stop
Copy the code
Open your browser to 192.168.0.104 (your raspberry PI IP address) and you will see the nginx page, indicating that it is installed. I have uploaded my blog here, as shown below
I can see the page normally, but this can only be seen on the Intranet (LAN), I want everyone to access what to do?
8. Intranet penetration
Intranet penetration means that Intranet (local) Web applications are penetrated to the public network through NAT so that others can access them.
At present, Intranet penetration mainly consists of NGROK and FRP, which are very easy to use. Domestic NGROK is free of charge, including ItTUN, Sunny and NatApp, which are all free of charge. The first two can customize the domain name, while the latter requires VIP version to customize the domain name.
I have tried all three, I found sunny’s ARM version of ngrok client does not work on my raspberry PI, ittun’s and NatPP’s Ngrok are ok, I use ittun’s Ngrok_ARM version because I need to customize the domain name
The use of these three official website has a detailed description, we check.
This is a normal runtime screenshot, and you can see the console HTTP request log when you visit http://zerow.ittun.com/
Since I need ngrok to run in the background, I use a Screen session to make it run in the background. However, self-starting is not implemented yet. In case of power failure or network failure, I have to manually run ngrok, which is a pain point that has not been solved yet.
9. More
Raspberry PI can not only be used to run a website, there are many functions waiting for you to develop, you can go to the Raspberry PI lab, many gods have written a lot of practical tutorials.
My zero W status information is as follows:
Nginx and Ngrok services are enabled on the server. The remaining memory is 250MB, which is very comfortable. The CPU temperature is not high, running for two days, basically between 37-39.