centos7.4安装最新lnmp架构设置授权访问并搭建Discuz论坛

[[email protected] ~]# yum install -y \ 安装nginx所需要的库

pcre-devel \ //rewrite模块需要?pcre?库
zlib-devel //?gzip模块需要?zlib?库
[[email protected] ~]# useradd -M -s /sbin/nologin nginx 创建程序用户nginx
[[email protected] ~]# tar xf nginx-1.13.9.tar.gz -C /opt/ 解压
[[email protected] ~]# cd /opt/nginx-1.13.9/
[[email protected] nginx-1.13.9]# ./configure \
--prefix=/usr/local/nginx \ //指定安装路径
--user=nginx \ //指定运行用户
--group=nginx \ //指定运行组
--with-http_stub_status_module //添加日志统计模块

注:./configure报以下错误时:
Configure:error:You need a C++ compiler for C++ support
可以使用以下命令解决:yum install -y gcc gcc-c++
[[email protected] nginx-1.13.9]# make && make install

[[email protected] nginx-1.13.9]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ 软连接
[[email protected] nginx-1.13.9]# nginx -t //配置文件语法检查

[[email protected] nginx-1.13.9]# nginx //启动服务
[[email protected] nginx-1.13.9]# killall -1 nginx //安全重启
[[email protected] nginx-1.13.9]# killall -3 nginx //停止服务
启动nginx之后,浏览器中输入192.168.80.140可以验证是否安装成功:

[[email protected] nginx-1.13.9]# vi /etc/init.d/nginx //系统服务管理脚本
#!/bin/bash
#chkconfig: 35 99 20 //运行级别35,第99个开启,第20 个关闭
#description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx" //主路径程序
PIDF="/usr/local/nginx/logs/nginx.pid" //PID存放路径
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF) //根据PID终止Nginx进程
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF) //根据进程号重载配置
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1 //不正常退出,输入错误时退出
esac
exit 0

[[email protected] nginx-1.13.9]# chmod +x /etc/init.d/nginx //给予服务脚本执行权限
[[email protected] nginx-1.13.9]# chkconfig --add nginx //添加为系统服务
[[email protected] ~]# vi /usr/local/nginx/conf/nginx.conf
user nginx nginx; //把前面的注释符号去掉,运行用户,加组时,空格加组名
error_log logs/error.log info; //错误日志消息
events {
use epoll; //新增此行 默认使用select/poll,在events模块内指定epoll模型
worker_connections 1024; //表示每个工作进程允许1024个连接。
log_format main //定义日志格式 把前面的#号去掉
charset utf-8; //更改语言支持
location ~ /status { //配置统计模块
stub_status on;
access_log off;
} //在server 模块里的error_page 上面增加




[[email protected] ~]# service nginx restart
[[email protected] ~]# cat /usr/local/nginx/logs/access.log //查看连接数

在浏览器中输入http:192.168.80.140/status

//当前的活动连接数,已处理的连接数,成功的TCP握手次数,已处理的请求数.
以下配置nginx的授权认证功能
[[email protected] ~]# yum install -y httpd-tools
[[email protected] ~]# htpasswd -c /usr/local/nginx/passwd.db jack //生成用户认证文件
[[email protected] ~]# chmod 400 /usr/local/nginx/passwd.db //为了安全,更改权限和归属
[[email protected] ~]# chown nginx /usr/local/nginx/passwd.db
[[email protected] ~]# vi /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.html index.htm;
allow 192.168.80.0/24; //允许192.168.80.0网段连接
deny all; //拒绝所有
auth_basic "secret"; //添加认证配置
auth_basic_user_file /usr/local/nginx/passwd.db; //指定用户认证文件
}

[[email protected] ~]# nginx -t
[[email protected] ~]# service nginx restart
在浏览器中输入192.168.80.140进行验证:

输入我们创建的用户名和密码:

以下配置虚拟主机功能:
[[email protected] ~]# vi /usr/local/nginx/conf/nginx.conf
server { //基于域名的虚拟主机
listen 80;
server_name www.lq1.com;
charset utf-8;
access_log logs/lq1.access.log main;
location / {
root /var/www/lq1;
index index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
server {
listen 80;
server_name www.lq3.com;
charset utf-8;
access_log logs/lq3.access.log main;
location / {
root /var/www/lq3;
index index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

[[email protected] ~]# mkdir -p /var/www/lq1
[[email protected] ~]# mkdir /var/www/lq3
[[email protected] www]# cd lq1/
[[email protected] lq1]# vi index.html

[[email protected] lq1]# vi /var/www/lq3/index.html

[[email protected] www]# service nginx restart
真机验证时因为服务器没有搭建dns所以要去hosts文件做域名解析
C盘——windows——system32——drivers——etc——hosts //打开hosts路径

然后在浏览器中输入http://www.lq1.com和http://www.lq3.com,在断网情况下

安装MySQL步骤同lamp搭建过程一致,这里就不做解释了
命令如下:
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake

useradd -s /sbin/nologin mysql

tar xf 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_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 && make install

chown -R mysql.mysql /usr/local/mysql/ 也可mysql:mysql

vi /etc/my.cnf

[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
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
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 mysql:mysql /etc/my.cnf //更改归属,方便程序用户读取

echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH‘ >> /etc/profile
echo ‘export 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/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld
netstat -anpt | grep 3306

systemctl enable mysqld

mysqladmin -u root -p password "abc123" //给root账号设置密码

mysql -u root -p //进入数据库,进入后输入之前设置的密码

以下安装PHP
[[email protected] mysql]# yum -y install \ //安装依赖包
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

[[email protected] ~]# tar xjvf php-7.1.10.tar.bz2 -C /opt/
[[email protected] ~]# cd /opt/php-7.1.10/
[[email protected] php-7.1.10]# ./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-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo --enable-tokenizer --enable-zip --enable-fpm

[[email protected] php-7.1.10]# make && make install
[[email protected] php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[[email protected] php-7.1.10]# vi /usr/local/php/lib/php.ini
mysqli.default_socket = /usr/local/mysql/mysql.sock
date.timezone = Asia/Shanghai


[[email protected] php-7.1.10]# /usr/local/php/bin/php -m

配置及优化FPM模块: //nginx处理动态网页,需要php-fpm模块
[[email protected] php-7.1.10]# cd /usr/local/php/etc/
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf
[[email protected] etc]# cd /usr/local/php/etc/php-fpm.d/
[[email protected] php-fpm.d]# cp www.conf.default www.conf

[[email protected] etc]# vi php-fpm.conf

[[email protected] etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
[[email protected] etc]# netstat -anpt | grep 9000

[[email protected] etc]# ln -s /usr/local/php/bin/ /usr/local/bin/
[[email protected] etc]# ps aux | grep -c "php-fpm"

更新启动脚本
[[email protected] etc]# vi /etc/init.d/nginx
#!/bin/bash
#chkconfig: 35 99 20 //运行级别35,第99个开启,第20 个关闭
#description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/php/sbin/php-fpm"
PIDF_FPM="/usr/local/php/var/run/php-fpm.pid"
case "$1" in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF)
kill -s QUIT $(cat $PIDF_FPM)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0

[[email protected] lq]# vi /usr/local/nginx/conf/nginx.conf
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; //注意目录名称
include fastcgi_params;
}

[[email protected] lq]# nginx -t
[[email protected] etc]# cd /usr/local/nginx/html/
[[email protected] html]# vi index.php //编辑网页测试文件
<?php
phpinfo();
?>

在浏览器中输入http://192.168.80.140/index.php

[[email protected] lq]# mysql -u root -p
CREATE DATABASE bbs; //创建数据库bbs
GRANT all ON bbs. TO ‘bbsadm‘@‘%‘ IDENTIFIED BY ‘admin123‘; //给予bbsadm最大权限
GRANT all ON bbs.
TO ‘bbsadm‘@‘localhost‘ IDENTIFIED BY ‘admin123‘;
flush privileges; //刷新权限

[[email protected] lq]# vi /var/www/lq/index.php
<?php
$link=mysqli_connect(‘192.168.80.140‘,‘bbsadm‘,‘admin123‘);
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>

[[email protected] lq]# service nginx restart
在浏览器中输入http://192.168.80.140/index.php

以下安装Discuz论坛
[[email protected] ~]# yum install -y unzip
[[email protected] ~]# unzip Discuz_X3.4_SC_UTF8_0101.zip -d /tmp/
[[email protected] bbs]# cd /tmp/dir_SC_UTF8/
[[email protected] dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs
//放到nginx的网页根目录中正常生效
[[email protected] dir_SC_UTF8]# cd /usr/local/nginx/html/bbs
[[email protected] bbs]# chown -R root:nginx ./config/
[[email protected] bbs]# chown -R root:nginx ./data/
[[email protected] bbs]# chown -R root:nginx ./uc_client/
[[email protected] bbs]# chown -R root:nginx ./uc_server/
[[email protected] bbs]# chmod -R 777 ./config/
[[email protected] bbs]# chmod -R 777 ./data/
[[email protected] bbs]# chmod -R 777 ./uc_client/
[[email protected] bbs]# chmod -R 777 ./uc_server/
在浏览器中输入192.168.80.140/bbs/install/index.php




在浏览器中,输入192.168.80.140/bbs/index.php

原文地址:http://blog.51cto.com/13496696/2093060

时间: 2024-11-01 12:06:45

centos7.4安装最新lnmp架构设置授权访问并搭建Discuz论坛的相关文章

LNMP动态网站架构及web应用部署,搭建discuz论坛

1)部署Nginx 实验tar安装包可找本人拿记得点+关注,感谢亲们支持,评论拿包 systemctl stop firewalld iptables -F setenforce 0 1)安装支持软件 yum -y install pcre-devel zlib-devel openssl-devel 2)创建运行用户,组 useradd -M -s /sbin/nologin nginx 3)编译安装nglinx tar xf nglix-1.14.2.tar.gz -C /usr/src 4

LAMP架构搭建+Discuz论坛搭建【weber出品必属精品】

一.     本机简介: 本机系统: CentOS-6.4-x86_64 主机名:oracle.ywb IP地址:192.168.146.129 二.     在Linux环境下安装Apache步骤 首先将准备好的文件通过PSCP发送至Linux的/Root/test/soft目录下 在windows下按住Ctrl+R,打开运行,输入CMD进入DOS命令行.在dos命令行中使用pscp –scp  命令将要上传的文件上传至Linux中. 上传成功后.我们总共要安装四个文件.第一个我们首先解压:a

LNMP环境搭建(discuz论坛)

一.操作系统级环境及软件版本 操作系统:CentOS release 6.5 (Final)minimal 内核版本:2.6.32-431.el6.x86_64 MySQL版本:MySQL-5.6.28 nginx版本:nginx-1.8.1 php版本:php-5.6.19 二.安装MySQL-5.6.28 获取地址:http://mirrors.sohu.com/mysql/自行选择想要的版本 mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz这个版本是官方编

采用lamp架构搭建discuz论坛

lamp简介 LAMP指的Linux(操作系统).ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web 服务器. Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件 下面给大家讲解一个lamp结构论坛的案例 1.安装所需软件包 [[email protected] ~]# yum install httpd mysq

(转) Linux(Centos7)yum安装最新mysql

原文:http://blog.csdn.net/gebitan505/article/details/54613549 环境 CentOS 7.1 (64-bit system) MySQL 5.6.24 CentOS 安装 参考:http://www.waylau.com/centos-7-installation-and-configuration/ 依赖 MySQL 依赖 libaio,所以先要安装 libaio yum search libaio # 检索相关信息 yum install

Linux(Centos7)yum安装最新redis

1.启用EPEL仓库## RHEL/CentOS 7 64-Bit ### wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm# rpm -ivh epel-release-7-5.noarch.rpm 要验证EPEL仓库是否建立成功,可以执行:# yum repolist 2.通过Yum安装Redis# yum -y update# yum install redis 如果redis还

LNMP架构搭建Discuz论坛(实战!)

什么是LNMP架构 LNMP平台就是Linux.Ngnix. MySQL. PHP的组合架构,需要Linux服务器.MySQL数据库.PHP解析环境 MySQL安装配置 为了与Nginx.PHP环境保持一致,此处选择采用源代码编译的方式安装MySQL组件 MySQL部署的方法 编译安装MySQL 优化调整 初始化数据库 启动mysq|服务并设置root数据库账号的密码 PHP解析环境的安装 配置网页动静分离,解析PHP,有两种方法可以选择 使用PHP的FPM模块 将访问PHP页面的Web请求转交

利用lamp架构搭建Discuz论坛,并实现对数据库的高可用

lamp架构=LAMP指的Linux(操作系统).Apache(HTTP 服务器),MySQL(数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web 服务器. #############源码安装php########### tar jxf php-5.6.20.tar.bz2 cd php-5.6.20 解决依赖性: yum install freetype-devel libmcrypt-2.5.8-9.el6.x86_64.rpm net-snmp-d

基于LNMP搭建Discuz!论坛,并配置nginx,php

前面我们已经搭建好了LNMP环境:http://1015489314.blog.51cto.com/8637744/1688048 下面我们基于LNMP来搭建一个Discuz!论坛 一.安装Discuz! 1.新建目录来存放网页等 [[email protected] ~]# mkdir /data/www[[email protected] ~]# cd /data/www   [[email protected] www]# wget http://download.comsenz.com/