首页 > 其他分享 >一键安装lnmp

一键安装lnmp

时间:2023-02-22 14:37:34浏览次数:43  
标签:enable -- local 一键 lnmp usr mysql php 安装

#!/bin/bash

 

nginx_souecepwd=/usr/local/nginx 

cdnginx_configpwd=/usr/local/nginx/conf

systemd_ExecStartpwd=/usr/local/nginx/sbin/nginx

if [ ! -d $nginx_souecepwd ];then

mkdir $nginx_souecepwd

echo "=========================开始安装Nginx==========================="


sed -i 's/SELINUX=enforcing/\SELINUX=disabled/' /etc/selinux/config 

 

for nginx_depend_pack in wget gcc pcre pcre-devel zlib zlib-devel;do
nginx_depend_result=$(rpm -qa $nginx_depend_pack)
if [ -z "$nginx_depend_result" ];then
yum install -y $nginx_depend_pack
else
echo "$nginx_depend_pack is 判断是否安装NGINX依赖包OK"
fi
done

 

nginxdownloadurl="http://192.168.80.113/nginx-1.22.0.tar.gz"

cd $nginx_souecepwd 

wget "$nginxdownloadurl"


nginx_targzname=$(echo $nginxdownloadurl | sed 's#.*/##') 

 

tar -zxvf $nginx_targzname 

dirname=$(echo $nginx_targzname | sed 's/.tar.gz//') 


cd $dirname 

./configure --prefix=$nginx_souecepwd

make && make install || exit 1

 

cp /etc/profile /etc/profile.bak 

sed -i '$ a export PATH=$PATH:/usr/local/nginx/sbin' /etc/profile 

 

echo "[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=$systemd_ExecStartpwd
[Install]
WantedBy=multi-user.target" > /usr/lib/systemd/system/nginx.service
#为了使Nginx服务器以systemctl运行

chmod 754 /lib/systemd/system/nginx.service

systemctl start nginx.service

systemctl enable nginx.service

cd $cdnginx_configpwd

cp nginx.conf nginx.conf.bak

sed -i '45s/index index.html index.htm;/ index index.php index.html index.htm ;/g' nginx.conf 

sed -i '65,71s/#/ /g' nginx.conf 

sed -i 's#/scripts#$document_root#g' 

source /etc/profile

nginx -t

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --reload

programName=${0##*/}

source /etc/profile $programName

 

else

echo "=========================安装Nginx失败已经安装过Nginx==========================="

fi

 


#下面是编译PHP安装

php_souece_pwd=/usr/local/php

cd_php_configpwd=/usr/local/php/etc

phpfpm_systemd_ExecStartpwd=/usr/local/php/sbin/php-fpm

cp_phpconf_ini=/usr/local/php/etc/php-fpm.conf.default

cd_phpconf_ini=usr/local/php/etc/php-fpm.conf

if [ ! -d $php_souece_pwd ];then

mkdir $php_souece_pwd

echo "=========================开始安装php==========================="

yum -y install epel-release

for php_depend_pack in gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel;do
php_depend_result=$(rpm -qa $php_depend_pack)
if [ -z "$php_depend_result" ];then
yum install -y $php_depend_pack
else
echo "$php_depend_pack is 判断是否安装php依赖包OK"
fi
done


phpdownloadurl="http://192.168.80.113/php-7.0.27.tar.gz"

cd $php_souece_pwd

wget "$phpdownloadurl"

php_targz_name=$(echo $phpdownloadurl | sed 's#.*/##')

tar -zxvf $php_targz_name

php_dir_name=$(echo $php_targz_name | sed 's/.tar.gz//')

cd $php_dir_name

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm


./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm

./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mhash --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --enable-bcmath --enable-gd --with-jpeg --with-freetype --enable-mbstring --enable-ftp --enable-sockets --with-gettext --enable-session --with-curl --enable-fpm --with-fpm-user=php --with-fpm-group=php --enable-pdo -enable-tokenizer --with-zip

make && make install


cp php.ini-production /usr/local/php/etc/php.ini

 

echo "[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=$phpfpm_systemd_ExecStartpwd
[Install]
WantedBy=multi-user.target" > /usr/lib/systemd/system/php-fpm.service


chmod 754 /usr/lib/systemd/system/php-fpm.service


mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cd $cd_php_configpwd

cp /etc/profile /etc/profile.php

#sed -i '164c listen = 0.0.0.0:9000' 

sed -i '190s/;//g' php-fpm.conf 

echo 'export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin/' >> /etc/profile


source /etc/profile


programName=${0##*/}

echo $programName

source /etc/profile $programName

systemctl start php-fpm.service

systemctl enable php-fpm.service

systemctl restart php-fpm.service

systemctl restart nginx.service

firewall-cmd --zone=public --add-port=9000/tcp --permanent

firewall-cmd --zone=public --add-port=9000/udp --permanent

firewall-cmd --reload

else

echo "=========================安装php失败已经安装过php==========================="

fi

 

 


mysql_souece_pwd=/usr/local/mysql

cd_mysql_cnfmypwd=/usr/local/mysql/etc/my.cnf

data_mysql=/data/mysql

cd_mysqlslow_log=/data/mysql/mysql-slow.log

cp_mysqlmy_conf_ini=

cd_mysqlmy_conf_ini=

if [ ! -d $mysql_souece_pwd ];then

mkdir $mysql_souece_pwd

echo "=========================开始安装mysql==========================="


yum -y install epel-release

useradd -s /sbin/nologin mysql

for mysql_depend_pack in gcc gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel;do
mysql_depend_result=$(rpm -qa $mysql_depend_pack)
if [ -z "$mysql_depend_result" ];then
yum install -y $mysql_depend_pack
else
echo "$mysql_depend_pack is 判断是否安装mysql依赖包OK"
fi
done


mysqldownloadurl="http://192.168.80.113/mysql-5.6.39.tar.gz"

cd $mysql_souece_pwd

wget "$mysqldownloadurl"

mysql_targz_name=$(echo $mysqldownloadurl | sed 's#.*/##')

tar -zxvf $mysql_targz_name

mysql_dir_name=$(echo $mysql_targz_name | sed 's/.tar.gz//')

cd $mysql_dir_name

 

cmake -DCMAKE_INSTALL_PREFIX=$mysql_souece_pwd -DMYSQL_DATADIR=$data_mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_DEBUG=0 -DWITH_SSL=yes -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 2>/tmp/aa

make && make install

cp support-files/mysql.server /etc/init.d/mysqld

 

chmod a+x /etc/init.d/mysqld

cd "$mysql_dir_name"

cp my.cnf my.cnf.bak

mkdir /usr/local/mysql/etc

mv my.cnf /usr/local/mysql/etc/my.cnf.bak

rm -rf /usr/local/mysql/my.cnf

mkdir -pv /data


chmod 777 /data

chown -R mysql:mysql /data/

 

mkdir -pv /data/mysql


chmod 777 /data/mysql

chown -R mysql:mysql /data/mysql

chown -R mysql:mysql /usr/local/mysql/data

chown -R mysql:mysql /usr/local/mysql /data/mysql


echo "[mysqld]
bind-address=0.0.0.0
port=3306
datadir=/data/mysql
user=mysql
skip-name-resolve
long_query_time=2
slow_query_log_file=/data/mysql/mysql-slow.log
expire_logs_days=2
innodb-file-per-table=1
innodb_flush_log_at_trx_commit = 2
log_warnings = 1
max_allowed_packet = 512M
connect_timeout = 60
net_read_timeout = 120

[mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid " > /usr/local/mysql/etc/my.cnf


chmod 777 /usr/lib/systemd/system/mysqld.service


mkdir /var/lib//mysql

chmod 777 /var/lib//mysql

 

yum install -y perl-Module-Install


/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=/data/mysql/

echo '[Unit]
Description=mysqld
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
[Install]
WantedBy=multi-user.target' > /usr/lib/systemd/system/mysqld.service

chmod 777 /usr/lib/systemd/system/mysqld.service

ln -s /usr/local/mysql/bin/mysql /usr/bin

 

echo 'export PATH=$PATH:/usr/local/mysql/bin/' >>/etc/profile

programName=${0##*/}

source /etc/profile $programName


#systemctl daemon-reload

systemctl enable mysqld

systemctl restart mysqld.service

systemctl enable mysqld.service

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --reload

mysql -uroot -h 127.0.0.1 -A

#set password for root@localhost = password('zabbixpwd');

 

#mysqladmin -h 127.0.0.1 -u root password 'zabbixpwd'

flush privileges;

#grant all privileges on *.* to "user"@"%" identified by "password";

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%192.168.80.%' IDENTIFIED BY 'zabbixpwd' WITH GRANT OPTION;


flush privileges;

quit

exit

 

 

 

echo '<?php
$link=mysql_connect("192.168.80.52","root","zabbixpwd");
if(!$link){
echo "mysql_connect fail";
}else{
echo "mysql_connect success";
}
?>' >>/usr/local/nginx/html/test_mysql.php

 

else

echo "=========================安装mysql失败已经安装过mysql==========================="

fi

 根据51cto实践哥课程编写脚本,,,,本文版权归作者所有,欢迎转载,转载请注明链接,如果文章有写的不足的地方,或者是写得错误的地方,请你一定要指出,因为这样不光是对我写文章的一种促进,也是一份对后面看此文章的人的责任。谢谢

 一键安装lnmp - LY龙 - 博客园 (cnblogs.com)

标签:enable,--,local,一键,lnmp,usr,mysql,php,安装
From: https://www.cnblogs.com/lypro/p/lnmp_low_vertion.html

相关文章

  • 【解决】Github无法打开,导致无法下载Git安装包
    环境Windows11原因Git应用的安装程序在Github上,由于Github访问不稳定,导致无法下载。对策打开迅雷。将下载链接拷贝进去,利用迅雷的P2P技术,从其他网友处进行下载......
  • 一键安装wordpress
    #!/bin/bash nginx_souecepwd=/usr/local/nginx#源码安装路径cdnginx_configpwd=/usr/local/nginx/confsystemd_ExecStartpwd=/usr/local/nginx/sbin/nginxif[!-......
  • centos 7 安装python 3
    1.下载安装相关依赖,用来下载编译python3yum-yinstallzlib-develbzip2-developenssl-develncurses-develsqlite-develreadline-develtk-develgccmake2.安装epe......
  • 一键安装zhabix4.0.3
    #!/bin/bash nginx_souecepwd=/usr/local/nginx#源码安装路径cdnginx_configpwd=/usr/local/nginx/confsystemd_ExecStartpwd=/usr/local/nginx/sbin/nginxif[!-......
  • Python爬虫常用:谷歌浏览器驱动——Chromedriver 插件安装教程
    我们在做爬虫的时候经常要使用谷歌浏览器驱动,今天分享下这个Chromedriver插件的安装方法。第一步、打开谷歌浏览器打开设置面板第二步、查看当前谷歌浏览器版本号第三步、......
  • docker安装nacos集群
    1.临时启动dockerrun--namenacos-d-p8848:8848-p9848:9848-p9849:9849nacos/nacos-server:v2.1.12.创建配置文凭挂载目录mkdir-p/opt/docker/nacos/con......
  • maven的安装、仓库的种类和彼此关系
    maven的安装     maven仓库的种类和彼此的关系本地仓库:用来存储从远程仓库或中央仓库下载的插件和jar包,项目使用一些插件或jar包,优先从本地仓库查找默认本......
  • centos安装docker
    0.安装DockerDocker分为CE和EE两大版本。CE即社区版(免费,支持周期7个月),EE即企业版,强调安全,付费使用,支持周期24个月。DockerCE分为stabletest和nightly......
  • 我的Github-博客左上角可一键进入
    我的Github主页网址:https://github.com/BXF-Aurora168博客左上角可一键进入  github我很早就注册了,只是由于访问速度的问题一直没有使用。使用Steamcommunity30......
  • 如果个人pc上要装不同社区版本的pycharm,安装时需要注意的一点
    pycharm下载地址[包含了目前发行的所有版本]:https://www.jetbrains.com/pycharm/download/other.html选择指定的版本,点击     勾选uninstallsilently(sett......