termux搭建服務器方式



pkg install vim

apt update

安裝debian系統
apt install proot-distro
proot-distro install debian
proot-distro login debian

df -h 查看磁盤空間

安裝linux
pkg install proot
termux-chroot
pkg install wget
mkdir CentOS && cd CentOS && pkg install wget openssl-tool proot -y && hash -r && wget https://raw.fastgit.org/EXALAB/AnLinux-Resources/master/Scripts/Installer/CentOS/centos.sh && sed -i 's/githubusercontent.com/fastgit.org/' centos.sh && bash centos.sh && rm centos.sh
ls
./start-centos.sh
exit退出

 

使用ssh連接
apt install openssh
sshd

cp storage/dcim/公鑰文件名.pub ./.ssh
cat .ssh/公鑰文件名.pub >> .ssh/authorized_keys

whoami
ifconfig

ssh連接時候需要連接同一個,都可以上網的wifi
echo "sshd" >> ~/.bashrc

安裝jdk
yum install java-1.8.0-openjdk* -y
java -version

安裝tomcat
https://tomcat.apache.org/download-80.cgi
/data/data/com.termux/files/home/CentOS/centos-fs/usr
/usr/local/tomcat8
直接將本地tomcat考到termux中,然后解壓
yum install unzip
unzip tomcat

或者tar zxvf apache-tomcat-8.0.53.tar.gz

啟動tomcat時如果無法啟動提示權限不足,需要執行命令:chmod u+x *.sh
ls -l 文件名,查看文件權限

/data/data/com.termux/files/home/CentOS/centos-fs/usr/lib

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.aarch64/

修改環境變量
配置vim ~/.zshrc,增加如下內容:

#JDK8
export JAVA_HOME=/data/data/com.termux/files/home/java/jdk8
export PATH=$PATH:$JAVA_HOME/bin:.
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.

java 安裝目錄 /data/data/com.termux/files/home/CentOS/centos-fs/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.aarch64/
tomcat 安裝目錄 /data/data/com.termux/files/home/CentOS/centos-fs/usr/local/apache-tomcat-8.0.26/bin/startup.sh

安裝postgresql
pkg install postgresql
PGDATA=/data/data/com.termux/files/var/lib/pgsql/data
export PGDATA
initdb --encoding=utf-8

修改postgresql.conf,pg_hba.conf允許Navicat連接
pg_ctl start
pg_ctl restart重啟數據庫
createuser postgres
createdb mydb
psql mydb

 

訪問外部存儲卡

termux-setup-storage
CentOS 同目錄的storage 中的3233-3434目錄就是外部存儲卡
進入外部存儲卡的方式:
全目錄地址為:/storage/3233-3434/Android/data/com.termux/files
也是目錄地址:/data/data/com.termux/files/home/storage/external-1
也是目錄地址:~/storage/external-1
ln -s ~/storage/external-1 CentOS/centos-fs/usr/local/external-1

termux中的linux 訪問termux文件
https://blog.csdn.net/qq_35425070/article/details/8604119

nginx

pkg install nginx
nginx
nginx -s reload
nginx -s stop
nginx -s quit
kill -9 `pgrep nginx`
nginx配置,參考:
vim $PREFIX/etc/nginx/nginx.conf
https://www.sqlsec.com/2018/05/termux.html?tdsourcetag=s_pctim_aiomsg
cp -r /data/data/com.termux/files/usr/share/nginx/html /storage/3233-3434/Android/data/com.termux/files/html

 

創建文件軟連接
ln -s /data/data/com.termux/files/home/storage/shared/tencent/QQfile_recv QQ
~ $ cd
~ $ ls

訪問win10共享文件
apt install samba*
使用時提示smb.conf文件,需要手動創建
smbclient -L "\\192.168.1.101\Downloads" -U 賬號%密碼
smbclient //192.168.1.101/Downloads -U 賬號%密碼 -W domain

 

安裝mariadb
pkg isntall mariadb
mysql_install_db
You can start the MariaDB daemon with:
cd '/data/data/com.termux/files/usr' ; /data/data/com.termux/files/usr/bin/mysqld_safe --datadir='/data/data/com.termux/files/usr/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/data/data/com.termux/files/usr/mysql-test' ; perl mysql-test-run.pl

關閉數據庫

 mysqladmin shutdown -p

查看mysql狀態

mysqld status

查看mysql進程

ps aux|grep mysql

 mariadb 剛創建的時候沒有密碼,無法登錄,需要先執行mysql進入命令,

然后執行 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

alter user 'root'@'localhost' IDENTIFIED BY 'YourPassword';

 啟動mysql

mysqld

直接使用php內置服務發布

 php -S 0.0.0.0:8080 -t ./www

 

 

啟動php
php-fpm
關閉php
killall php-fpm

查看端口占用情況

 netstat -tunlp |grep 8000


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM