当前位置:   article > 正文

Termux 使用_termux redis

termux redis

1 初始化配置

1.1 更换镜像源

  1. sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main@' $PREFIX/etc/apt/sources.list
  2. sed -i 's@^\(deb.*games stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24 games stable@' $PREFIX/etc/apt/sources.list.d/game.list
  3. sed -i 's@^\(deb.*science stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable@' $PREFIX/etc/apt/sources.list.d/science.list
  4. # 更新软件列表
  5. pkg update

1.2 安装基础软件vim curl wget git tree

pkg install vim curl wget git tree -y

1.3 获取外部存储访问权限

termux-setup-storage

1.4 创建目录软连接

ln -s /data/data/com.termux/files/home/storage/shared/termux termux

.
├── storage
│   ├── dcim -> /storage/emulated/0/DCIM
│   ├── downloads -> /storage/emulated/0/Download
│   ├── movies -> /storage/emulated/0/Movies
│   ├── music -> /storage/emulated/0/Music
│   ├── pictures -> /storage/emulated/0/Pictures
│   └── shared -> /storage/emulated/0
├── termux -> /data/data/com.termux/files/home/storage/shared/termux

1.5 安装ssh,并开机启动sshd

安装:

pkg install openssh

启动:

sshd

开机启动ssh:

vim ~/.bashrc

 输入以下内容,并保存

  1. if pgrep -x "sshd" >/dev/null
  2. then
  3. echo "ssh-service运行中.."
  4. else
  5. sshd >/dev/null
  6. echo "ssh-service已开启..."
  7. fi

加载修改的配置,使配置立即生效

source ~/.bashrc

或者

 . ~/.bashrc

1.6 超级管理员身份

利用proot可以为手机没有root的用户来模拟一个root的环境

安装:

pkg install proot -y

2 开发环境配置

2.1 安装数据库(MariaDB

安装:

pkg install mariadb

查看是否安装成功

mysql --version

成功,则展示如下内容

mysql  Ver 15.1 Distrib 10.6.4-MariaDB, for Android (aarch64) using  EditLine wrapper

后台启动mysql

nohup mysqld &

开机启动mysql

将以下内容追加到~/.bashrc文件内

  1. if pgrep -x "mysqld_safe" >/dev/null
  2. then
  3. echo "mysql运行中..."
  4. else
  5. mysqld_safe -u root >/dev/null &
  6. echo "mysql已开启..."
  7. fi

2.2 安装jdk

安装:

pkg install openjdk-17 -y

验证:

java -version

成功,则展示如下内容

openjdk version "17-internal" 2021-09-14
OpenJDK Runtime Environment (build 17-internal+0-adhoc..src)
OpenJDK 64-Bit Server VM (build 17-internal+0-adhoc..src, mixed mode)

2.3 安装redis

pkg install redis

安装后启动:

报如下错误

WARNING Your kernel has a bug that could lead to data corruption during background save. Please upgrade to the latest stable kernel.

需要修改配置文件忽略此错误

 vim /data/data/com.termux/files/usr/etc/redis.conf

取消最后一行的注释,再启动redis即可

开机启动redis

将以下内容追加到~/.bashrc文件内

  1. # 启动redis
  2. if pgrep -x "redis-server" >/dev/null
  3. then
  4. echo "--------------"
  5. echo "redis-server运行中..."
  6. echo "--------------"
  7. else
  8. redis-server /data/data/com.termux/files/usr/etc/redis.conf >/dev/null &
  9. echo "--------------"
  10. echo "redis-server已开启..."
  11. echo "--------------"
  12. fi
source ~/.bashrc

3 系统安装

确保已经安装如下软件

  • proot
  • git
  • wget

安装Ubuntu

  1. # 回到home目录
  2. cd ~
  3. # 克隆安装脚本
  4. git clone https://github.com/MFDGaming/ubuntu-in-termux.git
  5. # 跳转到ubuntu-in-termux目录
  6. cd ubuntu-in-termux
  7. # 授权
  8. chmod +x ubuntu.sh
  9. # 执行安装脚本
  10. ./ubuntu.sh -y

启动Ubuntu

  1. # 启动ubuntu
  2. ./startubuntu.sh

4 基础配置脚本

  1. #!/data/data/com.termux/files/usr/bin/bash
  2. # 配置开机启动项
  3. function initBoot(){
  4. echo
  5. echo "-->删除.bashrc文件"
  6. rm -f ~/.bashrc
  7. echo
  8. echo "-->配置sshd开机启动项"
  9. if isInstall "sshd"
  10. then
  11. echo '
  12. # 启动sshd
  13. if pgrep -x "sshd" >/dev/null
  14. then
  15. echo "ssh-service运行中.."
  16. else
  17. sshd >/dev/null
  18. echo "ssh-service已开启..."
  19. fi
  20. ' >> ~/.bashrc
  21. echo "sshd 开机启动项配置完成"
  22. else
  23. echo "sshd 未安装"
  24. fi
  25. echo
  26. echo "-->配置mariadb开机启动项"
  27. if isInstall "mariadb"
  28. then
  29. echo '
  30. # 启动mariadb
  31. if pgrep -x "mysqld_safe" >/dev/null
  32. then
  33. echo "mysql运行中..."
  34. else
  35. mysqld_safe -u root >/dev/null &
  36. echo "mysql已开启..."
  37. fi
  38. ' >> ~/.bashrc
  39. echo "mariadb 开机启动项配置完成"
  40. else
  41. echo "mariadb 未安装"
  42. fi
  43. echo
  44. echo "-->使配置立即生效"
  45. source ~/.bashrc
  46. }
  47. # 判断多个应用是否都安装成功
  48. function isAllInstalled(){
  49. for soft in $1;do
  50. if isInstall $soft
  51. then
  52. continue
  53. else
  54. return 1
  55. fi
  56. done
  57. }
  58. # 判断应用是否安装成功
  59. function isInstall(){
  60. if ! type $1 >/dev/null 2>&1; then
  61. echo "$1 未安装"
  62. return 1
  63. else
  64. echo "$1 已安装"
  65. return 0
  66. fi
  67. }
  68. # 设置mariadb的root用户密码,允许远程访问数据库
  69. function initMariadb(){
  70. echo "-->修改root账户密码"
  71. while :
  72. do
  73. read -p "请输入root账户密码:" -s db_root_password
  74. if test -z "$db_root_password"
  75. then
  76. echo "密码不能为空"
  77. else
  78. break
  79. fi
  80. done
  81. echo
  82. echo "-->添加远程访问数据库的账户"
  83. while :
  84. do
  85. read -p "请输入远程访问数据库的用户名:" db_remote_username
  86. if test -z "$db_remote_username"
  87. then
  88. echo "用户名不能为空"
  89. else
  90. break
  91. fi
  92. done
  93. echo
  94. echo "-->输入$db_remote_username对应的密码"
  95. while :
  96. do
  97. read -p "请输入$db_remote_username账户密码:" -s db_remote_password
  98. if test -z "$db_remote_username"
  99. then
  100. echo "用户名不能为空"
  101. else
  102. break
  103. fi
  104. done
  105. echo
  106. mysql -u $(whoami) -e "use mysql;set password for 'root'@'localhost' = password('$db_root_password');CREATE USER '$db_remote_username'@'%' IDENTIFIED BY '$db_remote_password';GRANT ALL ON *.* TO '$db_remote_username'@'%';flush privileges;"
  107. echo "数据库账户信息:"
  108. mysql -u $(whoami) -e "use mysql;select host,user,password from user;"
  109. }
  110. # is empty
  111. function isEmpty(){
  112. if test -z "$1"
  113. then
  114. echo ""
  115. else
  116. echo "dmin is set !"
  117. fi
  118. }
  119. echo "Termux初始化脚本"
  120. echo
  121. echo "(1)更换为清华镜像源..."
  122. sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main@' $PREFIX/etc/apt/sources.list
  123. sed -i 's@^\(deb.*games stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24 games stable@' $PREFIX/etc/apt/sources.list.d/game.list
  124. sed -i 's@^\(deb.*science stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable@' $PREFIX/etc/apt/sources.list.d/science.list
  125. # 更新软件列表
  126. pkg update -y
  127. echo
  128. echo "(2)安装基础软件(vim curl wget git tree proot openssh)..."
  129. pkg install vim curl wget git tree proot openssh -y
  130. echo
  131. echo "(3)安装开发软件(mariadb jdk)..."
  132. echo "(3.1)安装mariadb"
  133. read -p "是否安装mariadb,输入yes安装:" mariadb_sure
  134. if test $mariadb_sure = "yes"
  135. then
  136. pkg install mariadb -y
  137. # 启动mariadb
  138. if isInstall mariadb
  139. then
  140. echo "mariadb版本信息:"
  141. mysql --version
  142. echo "启动mariadb"
  143. mysqld_safe -u root >/dev/null &
  144. echo "初始化mariadb"
  145. initMariadb
  146. else
  147. :
  148. fi
  149. else
  150. echo '已跳过安装:mariadb'
  151. fi
  152. echo "(3.2)安装jdk"
  153. read -p "是否安装jdk,输入yes安装:" jdk_sure
  154. if test $jdk_sure = "yes"
  155. then
  156. pkg install openjdk-17 -y
  157. echo "jdk版本信息:"
  158. java -version
  159. else
  160. echo '已跳过安装:jdk'
  161. fi
  162. echo
  163. echo "(4)-设置sshd, mariadb开机启动项"
  164. initBoot
  165. echo
  166. echo "(5)获取外部存储访问权限"
  167. termux-setup-storage
  168. echo
  169. echo "(6)设置新密码"
  170. passwd

5 初始化安装配置脚本

  1. #!/data/data/com.termux/files/usr/bin/bash
  2. # 配置开机启动项
  3. function initBoot(){
  4. echo
  5. echo "-->删除.bashrc文件"
  6. rm -f ~/.bashrc
  7. echo
  8. echo "-->配置sshd开机启动项"
  9. if isInstall "sshd"
  10. then
  11. echo '
  12. # 启动sshd
  13. if pgrep -x "sshd" >/dev/null
  14. then
  15. echo "--------------"
  16. echo "sshd运行中..."
  17. echo "--------------"
  18. else
  19. sshd >/dev/null
  20. echo "--------------"
  21. echo "sshd已开启..."
  22. echo "--------------"
  23. fi
  24. ' >> ~/.bashrc
  25. echo "sshd 开机启动项配置完成"
  26. else
  27. echo "sshd 未安装"
  28. fi
  29. echo
  30. echo "-->配置mariadb开机启动项"
  31. if isInstall "mariadb"
  32. then
  33. echo '
  34. # 启动mariadb
  35. if pgrep -x "mysqld_safe" >/dev/null
  36. then
  37. echo "--------------"
  38. echo "mysql运行中..."
  39. echo "--------------"
  40. else
  41. mysqld_safe -u root >/dev/null &
  42. echo "--------------"
  43. echo "mysql已开启..."
  44. echo "--------------"
  45. fi
  46. ' >> ~/.bashrc
  47. echo "mariadb 开机启动项配置完成"
  48. else
  49. echo "mariadb 未安装"
  50. fi
  51. echo
  52. echo "-->配置ubuntu开机启动项"
  53. if test -e /data/data/com.termux/files/home/ubuntu-in-termux/startubuntu.sh
  54. then
  55. echo '
  56. # 启动Ubuntu系统...
  57. /data/data/com.termux/files/home/ubuntu-in-termux/startubuntu.sh
  58. ' >> ~/.bashrc
  59. echo "ubuntu 开机启动项配置完成"
  60. else
  61. echo "ubuntu 未安装"
  62. fi
  63. echo
  64. echo "-->使配置立即生效"
  65. source ~/.bashrc
  66. }
  67. # 设置mariadb的root用户密码,允许远程访问数据库
  68. function initMariadb(){
  69. echo "-->修改root账户密码"
  70. while :
  71. do
  72. read -p "请输入root账户密码:" -s db_root_password
  73. if test -z "$db_root_password"
  74. then
  75. echo "密码不能为空"
  76. else
  77. break
  78. fi
  79. done
  80. echo
  81. echo "-->添加远程访问数据库的账户"
  82. while :
  83. do
  84. read -p "请输入远程访问数据库的用户名:" db_remote_username
  85. if test -z "$db_remote_username"
  86. then
  87. echo "用户名不能为空"
  88. else
  89. break
  90. fi
  91. done
  92. echo
  93. echo "-->输入$db_remote_username对应的密码"
  94. while :
  95. do
  96. read -p "请输入$db_remote_username账户密码:" -s db_remote_password
  97. if test -z "$db_remote_username"
  98. then
  99. echo "用户名不能为空"
  100. else
  101. break
  102. fi
  103. done
  104. echo
  105. mysql -u $(whoami) -e "use mysql;set password for 'root'@'localhost' = password('$db_root_password');CREATE USER '$db_remote_username'@'%' IDENTIFIED BY '$db_remote_password';GRANT ALL ON *.* TO '$db_remote_username'@'%';flush privileges;"
  106. echo "数据库账户信息:"
  107. mysql -u $(whoami) -e "use mysql;select host,user,password from user;"
  108. }
  109. # 判断多个应用是否都安装成功
  110. function isAllInstalled(){
  111. for((i=0;i<${#base_soft_array[@]};i++));do
  112. if isInstall ${base_soft_array[$i]}
  113. then
  114. continue
  115. else
  116. return 1
  117. fi
  118. done
  119. }
  120. # 判断应用是否安装成功
  121. function isInstall(){
  122. if ! type $1 >/dev/null 2>&1; then
  123. echo "$1 未安装"
  124. return 1
  125. else
  126. echo "$1 已安装"
  127. return 0
  128. fi
  129. }
  130. command_info="
  131. -----------------------------------------------------
  132. 执行Termux初始化安装配置脚本
  133. 输入以下指令编号,执行具体任务
  134. 0-退出
  135. 1-更换镜像源(清华)
  136. 2-安装基础软件(vim curl wget git tree proot openssh)
  137. 3-安装开发软件(jdk, mariadb)
  138. 4-安装ubuntu系统
  139. 5-配置开机启动项
  140. 6-Termux获取外部存储访问权限
  141. ll-显示所有命令
  142. -----------------------------------------------------
  143. "
  144. echo "$command_info"
  145. echo
  146. echo
  147. echo
  148. # 根据指令执行具体任务
  149. while :
  150. do
  151. echo
  152. read -p "请输入指令:" command
  153. case $command in
  154. 0)
  155. echo "退出"
  156. break
  157. ;;
  158. 1)
  159. echo "(1)更换镜像源..."
  160. sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main@' $PREFIX/etc/apt/sources.list
  161. sed -i 's@^\(deb.*games stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24 games stable@' $PREFIX/etc/apt/sources.list.d/game.list
  162. sed -i 's@^\(deb.*science stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable@' $PREFIX/etc/apt/sources.list.d/science.list
  163. # 更新软件列表
  164. pkg update -y
  165. ;;
  166. 2)
  167. echo "(2)安装基础软件(vim curl wget git tree proot openssh)..."
  168. pkg install vim curl wget git tree proot openssh -y
  169. base_soft_array=("vim" "curl" "wget" "git" "tree" "proot" "openssh")
  170. if isAllInstalled $base_soft_array
  171. then
  172. echo "基础软件(vim curl wget git tree proot openssh)安装完成"
  173. else
  174. :
  175. fi
  176. ;;
  177. 3)
  178. echo "(3)安装开发软件(jdk, mariadb)..."
  179. echo "(3.1)安装mariadb"
  180. read -p "输入yes安装安装mariadb:" mariadb_sure
  181. if test $mariadb_sure = "yes"
  182. then
  183. pkg install mariadb -y
  184. # 启动mariadb
  185. if isInstall mariadb
  186. then
  187. echo "mariadb版本信息:"
  188. mysql --version
  189. echo "启动mariadb"
  190. mysqld_safe -u root >/dev/null &
  191. echo
  192. echo "初始化mariadb"
  193. initMariadb
  194. else
  195. :
  196. fi
  197. else
  198. echo '已跳过安装:mariadb'
  199. fi
  200. echo "(3.2)安装jdk"
  201. read -p "输入yes安装jdk:" jdk_sure
  202. if test $jdk_sure = "yes"
  203. then
  204. pkg install openjdk-17 -y
  205. echo "jdk版本信息:"
  206. java -version
  207. else
  208. echo '已跳过安装:jdk'
  209. fi
  210. ;;
  211. 4)
  212. echo "(4)安装ubuntu系统"
  213. # 判断是否安装git,wget,proot
  214. soft_array=("git" "wget" "proot")
  215. if isAllInstalled $soft_array
  216. then
  217. # 执行安装ubuntu命令
  218. # 回到home目录
  219. cd ~
  220. # 克隆安装脚本
  221. git clone https://github.com/MFDGaming/ubuntu-in-termux.git
  222. # 跳转到ubuntu-in-termux目录
  223. cd ubuntu-in-termux
  224. # 授权
  225. chmod +x ubuntu.sh
  226. # 执行安装脚本
  227. ./ubuntu.sh -y
  228. else
  229. echo "缺少必要的软件,建议先执行指令2"
  230. fi
  231. ;;
  232. 5)
  233. echo "(5)配置开机启动项(sshd,mariadb,ubuntu)"
  234. read -p "原先配置将删除,输入yes确认:" init_sure
  235. if test $init_sure = "yes"
  236. then
  237. initBoot
  238. else
  239. echo "取消配置开机启动项"
  240. fi
  241. ;;
  242. 6)
  243. echo "(6)Termux获取外部存储访问权限"
  244. termux-setup-storage
  245. ;;
  246. ll)
  247. echo "$command_info"
  248. ;;
  249. *)
  250. echo '指令错误'
  251. continue
  252. ;;
  253. esac
  254. done


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/143242
推荐阅读
相关标签
  

闽ICP备14008679号