Note: If you don’t want to download in such a trouble, you can move to 八.Termux的备份和恢复
this step
Termux installs Linux and runs java code
- 1. Cause
- 2. Download software
- 3. Configuration
- 4. Test
- 5. Realize external network access
- 6. Set boot automatically
- Seven. Build a database
- 8. Backup and restore of Termux
1. Cause
The speed of mobile phone replacement is very fast. Even if it takes a long time to change the mobile phone, what do you do with the old mobile phone at home?
But when you suddenly find out that
you don’t need to change the basin, we can use a mobile phone to get a server or a home network disk. There is absolutely no speed limit. The current premise depends on your network speed (there is usually a wireless network at home, right? If you don’t have one, you can get a data card. If you don’t have much, don’t get a network disk. Then upload a few g and you’ll burp if you don’t have data.) What I write here is mainly to use
Termux software on the mobile phone to install linux and build a java environment to run the jar package on the mobile phone
. Build a java environment, run the jar package on the mobile phone, no root is required, and the external network can also be accessed
It is recommended to read it roughly first, and then operate it, so that external network access can be penetrated through the internal network of the Peanut Shell app
2. Download software
It is recommended to use the official website to download, download first F-Droid
and then go to the software to search and Termux
download or download
from or , the network is limited, you can use Baidu for details,Google Play
Google Play
Personally recommend using F-Droid, of course it is just a recommendation
F-Droid address: https://f-droid.org/packages/com.termux/
Google Play address: https://play.google.com/store/apps/details?id=com.termux
Termux official website: https ://termux.dev/en/
3. Configuration
1. Replace the installation source
termux-change-repo
Enter the command, the following interface will appear, click ok or enter. At
first it is the picture below. Wait until
it changes to the picture below and then click ok or press enter. If some are notChinaAll
, you can chooseTsinghua
(Tsinghua source)
Click to switch
renew
pkg update
Install common software
pkg install vim curl wget tree -y
2. Grant permission and create a link
3.1 Grant termux the permission to read files.
Enter the command and it will pop up after a while. After allowing it, enter ls and you will find an additionalstorage
folder.storage
Each folder in it points to each folder of the phone, whichshared
points to the root directory of the internal storage.
termux-setup-storage
3.2 Create a soft link
The purpose of creating a soft link is to facilitate future use. If there is no soft link, you will need to enter a lot to complete the operation of the file. Here,
I create a 1/file file in the root directory of the mobile phone, so it is easy to find
ln -s storage/shared/1/file/ file
Enter ls -l
and you will find one more mapping file file
3.3 Create an ssh connection
because it is not very convenient to use a mobile phone to operate. Here, install openssh to connect to a computer for operation. Of course, only a mobile phone can also be used. It is just a suggestion
install openssh
pkg install openssh -y
Set a password, it is invisible when entering the password, you need to enter the password twice
passwd
Then ifconfig
get the ip address and whoami
get the username
Here it is recommended that the computer turn on the hotspot for the mobile phone, or connect the computer and mobile phone to a wifi at the same time, or use the intranet penetration or... and then use the computer to connect, turn on the wifi of the mobile phone, you can also check the ip
and then you can connect to the computer
3.4 Xshell connects
the mobile phone to start ssh
sshd &
If you start connecting
with a computer, you can watch the big screen on the computer and perform subsequent operations. If you don’t have a computer, you can continue to use your mobile phone.
You can not use it, just record the root authority of
the self-starting
pkg install termux-services
sv-enable sshd
termux There are two methods
1. The phone does not have root, use proot to simulate root
pkg install proot
termux-chroot
#Enter root
exit
#Exit
2. The phone is already rooted, you can Install tsu
pkg install tsu
tsu
#Enter root
exit
#Exit
3. Download jdk
jdk can download the required version from its official website, or use the recommended download
3.1 command download
Because I want to use jdk1.8 and then...
1. Query the official JDK
pkg search jdk
The jdk that can be downloaded will be listed, the following is an openjdk-17
2. Install JDK
pkg install openjdk-17
3. Verify that the installation is successful
java -version
3.2 Official website download
Download the jdk version you need, pay attention to choose the linux-aarch64 version
Oracle official website download address: https://www.oracle.com/java/technologies/downloads/
If you don’t want to log in to your account to download, look here. I downloaded jdk- 8u341-linux-aarch64.tar.gz version, the download speed is unlimited, the network speed is fast, it will be downloaded in a few seconds
jdk-8u341-linux-aarch64.tar.gz, click here to download , the password is 1234
3.2.1 Put jdk into termux
After downloading, transfer the installation package to the phone and put it
根目录/1/file
in a folder.
cp means copy, mv means move
cp file/jdk-8u341-linux-aarch64.tar.gz ~
mv file/jdk-8u341-linux-aarch64.tar.gz ~
3.2.2 Decompress jdk
Unzip jdk and delete it. If you don’t want to delete it, just remove && and the following code
tar -zxvf jdk-8u341-linux-aarch64.tar.gz && rm -rf jdk-8u341-linux-aarch64.tar.gz
Enter the directory after decompression
cd jdk1.8.0_341
Enter
pwd
the acquisition path
The path is:/data/data/com.termux/files/home/jdk1.8.0_341
first install linux, then put the environment in linux
4. Download Linux
4.1 Download using proot-distro
4.1.1 Download and installproot-distro
pkg install proot-distro
4.1.2 Query supported versions
proot-distro list
4.1.3 install ubuntu
proot-distro install ubuntu
Now run ‘proot-distro login ubuntu’ to log in.
4.1.4 run linux
proot-distro login ubuntu
Write a startup script, use the command to start every time, write a running script, run the startup script directly and it will be OK
vi ~/linux-ubuntu-start.sh
Enter i to enter the edit mode, copy the script in, then press esc and use the :wq command to save and exit. The script is as follows:
#启动linux-ubuntu
echo "linux-ubuntu running..."
proot-distro login ubuntu
Set executable permissions for the script
chmod +x ~/linux-ubuntu-start.sh
4.1.5 Start Linux
./linux-ubuntu-start.sh
4.2 Download using script
First install the required git to pull things, proroot will use it to start Centos
pkg install proot git -y
Use git to pull
git clone https://github.com/sqlsec/termux-install-linux
Then you will find an extra termux-install-linux
folder
cd termux-install-linux
Install the python environment, because the executed script requires python
pkg install python -y
Check if the installation is successful
python -V
Start the script, and then make a selection,
python termux-linux-install.py
Here I install Centos, after selecting, press Enter to download, and then wait,
some people will reportCANNOT LINK EXECUTABLE "sh": library "/data/data/com.termux/files/usr/lib/libtermux-exec.so" needed or dlopened by "/system/bin/sh" is not accessible for the namespace "(default)"
an error similar to this, exit and close the software, re-enter, rundpkg --configure -ato fix it, then restart the script
After completion, return to the main directory, enter
Termux-Linux
the folder (the downloaded scripts are placed here), and then the corresponding system has a corresponding name
What I downloaded here is CentOS, just go directly to this folder
cd Termux-Linux/CentOS/
start the system
./start-centos.sh
5. Configure jdk environment
Enter
whoami
to see if it isroot
a user
5.1 Edit configuration
vi /etc/profile
5.2 Add jdk configuration
Enter
i
to enter the edit mode, and then add the following content at the end
HereJAVA_HOME
ispwd
the path obtained before
#set jdk
JAVA_HOME=/data/data/com.termux/files/home/jdk1.8.0_341
CLASS_PATH=$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASS_PATH PATH
5.3 Reload configuration file
source /etc/profile
5.4 Check whether the configuration is successful
java -version
4. Test
1. Transfer files to linux
First put the file under the 根目录/1/file
folderwx.jar
jar包
file
/opt
mv /data/data/com.termux/files/home/file/wx.jar /opt
2. Start the jar package
java -jar wx.jar
Then enter the mobile phone ip: port number to access
5. Realize external network access
1. NATAPP
Pros: Use natapp to run commands in linux, exercise linux commands
Cons: This is a mobile phone, we can install apps, but sometimes it will be disconnected, and it is troublesome to close it when you don’t want others to see it
1.1. Intranet penetration
natapp
The official website of NATAPP is used here : https://natapp.cn/
After registering and logging in, add a tunnel
and purchase directly for free
. Record the authtoken that just configured the port.
1.2. Download the executable file
Click the client download in the upper right corner
URL: https://natapp.cn/#download
1.3. Run
After downloading, put the file
手机根目录/1/file
under the folder
Move
natapp
it intolinux
it
and create a file first, I usually put it/usr/local
in it
mkdir /usr/local/natapp
cd /usr/local/natapp
mobile natapp
mv /data/data/com.termux/files/home/file/natapp /usr/local/natapp/
Make sure that the jar package you got before is starting. You can start it in the foreground, and then create a new connection, or start it in the background. If it is a mobile phone, use the background start
In this way, wx.jar is started in the background, where a.log is the log directory generated by jar startup and the jar package is at the same level, and the name and directory can be customized
nohup java -jar wx.jar > a.log &
If you test the time and find that the time is wrong, please read this article: https://blog.csdn.net/weixin_45853881/article/details/126890153
Here, in order to intuitively see that it is accessed, use the foreground to run, otherwise it is troublesome to look at the log
1. 3.1 Start intranet penetration
Grant natapp permission to run
chmod +x natapp
1.3.1.1 Direct boot
./natapp -authtoken=xxx
Then the mapped external network address will be displayed in the foreground
1.3.1.2 Background start
But some people say, run directly in the foreground, what should I do if I want to get some other code, I am not a computer, so it is inconvenient
to go to the official website of natapp: https://natapp.cn/article/config_ini
to add a configuration file
vi config.ini
Get the following content up, don't forget to write
authtoken
#将本文件放置于natapp同级目录 程序将读取 [default] 段
#在命令行参数模式如 natapp -authtoken=xxx 等相同参数将会覆盖掉此配置
#命令行参数 -config= 可以指定任意config.ini文件
[default]
authtoken= #对应一条隧道的authtoken
clienttoken= #对应客户端的clienttoken,将会忽略authtoken,若无请留空,
log=none #log 日志文件,可指定本地文件, none=不做记录,stdout=直接屏幕输出 ,默认为none
loglevel=ERROR #日志等级 DEBUG, INFO, WARNING, ERROR 默认为 DEBUG
http_proxy= #代理设置 如 http://10.123.10.10:3128 非代理上网用户请务必留空
background start
nohup ./natapp &
At this time, there is another problem. It is indeed started in the background, but I can’t find the mapped URL. What should I do?
Tell me how to fix it, or I will beat you up
modify
config.ini
file
vi config.ini
The modified content is as follows:
modify the log log file tostdout
log level and modify it toINFO
authtoken
write on the official website for yourself
#将本文件放置于natapp同级目录 程序将读取 [default] 段
#在命令行参数模式如 natapp -authtoken=xxx 等相同参数将会覆盖掉此配置
#命令行参数 -config= 可以指定任意config.ini文件
[default]
authtoken= #自己的隧道的authtoken ==>对应一条隧道的authtoken
clienttoken= #对应客户端的clienttoken,将会忽略authtoken,若无请留空,
log=stdout #log 日志文件,可指定本地文件, none=不做记录,stdout=直接屏幕输出 ,默认为none
loglevel=INFO #日志等级 DEBUG, INFO, WARNING, ERROR 默认为 DEBUG
http_proxy= #代理设置 如 http://10.123.10.10:3128 非代理上网用户请务必留空
start up
nohup ./natapp &
Query mapped address
cat nohup.out
This is the mapped address
Check out the running
natapp
ps -ef |grep natapp
Kill the natapp process
kill -9 xxx
, xxx is to find the corresponding port number
kill -9 18433
If you find it troublesome, you can also write a startup script
vi natapp-start.sh
Press
i
to enter edit mode, enter the code below, then pressexc
, enter:wq
#启动natapp
echo "natapp running..."
nohup ./natapp &
Add permissions
chmod +x natapp-start.sh
start up
./natapp-start.sh
The query mapping URL is the same as before
cat nohup.out
If you want to use ssh remotely, the configuration is the same as this one. I have no time recently. I will write it in a few days. You can directly use the following app to get it
2. Peanut shells
2.1 Configure the project port
Now we don't need linux commands, let's start downloading apps
Peanut shell download website: https://hsk.oray.com/download/
The mobile browser and the computer display are not the same, but the problem is not big
. There are two software in total, it is best to download
the peanut shell management app: for adding , Editing, Management Interface
Peanut Shell Intranet App: Also called Peanut Shell Intranet App, it is mainly used to start the Peanut Shell Management App to add open ports.
The external network address and the access address of the management version are the same. The internal network host needs to map the ip: port number. For the mobile phone’s ip, you can find wifi and then connect to the wifi to find the ip or find -> set -> About mobile phone->status information->IP address, every time the mobile phone connects to wifi, it will have a random ip, which can be fixed for him. The method is Baidu, and then there is a chance to have a mapping
diagnosis. This is a failure
because every time you reconnect to the wifi mobile phone It will change the IP so the connection fails. After modifying from the peanut shell management app, exit the background version of the peanut shell internal version software and re-enter it, and then check it again (Exit the software and re-enter to update and load the data just configured)
2.2 Configure ssh port
The configuration items on the mobile phone are also the same, but the interface is different. The
access address here istcp://xxx:xxx
==>tcp://地址:端口号
thistcp://
is high-speed. We use tcp connection herehttp://
,https://
which means (it should be like this)
computer or other platforms. When connecting remotely, you only need to use地址
and端口号
The peanut shell management app must add a port, and then it must be turned on, that is, the green switch, and the computer configuration can also be used. After that, the management app can be closed, and then open the peanut shell intranet app to check whether it is connected. This intranet app It must be turned on all the time (running in the background) to ensure a constant connection
6. Set boot automatically
Look here ===>> https://blog.csdn.net/weixin_45853881/article/details/126930875
Seven. Build a database
Look here ====>> https://blog.csdn.net/weixin_45853881/article/details/126940611
8. Backup and restore of Termux
Look here ====>> https://blog.csdn.net/weixin_45853881/article/details/127427339
Exceeding the limit, I am poor and cannot afford the package.
I have a well-configured cetos system here, and it can be used directly after Russian recovery. It has been uploaded
to csdn, free of charge, and you can download it directly if you need it. /86795325