执行脚本前,要把需要的包上传进去
软件包可以从对应官网找
#! /bin/bash
echo "创作时间: 2024年4月1日"
echo "作者: SKY-慕雪"
echo "一键部署LNMP"
sleep 3
echo ">>>>>!!!注意!!!<<<<<"
echo "请确保全部的软件包都放在当前目录下!!!"
echo "如果还没放入软件包请按ctrl+C终止!"
sleep 5
echo ">>>>>开始执行<<<<<"
sleep 2
nginx=nginx-1.12.2
libmcrypt=libmcrypt-2.5.8
php=php-5.6.27
wordpress=wordpress-4.7.3-zh_CN.zip
echo ">>>>>关闭防火墙-换源-时间同步<<<<<"
sleep 3
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
yum install -y wget net-tools unzip vim
wget -O /etc/yum.repos.d/aliyun.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
date
yum install -y ntp
systemctl start ntpd && systemctl enable ntpd
sleep 8
date
echo ">>>>>安装部署mariadb服务<<<<<"
sleep 3
yum install -y mariadb mariadb-server
systemctl start mariadb && systemctl enable mariadb
mysql_secure_installation << EOF
y
000000
000000
y
n
y
y
EOF
sed -i 's/\[mysqld\]/\[mysqld\]\nlog_bin=mysql-bin\nbinlog_ignore_db=mysql\nserver_id=10/' /etc/my.cnf
systemctl restart mariadb
mysql -uroot -p000000 << EOF
grant all privileges on *.* to root@'%' identified by "000000";
grant replication slave on *.* to 'user'@'%' identified by "000000";
create database wordpress;
exit
EOF
echo ">>>>>部署Nginx服务<<<<<"
sleep 3
yum install -y gcc gcc-c++ openssl-devel zlib-devel zlib pcre-devel
groupadd -g 1001 nginx
useradd -u 900 nginx -g nginx -s /sbin/nologin
tar -zxvf ${nginx}.tar.gz
cd ${nginx}/
./configure --prefix=/usr/local/nginx --with-http_dav_module \
--with-http_stub_status_module --with-http_addition_module \
--with-http_sub_module --with-http_flv_module --with-http_mp4_module \
--with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
nginx -t
nginx
netstat -ntpl
sleep 3
echo ">>>>>部署PHP服务<<<<<"
sleep 3
cd
yum install -y gcc gcc-c++ libxml2-devel libcurl-devel openssl-devel bzip2-devel
tar -zxvf ${libmcrypt}.tar.gz
cd ${libmcrypt}/
./configure --prefix=/usr/local/libmcrypt && make && make install
cd
tar -zxvf ${php}.tar.gz
cd ${php}/
./configure --prefix=/usr/local/php5.6 --with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm \
--enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir \
--with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash \
--with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
make && make install
groupadd -g 1001 nginx
useradd -u 900 nginx -g nginx -s /sbin/nologin
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
###php5.6根据软件包版本定义###
cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
sed -i "s/user = nobody/user = nginx/" /usr/local/php5.6/etc/php-fpm.conf
sed -i "s/group = nobody/group = nginx/" /usr/local/php5.6/etc/php-fpm.conf
sed -i "s/listen = 127.0.0.1:9000/listen = $(hostname -I | tr -d ' '):9000/" /usr/local/php5.6/etc/php-fpm.conf
sed -i "s/pm.max_children = 5/pm.max_children = 50/" /usr/local/php5.6/etc/php-fpm.conf
sed -i "s/pm.start_servers = 2/pm.start_servers = 5/" /usr/local/php5.6/etc/php-fpm.conf
sed -i "s/pm.min_spare_servers = 1/pm.min_spare_servers = 5/" /usr/local/php5.6/etc/php-fpm.conf
sed -i "s/pm.max_spare_servers = 3/pm.max_spare_servers = 35/" /usr/local/php5.6/etc/php-fpm.conf
service php-fpm start
netstat -ntpl
sleep 3
cat > /usr/local/nginx/conf/nginx.conf << EOF
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /www;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root /www;
fastcgi_pass 127.0.0.1:9000; #更改为当前主机的IP地址:9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
}
EOF
sed -i "s/fastcgi_pass 127.0.0.1:9000;/fastcgi_pass $(hostname -I | tr -d ' '):9000;/" /usr/local/nginx/conf/nginx.conf
sed -i '/fastcgi_param SCRIPT_NAME $fastcgi_script_name;/a\fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;' /usr/local/nginx/conf/fastcgi_params
mkdir /www
chown nginx:nginx /www/
cd
unzip ${wordpress}
mv wordpress/* /www/
cp /www/wp-config-sample.php /www/wp-config.php
sed -i "s/define('DB_NAME', 'database_name_here');/define('DB_NAME', 'wordpress');/" /www/wp-config.php
sed -i "s/define('DB_USER', 'username_here');/define('DB_USER', 'root');/" /www/wp-config.php
sed -i "s/define('DB_PASSWORD', 'password_here');/define('DB_PASSWORD', '000000');/" /www/wp-config.php
sed -i "s/define('DB_HOST', 'localhost');/define('DB_HOST', '$(hostname -I | tr -d ' ')');/" /www/wp-config.php
nginx -s reload
echo ">>>>>部署成功<<<<<"
echo "输入当前主机的IP地址:9000进行访问"