systemctl stop firewalld
systemctl disable firewalld
setenforce 0
nginx-1.12.0.tar.gz
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
useradd -M -s /sbin/nologin nginx
cd /opt
tar zxvf nginx-1.12.0.tar.gz -C /opt/
cd nginx-1.12.0/
./configure
–prefix=/usr/local/nginx
–user=nginx
–group=nginx
–with-http_stub_status_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
#!/bin/bash
#chkconfig: - 99 20
#description:Nginx Service Control Script
COM=“/usr/local/nginx/sbin/nginx”
PID=“/usr/local/nginx/logs/nginx.pid”
case “$1” in
start)
$COM
;;
stop)
kill -s QUIT $(cat $PID)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PID)
;;
*)
echo “Usage: $0 {start|stop|restart|reload}”
exit 1
esac
exit 0
chmod +x /etc/init.d/nginx
chkconfig --add nginx
systemctl stop nginx
systemctl start nginx
yum -y install ncurses ncurses-devel bison cmake gcc gcc-c++
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/
useradd -M -s /sbin/nologin mysql
Mysql数据库使用cmake编译
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
安装耗时长,耐心等待
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
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
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
加载mysql并启动服务,设置开机自启动
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
mysqladmin -u root -p password “123456”
1.安装依赖包
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
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
make && make install
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
5.1调整主配置
cp /opt/php-7.1.24/php.ini-development /usr/local/php/lib/php.ini
编辑:vim /usr/local/php/lib/php.in
1170行 mysqli.default_socket = /usr/local/mysql/mysql.sock
939行设置时区 date.timezone = Asia/Shanghai
php -m查看模块配置
5.2调整进程服务配置
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
17行取消注释“;”
5.3调整扩展配置文件
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
查看是否启动
netstat -anpt | grep 9000
cd /opt/php-7.1.24/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/php-fpm.service
systemctl restart php-fpm.service
vim /usr/local/nginx/conf/nginx.conf
修改65-71行
重启nginx服务
systemctl restart nginx
编写网页测试文件
vim /usr/local/nginx/html/index.php
添加如下内容
unzip Discuz_X3.4_SC_UTF8.zip -d /opt/dis
cd /opt/dis/dir_SC_UTF8/
cp -r upload/ /usr/local/nginx/html/bbs/
cd /usr/local/nginx/html/bbs/
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
mysql -u root -p123456
CREATE DATABASE bbs;
GRANT all ON bbs.* TO ‘bbsuser’@‘%’ IDENTIFIED BY ‘admin123’;
GRANT all ON bbs.* TO ‘bbsuser’@‘localhost’ IDENTIFIED BY ‘admin123’;
flush privileges;
#!/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 <
请将安装包放入/opt目录下
1.安装nginx服务
2.安装mysql
3.安装php
4.一键安装LNMP架构
EOF
read -p “请输入你的选择:” choice
##########################编译安装NGINX服务#######################################
nginx (){
#安装依赖包
yum -y install pcre-devel zlib-devel gcc gcc-c++ make >>/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 <
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
#更改执行权限
chmod 754 /lib/systemd/system/nginx.service
#启动服务并开机自启动
systemctl start nginx.service
systemctl enable 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 <
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
EOF
#更改安装目录属主属组为mysql
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf
#添加环境变量
#echo ‘export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH’ >> /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