Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert a router into a git server

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to convert a router into a git server". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Hardware

A router that can install OpenWRT (or Linux), I use an old device, Netgear WND3700V1. Depending on your daily workload, prepare a flash drive with enough space, preferably at a high speed, which is enough to match the router's USB port.

systems software

At the time of writing, the version of OpenWRT is 18.06.0, and other versions should also work. OpenWRT has supported the git package for a long time. It may also be my problem, but at least it seems that such a pure technology website can no longer be downloaded without FQ. Because of the hardware complexity of each routing device, although it is the same OpenWRT, different routers still have to download their own hardware version. The installation of OpenWRT is not discussed here, please refer to the relevant official documentation. Usually use the software update function in the management interface of your own router, select the downloaded firmware file, upload and then upgrade. Then, according to the situation of your home network, configure the Internet to set up each project to ensure that the basic routing function works properly.

Manage the router

The default management method for OpenWRT18.06.0 is to use ssh, and the method is ssh root@ [IP address]. According to the FLASH size of the router, the smaller FLASH does not have a WEB GUI interface by default, such as the one I use. Fortunately, using the command line to configure a router is more efficient in most cases, and there are some tasks that cannot be done using the GUI interface. OpenWRT's default account user name is root, and there is no password. Normally, the first login will require you to change your password. In an environment connected to the public network, please log in and change your password as soon as possible.

Configure Mirror sourc

If you can access the official source server without FQ, please skip this section.

OpenWRT uses the opkg tool to manage expansion packs. For the reasons mentioned earlier, you need to configure the use of mirror sources to ensure the installation of the required software packages. A small problem encountered in the middle is the foreign mirror server, which basically uses the https protocol, and OpenWRT cannot directly support it. Most of the domestic images are based on the http protocol, but there is a lack of some driver packages in the image, which can not drive the USB disk. So if you can't find a better source of integrity, you have to divide the small thing of changing the source into two steps. Opkg source configuration file path is: / etc/opkg/distfeeds.conf, first make a backup, and then you can use your favorite editing tool to modify, I am usually vi. Modify the contents of the distfeeds.conf file to:

Src/gz openwrt_core http://openwrt.proxy.ustclug.org/releases/18.06.0/targets/ar71xx/generic/packagessrc/gz openwrt_kmods https://downloads.lede-project.urown.net/snapshots/targets/ar71xx/generic/kmods/4.9.117-1-e017c397f3c6ba06dc921b136a63fb36src/gz openwrt_base http://openwrt.proxy.ustclug.org/releases/18.06.0/packages/mips_24kc/basesrc/gz openwrt_luci http://openwrt.proxy.ustclug.org/ Releases/18.06.0/packages/mips_24kc/lucisrc/gz openwrt_packages http://openwrt.proxy.ustclug.org/releases/18.06.0/packages/mips_24kc/packagessrc/gz openwrt_routing http://openwrt.proxy.ustclug.org/releases/18.06.0/packages/mips_24kc/routingsrc/gz openwrt_telephony http://openwrt.proxy.ustclug.org/releases/18.06.0/packages/mips_24kc/telephony uses two sources They are http://openwrt.proxy.ustclug.org and https://downloads.lede-project.urown.net.

Then use the opkg update command in the OpenWRT command, as long as there is no problem with the network, you can complete the update of the source directory package, of course, the source in https will report an error, never mind.

In general, one opkg update before each package installation is sufficient, which is to download all directories from the software source and index them locally. The router shuts down, or the source content in the cloud changes before it needs to be re-executed.

Then install the software packages required for the https protocol:

Opkg install libustream-openssl ca-bundle ca-certificates

Then do opkg update again, and this time, all sources should be able to get the directory package. If you have a better http source, the step of configuring https access can be omitted.

At this point, the opkg package management tool is complete. If you prefer to use the GUI interface, you can install it with the following command:

Opkg updateopkg install luci installs USB disk and sets automatic loading

If it is only used as a private cloud disk, the format of the USB disk can be arbitrary. But if you are going to use it as a git repository and to make up for the poor FLASH storage of the router, you must use a Linux proprietary format, such as EXT4. So you should back up the flash drive that you are going to use on the router in advance, because the later installation will reformat the flash drive. The first is to install the drivers and related supporting tools needed to load the USB disk:

# suppose you have already done opkg udpateopkg install block-mount e2fsprogs kmod-fs-ext4 kmod-usb3 kmod-usb2 kmod-usb-storage and then use ext4 format Reinitialize the flash drive: # Note that this step clears all existing contents on the flash drive mkfs.ext4 / dev/sda1 and then sets the flash drive to load automatically after the router starts: block detect > / etc/config/fstabuci set fstab.@mount [0] .enabled ='1' & & uci set fstab.@global [0] .check _ fs='1' & & uci commit/sbin/block mount & & service fstab enable

At this time, you can use the mount command to check whether the USB disk is loaded successfully (no reboot is required). If the output information is usually on the last line, if there is a message like the following, it means that the USB disk has been loaded successfully:

/ dev/sda1 on / mnt/sda1 type ext4 (rw,relatime,data=ordered)

In my experiment, there was a flash drive that could not be loaded automatically anyway. It was guessed that it had something to do with the USB disk model or the support of the specific hardware and OpenWRT version. Instead of digging into the cause, you can use a startup script to solve this situation, first execute mkdir / mnt/sda1, and then add it to the last line of the / etc/rc.local file:

Mount / dev/sda1 / mnt/sda1

Rebooting later will automatically load the flash drive.

Install the git toolkit

This step is really not a problem for the new router, which can be done with a single command of opkg:

Opkg install git

It's a big problem for my old router, because this WND3700 router has only 4m FLASH, which is equivalent to the storage space of a hard disk. The git package is 4.3m after compression, which is not available at all. At this time, the EXT4 flash drive that I just installed worked. I installed git on the USB disk by hand, and the size of the software package is not a problem. First download the git package:

Cd / mnt/sda1/wget http://openwrt.proxy.ustclug.org/releases/18.06.0/packages/mips_24kc/packages/git_2.16.3-1_mips_24kc.ipk

Note that the download path is related to the router version you are using, for example, the download address above indicates the OpernWRT18.06.0 version, which runs on the mips_24kc chip. Based on this information, you need to find the software packages available on your router, which is usually done by opkg. After the download is complete, extract the file manually:

The decompression above tar xzvf git_2.16.3-1_mips_24kc.ipk# usually results in 3 files, of which we only use the data.tar.gz file. Mkdir ipkscd ipkstar xzvf.. / data.tar.gzcd. # Delete 3 extracted temporary files rm control.tar.gz data.tar.gz debian-binary

All the files are saved in the / mnt/sda1/ipks/usr path, and we need to complete the installation manually before we can run:

Ln-s / mnt/sda1/ipks/usr/bin/git / usr/bin/ln-s / mnt/sda1/ipks/usr/bin/git-receive-pack / usr/bin/ln-s / mnt/sda1/ipks/usr/bin/git-upload-archive / usr/bin/ln-s / mnt/sda1/ipks/usr/bin/git-shell / usr/bin/ln-s / mnt/sda1/ipks/usr/bin/git-upload-pack / usr/bin/ln-s / mnt/ Sda1/ipks/usr/lib/git-core/ / usr/lib/ln-s / mnt/sda1/ipks/usr/share/git-core/ / usr/share/

At this point, git is ready to use. Next, let's set up a working directory:

Mkdir / mnt/sda1/prjsln-s / mnt/sda1/prjs/ /

The / prjs directory is our main storage directory. Because the router has only one root account, there is no need to consider additional permissions. In the future, all git repositories can be saved by creating a separate directory under the / prjs path. Let's build a test warehouse to verify that it is working properly:

Mkdir / prjs/testcd / prjs/testgit init-- bare

All right, all the preparations on the router have been completed so far. In the future, add a new git warehouse, use the new warehouse name, and repeat the last operation above to build the test warehouse.

Test the git warehouse on the router

Go back to our working computer and set up a working directory at random to test whether the git warehouse on the router is working properly. Let's assume that the IP address of our router is 192.168.1.1. Please modify it to the correct address of your own router.

Mkdir testgitcd testgitgit init .echo "test information" > abc.txtecho "Test Information" > abc1.txtgit add .git commit-m "something new" git remote add origin root@192.168.1.1:/prjs/test/git push-- set-upstream origin master

After the final git push is executed, you need to enter the password for the router root account, and then if a message similar to the following is displayed, it is successful:

Counting objects: 2, done.Delta compression using up to 4 threads.Compressing objects: 100% (2 bytes 2), done.Writing objects: 100% (2 delta 2), 231 bytes | 231.00 KiB/s, done.Total 2 (delta 0), reused 0 (delta 0) To root@192.168.1.1:/prjs/test/570db28..5ab2627 master-> master automatic verification

If you don't want to enter the router password every time git push, you can store the public key of your computer to the router for the record, so you don't need to enter the password in the future. Copy the public key to the router first:

Scp / .ssh/id_rsa.pub root@192.168.1.1:~/

Then execute on the router:

Cat id_rsa.pub > > / etc/dropbear/authorized_keys

You can use ssh to test whether it works. After ssh root@192.168.1.1, if you no longer require a password to log in directly to the router, it means that automatic verification is in effect.

This is the end of "how to convert a router into a git server". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report