shell脚本部署lnmp环境

谁借莪1个温暖的怀抱¢ 2022-11-19 11:23 317阅读 0赞

根据别人的脚本改编

  1. #!/bin/bash
  2. menu(){
  3. clear
  4. echo "######################-Menu-#################"
  5. echo "#1.Install Nginx"
  6. echo "#2.Install MySQL"
  7. echo "#3.Install PHP"
  8. echo "#4.Exit Program"
  9. echo "############################################"
  10. }
  11. choice(){
  12. read -p "Please choice a menu[1-4]:" select
  13. }
  14. install_nginx(){
  15. id nginx &> /dev/null
  16. if [ $? -ne 0 ];then
  17. useradd -s /sbin/nologin nginx
  18. fi
  19. if [ -f nginx-1.17.6.tar.gz ];then
  20. tar -xf nginx-1.17.6.tar.gz
  21. cd nginx-1.17.6
  22. yum -y install gcc pcre-devel openssl-devel zlib-devel make
  23. ./configure --prefix=/usr/local/nginx --with-http_ssl_module
  24. make && make install
  25. ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
  26. conf=/usr/local/nginx/conf/nginx.conf
  27. sed -i '65,71s/#//' $conf
  28. sed -i '/SCRIPT_FILENAME/d' $conf
  29. sed -i 's/fastcgi_params/fastcgi.conf/' $conf
  30. cd ..
  31. /usr/local/nginx/sbin/nginx
  32. echo -e "<?php\nphpinfo();\n?>" > /usr/local/nginx/html/index.php
  33. cat > /usr/local/nginx/html/mysql.php <<"EOF"
  34. <?php
  35. $servername = "localhost";
  36. $username = "root";
  37. $password = "Qwe123..";
  38. // 创建连接
  39. $conn = new mysqli($servername, $username, $password);
  40. // 检测连接
  41. if ($conn->connect_error) {
  42. die("连接失败: " . $conn->connect_error);
  43. }
  44. echo "连接成功";
  45. ?>
  46. EOF
  47. else
  48. echo "没有Nginx源码包"
  49. fi
  50. }
  51. install_php(){
  52. yum -y install php php-fpm php-mysql
  53. systemctl restart php-fpm
  54. }
  55. install_mysql(){
  56. if [ -f mysql-5.7.32 ];then
  57. tar -xvf mysql-5.7.32
  58. yum -y install mysql-community-*.rpm
  59. systemctl restart mysqld
  60. systemctl enable mysqld
  61. mysql --connect-expired-password -uroot -p`cat /var/log/mysqld.log|awk '/temporary password/{print $NF}'` << EOF
  62. alter user root@localhost identified by "Qwe123..";
  63. flush privileges;
  64. EOF
  65. else
  66. echo "安装包不存在"
  67. fi
  68. }
  69. while :
  70. do
  71. clear
  72. menu
  73. choice
  74. case $select in
  75. 1)
  76. install_nginx;;
  77. 2)
  78. install_mysql;;
  79. 3)
  80. install_php;;
  81. 4)
  82. exit;;
  83. esac
  84. done

发表评论

表情:
评论列表 (有 0 条评论,317人围观)

还没有评论,来说两句吧...

相关阅读