关闭防火墙和增强机制,将软件包防盗opt目录下
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
yum install -y pcre-devel zlib-devel gcc gcc-c++ make
useradd -M -s /sbin/nologin nginx
tar zxf nginx-1.20.2.tar.gz
cd nginx-1.20.2/
./configure \
--prefix=/usr/local/nginx \ #指定nginx的安装路径
--user=nginx \ #指定用户名
--group=nginx \ #指定组名
--with-http_stub_status_module #启用 http_stub_status_module 模块以支持状态统计
make -j2 && make install
制作一个软链接;让系统识别nginx的操作命令
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
vim /lib/systemd/system/nginx.service
[Unit] #服务说明
Description=nginx #描述服务
After #依赖,当依赖的服务启动之后再启动自定义的服务
[Service] #服务运行参数设置
Type=forking #是后台运行的形式,使用此启动类型应同时指定
PIDFile= #服务的主进程
ExecStart=/usr/local/nginx/sbin/nginx #为服务的具体运行命令-启动
ExecReload=/bin/kill -s HUP $MAINPID #重载命令
ExecStop=/bin/kill -s QUIT $MAINPID #停止命令
PrivateTmp=ture #表示给服务分配独立的临时空间
[Install] #服务安装的相关设置,可设置为多用户
WantedBy=multi-user.target
二、编译安装MySQL服务
yum install -y gcc gcc-c++ ncures ncures-devel bison cmake
useradd -M -s /sbin/nologin mysql
在这里插入图片描述
tar zxf mysql-boost-5.7.20.tar.gz
cd /mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
make -j2 && make install
vim /etc/my.cnf
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES'
chown -R mysql:mysql /usr/local/mysql
chown mysql:mysql /etc/my.cnf
ll /usr/local/mysql/
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
source /etc/profile
cd /usr/local/mysql/bin/
./mysqld \
> --initialize-insecure \ 生成初始化密码为空
> --user=mysql \ 指定管理用户
> --basedir=/usr/local/mysql \ 指定数据库安装路径
> --datadir=/usr/local/mysql/data 指定数据库文件存储路径
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ #用于systemctl服务管理
systemctl daemon-reload #刷新识别
systemctl start mysqld.service #开启服务
systemctl enable mysqld #开机自启动
netstat -anpt | grep 3306 #查看端口
mysqladmin -u root -p password "123456"
#给root账号设置密码为123456,提示输入的是原始密码(为空)
mysql -u root -p
grant all privileges on *.* to 'root'@'%' identified by 'abc123';
#授予root用户可以在所有终端远程登录,使用的密码是abc123,并对所有数据库和所有表有操作权限
show databases; #查看当前已有的数据库
yum install -y \
> gd \
> libjpeg libjpeg-devel \
> libjpng libpng-devel \
> freetype freetype-devel \
> libxml2 libxml2-devel \
> zlib zlib-devel \
> curl curl-devel \
> openssl openssl-devel
cd /opt
tar zxvf php-7.1.24.tar.gz
cd /opt/php-7.1.24/
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
make -j2 && make install
cp /opt/php-7.1.24/php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
--1170行--修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
--939行--取消注释,修改
date.timezone = Asia/Shanghai
ln -s /usr/local/php/bin/* /usr/local/bin/
php -m #查看PHP 加载了哪些模块
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
17行 pid = run/php-fpm.pid
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
ln -s /usr/local/php/sbin/* /usr/local/sbin
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
netstat -anpt | grep 9000
vim /usr/local/nginx/conf/nginx.conf
--65行--取消注释,修改
65c location ~ \.php$ {'
66c root html;'
67c fastcgi_pass 127.0.0.1:9000;'
68c fastcgi_index index.php;'
69c fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;'
70c include fastcgi_params;'
71c }'
systemctl restart nginx.service
echo '' > /usr/local/nginx/html/index.php
mysql -u root -p
mysql> CREATE DATABASE bbs;
#把bbs数据库里面所有表的权限授予给bbsuser,并设置密码
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY '123456';
#刷新数据库
mysql>flush privileges;
unzip Discuz_X3.4_SC_UTF8.zip -d /opt/dis
cd /opt/dis/dir_SC_UTF8/
cp -r upload/ /usr/local/nginx/html/bbs/ #将论坛程序拷贝到nginx/html下
#切换论坛目录
#更改论坛目录属主(httpd安装若改配置文件为apache,则下方命令将daemon改为apache,并创建apache用户)
cd /usr/local/nginx/html/bbs/
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
论坛安装页面为:192.168.48.11/bbs/install/index.php
网页访问地址为:192.168.48.11/bbs/index.php
#!/bin/bash
#编译安装LNMP架构
#关闭防火墙和selinux
systemctl stop firewalld >>/dev/null
systemctl disable firewalld >>/dev/null
sed -i 's/SELINUX=enable/SELINUX=disable/' /etc/selinux/config
cat <>/dev/null
#创建管理账户
useradd -M -s /sbin/nologin nginx
#切换到安装包目录,并解压
cd /opt
tar -xf nginx-1.20.2.tar.gz
#切换到解压目录
cd nginx-1.20.2/
#编译安装
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module 2>>/opt/nginx_error.txt
sleep 1
make 2>>/opt/nginx_error.txt
make install 2>>/opt/nginx_error.txt
#创建软连接
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
#添加nginx到系统服务
cat > /lib/systemd/system/nginx.service <> /dev/null
netstat -antp|grep nginx >> /dev/null
if [ $? -eq 0 ];then
echo "nginx服务安装完成"
else
echo "服务安装失败,请检查"
fi
}
############################编译安装MYSQL数据库###################################
mysql (){
#安装依赖包
yum -y install ncurses ncurses-devel bison cmake gcc gcc-c++
#创建mysql用户
useradd -M -s /sbin/nologin mysql
#解压安装包
cd /opt
tar -xf mysql-5.7.17.tar.gz
tar -xf boost_1_59_0.tar.gz -C /usr/local/
mv /usr/local/boost_1_59_0 /usr/local/boost
#切换到解压目录
cd mysql-5.7.17/
#编译安装
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost \
-DWITH_SYSTEMD=1
make -j3 && make install
#修改配置文件
cat > /etc/my.cnf <> /etc/profile
#source /etc/profile
#创建软连接
ln -s /usr/local/mysql/bin/* /usr/local/bin
#初始化数据库
cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
#添加MYSQL到系统服务管理
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
if [ $? -eq 0 ];then
echo "MYSQL安装完成"
else
echo "服务安装异常,请检查"
fi
systemctl enable mysqld.service
}
php (){
#编译安装PHP
#安装依赖包
yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
#切换目录,并解压安装包
cd /opt
tar -xf php-7.1.24.tar.gz
cd php-7.1.24/
#编译安装
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
#根据实际配置选择cpu核数
make -j3 && make install
#创建服务软连接
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
#修改主配置文件
cp /opt/php-7.1.24/php.ini-development /usr/local/php/lib/php.ini
#添加数据库接口地址
sed -i '1170c mysqli.default_socket = /usr/local/mysql/mysql.sock' /usr/local/php/lib/php.ini
#更改时区
sed -i '939c date.timezone = Asia/Shanghai' /usr/local/php/lib/php.ini
#调整进程服务配置
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
#取消17行注释
sed -i '17s/;/ /g' php-fpm.conf
#调整扩展配置文件
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
#将服务加入系统服务
cd /opt/php-7.1.24/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/php-fpm.service
systemctl start php-fpm.service
#检查服务是否安装成功
netstat -anpt | grep 9000 >> /dev/null
if [ $? -eq 0 ];then
echo "服务安装成功"
else
echo "服务安装失败,请检查"
fi
}
##################配置NGINX支持PHP###################################
conf (){
#配置Nginx,使其支持PHP
cd /usr/local/nginx/conf/
#取消61-71行注释
sed -i '65,71s/#/ /g' nginx.conf
#修改69行,将/scripts 修改为nginx的工作目录
sed -i '69s/\/scripts/\/usr\/local\/nginx\/html/g' nginx.conf
echo "
" >> /usr/local/nginx/html/index.php
#重启nginx服务
systemctl restart nginx.service
}
################调用函数###################################
case $choice in
1)
nginx
;;
2)
mysql
;;
3)
php
;;
4)
nginx
sleep 2
mysql
sleep 2
php
sleep 2
conf
;;
*)
echo "请输入正确选项"
esac
通过上述实验,编译安装LNMP架构,可以了解LNMP的数据流向,为大家准备了一键部署LNMP脚本
if [ $? -eq 0 ];then
echo “服务安装成功”
else
echo “服务安装失败,请检查”
fi
}
##################配置NGINX支持PHP###################################
conf (){
#配置Nginx,使其支持PHP
cd /usr/local/nginx/conf/
#取消61-71行注释
sed -i ‘65,71s/#/ /g’ nginx.conf
#修改69行,将/scripts 修改为nginx的工作目录
sed -i ‘69s//scripts//usr/local/nginx/html/g’ nginx.conf
echo "
" >> /usr/local/nginx/html/index.php
#重启nginx服务
systemctl restart nginx.service
}
################调用函数###################################
case $choice in
1)
nginx
;;
2)
mysql
;;
3)
php
;;
4)
nginx
sleep 2
mysql
sleep 2
php
sleep 2
conf
;;
*)
echo “请输入正确选项”
esac
### 六、总结
通过上述实验,编译安装LNMP架构,可以了解LNMP的数据流向,为大家准备了一键部署LNMP脚本