千家信息网

LNAMP环境下如何搭建discuz论坛并实现mysql主从部署

发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,本文主要给大家介绍LNAMP环境下如何搭建discuz论坛并实现mysql主从部署,文章内容都是笔者用心摘选和编辑的,具有一定的针对性,对大家的参考意义还是比较大的,下面跟笔者一起了解下LNAMP环境
千家信息网最后更新 2026年10月31日LNAMP环境下如何搭建discuz论坛并实现mysql主从部署

本文主要给大家介绍LNAMP环境下如何搭建discuz论坛并实现mysql主从部署,文章内容都是笔者用心摘选和编辑的,具有一定的针对性,对大家的参考意义还是比较大的,下面跟笔者一起了解下LNAMP环境下如何搭建discuz论坛并实现mysql主从部署吧。

实验环境:

1、VMware Workstation 10

2、真机IP:192.168.0.113

2、设备A:nginx+apache+php+discuz+mysql,IP地址:192.168.145.133,host:master1

3、设备B:

mysql,IP地址 192.168.145.134,host:master2

4、Linux发行版:Centos 6.5 x86_64;

5、nginx:nginx-1.8.0.tar.gz

6、apache:httpd-2.2.27.tar.bz2

7、php:php-5.6.12.tar.bz2

8、mysql:mysql-5.6.32-linux-glibc2.5-x86_64.tar.gz(B设备master)

mysql-5.1.73-linux-x86_64-glibc23.tar.gz(A设备slave)

9、discuz:Discuz_X3.2_SC_UTF8.zip

实验步骤:

1、在B设备上安装mysql数据库


   tar zxvf /usr/local/src/mysql-5.6.32-linux-glibc2.5-x86_64.tar.gz       mv mysql-5.6.32-linux-glibc2.5-x86_64 /usr/local/mysql       useradd -s /sbin/nologin mysql       cd /usr/local/mysql       mkdir -p /data/mysql       chown -R mysql:mysql /data/mysql       ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql #数据库初始化      cp support-files/my-large.cnf /etc/my.cnf   #拷贝数据库配置文件      cp support-files/mysql.server /etc/init.d/mysqld   #拷贝数据库启动脚本      chmod 755 /etc/init.d/mysqld       vim /etc/init.d/mysqld   #修改datadir=/usr/local/mysql       chkconfig --add mysqld       chkconfig mysqld on       service mysqld start      mysql -h227.0.0.1 -uroot       #登陆数据库      >create database discuz;   #创建discuz库      >grant all on discuz.* to 'xaioyuan'@'192.168.145.133' identified by '123456';      #这条语句是授权ip为192.168.145.133的xiaoyuan用户可以访问discuz库,访问密码为123456      >quit   #退出数据库


2、在设备A上安装apache


tar jxvf /usr/local/src/httpd-2.2.27.tar.bz2cd /usr/loca/src/httpd-2.2.27./configure \--prefix=/usr/local/apache2 \--with-included-apr \--enable-so \--enable-deflate=shared \--enable-expires=shared \--enable-rewrite=sharedmake & make installcp /usr/local/apache2/bin/apachectl /etc/init.d/httpd   #拷贝apache的启动脚本vim /etc/init.d/httpd   在第一行#!/bin/sh下增加两行文字# chkconfig: 35 70 30# description: Apache保存退出chkconfig --level 35 httpd on


3、在设备A上安装php


tar zxf /usr/local/src/php-5.6.12.tar.gz cd php-5.6.12 ./configure \--prefix=/usr/local/php \--with-apxs2=/usr/local/apache2/bin/apxs \--with-config-file-path=/usr/local/php/etc \--with-mysql=mysqlnd \--with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \--with-libxml-dir \--with-gd \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--with-iconv-dir \--with-zlib-dir \--with-bz2 \--with-openssl \--with-mcrypt \--enable-soap \--enable-gd-native-ttf \--enable-mbstring \--enable-sockets \--enable-exif \--disable-ipv6 #在编译php的时候如果遇到反复报错,则应该观察编译选项是否在不该出现空格的时候出现了空格,如:"\--with-mysql=mysqlnd \--with-mysqli=mysqlnd"写成了"\--with-mysql=mysqlnd \  --with-mysqli=mysqlnd"。make && make installcp /usr/local/src/php-5.6.12/php.ini-production /usr/local/php/etc/php.ini


4、配置apache与php关联


vim /usr/local/apache2/conf/httpd.conf 找到:AddType application/x-gzip .gz .tgz在其下面添加:AddType application/x-httpd-php .php找到:DirectoryIndex index.html/IfModule>将其改为:DirectoryIndex index.html index.htm index.php找到:#ServerName www.example.com:80 修改为:ServerName localhost:88找到:listen:80 修改为:listen:88找到:    Options FollowSymLinks    AllowOverride None    Order deny,allow    Deny from all改为:    Options FollowSymLinks    AllowOverride None    Order deny,allow    Allow from all找到:#Include conf/extra/httpd-vhosts.conf 把最前面的#去掉查看是否存在modules/libphp5.sovim /usr/local/apache2/conf/extra/httpd-vhosts.conf    #打开apache虚拟主机配置文件在最后添加:        DocumentRoot "/date/discuz/"        ServerName bbs.xiaoyua.com        ErrorLog "logs/bbs.xiaoyuan.com-error_log"        CustomLog "logs/bbs.xiaoyuan.com-access_log" commonservice httpd -t (检查错误)service httpd graceful(加载配置)查看httpd的运行情况netstat -lnp | grep httpd


5、在设备A上安装nginx


tar zxvf /usr/local/src/nginx-1.8.0.tar.gz cd nginx-1.8.0./configure   --prefix=/usr/local/nginx   --with-pcre make  &  make instalvim /etc/init.d/nginx    #编写启动脚本:#!/bin/bash# chkconfig: - 30 21# description: http service.# Source Function Library. /etc/init.d/functions# Nginx SettingsNGINX_SBIN="/usr/local/nginx/sbin/nginx"NGINX_CONF="/usr/local/nginx/conf/nginx.conf"NGINX_PID="/usr/local/nginx/logs/nginx.pid"RETVAL=0prog="Nginx"start() {                echo -n $"Starting $prog: "                mkdir -p /dev/shm/nginx_temp                daemon $NGINX_SBIN -c $NGINX_CONF                RETVAL=$?                echo                return $RETVAL}stop() {                echo -n $"Stopping $prog: "                killproc -p $NGINX_PID $NGINX_SBIN -TERM                rm -rf /dev/shm/nginx_temp                RETVAL=$?                echo                return $RETVAL}reload(){                echo -n $"Reloading $prog: "                killproc -p $NGINX_PID $NGINX_SBIN -HUP                RETVAL=$?                echo                return $RETVAL}restart(){                stop                start}configtest(){        $NGINX_SBIN -c $NGINX_CONF -t        return 0}case "$1" in  start)        start        ;;  stop)        stop        ;;  reload)        reload        ;;  restart)        restart        ;;  configtest)        configtest        ;;  *)        echo $"Usage: $0 {start|stop|reload|restart|configtest}"                RETVAL=1esacexit $RETVAL将nginx服务启动:chmod a+x /etc/init.d/nginxchkconfig --add nginxchkconfig nginx on/usr/local/nginx/conf/nginx.conf  #编写nginx的配置文件:user nobody nobody;worker_processes 2;error_log /usr/local/nginx/logs/nginx_error.log crit;pid /usr/local/nginx/logs/nginx.pid;worker_rlimit_nofile 51200;events{    use epoll;    worker_connections 6000;}http{    include mime.types;        default_type application/octet-stream;        server_names_hash_bucket_size 3526;        server_names_hash_max_size 4096;        log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'    '$host "$request_uri" $status'    '"$http_referer" "$http_user_agent"';        sendfile on;        tcp_nopush on;        keepalive_timeout 30;        client_header_timeout 3m;        client_body_timeout 3m;        send_timeout 3m;        connection_pool_size 256;        client_header_buffer_size 1k;        large_client_header_buffers 8 4k;        request_pool_size 4k;        output_buffers 4 32k;        postpone_output 1460;        client_max_body_size 10m;        client_body_buffer_size 256k;        client_body_temp_path /usr/local/nginx/client_body_temp;        proxy_temp_path /usr/local/nginx/proxy_temp;        fastcgi_temp_path /usr/local/nginx/fastcgi_temp;        fastcgi_intercept_errors on;        tcp_nodelay on;        gzip on;        gzip_min_length 1k;        gzip_buffers 4 8k;        gzip_comp_level 5;        gzip_http_version 1.1;        gzip_types text/plain application/x-javascript text/css text/htm application/xml;        include /usr/local/nginx/conf/vhosts/*.conf;                    mkdir -p /usr/local/nginx/conf/vhosts    #创建nginx虚拟主机        vim /usr/local/nginx/conf/vhosts/bbs.conf   ##配置nginx虚拟主机(discuz)        server{    listen 80;    server_name bbs.chinaops.com;    index index.html index.htm index.php;    root /date/bbs;#限制user_agent    if ($http_user_agent ~            'bingbot/2.0|MJ12bot/v1.4.2|Spider/3.0|YoudaoBot|    Tomato|Gecko/20100315'){            return 403;    }            location ~ admin.php {        allow 192.168.0.113; ##只允许真机访问admin.php        deny all;        proxy_pass   http://127.0.0.1:88;        proxy_set_header Host   $host;    }    #代理apache    location ~ \.php$ {         proxy_pass   http://127.0.0.1:88;         proxy_set_header Host   $host;         proxy_set_header X-Real-IP      $remote_addr;         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    }    #设置静态缓存    location ~ .*\.(js|css)?$    {          expires      24h;          access_log off;    }    #设置防盗链    location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$ {         expires 7d;         valid_referers none blocked server_names  *.baidu.com\         *.google.com *.google.cn *.soso.com ;         if ($invalid_referer) {              return 403;              #rewrite ^/ http://www.example.com/nophoto.gif;         }         access_log off;    }    rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;    rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;    rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;    rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;    rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;    rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;    access_log /home/logs/discuz.log combined_realip;}


5、在设备A上安装discuz


mkdir /data/discuzcd /data/discuzwget unzip Discuz_X3.2_SC_UTF8.zip mv upload/* .在浏览器中输入:bbs.xiaoyuan.com/installcd /data/bbschown -R daemon.daemon config/ data/ uc_client/data/ uc_server/data/按照提示的安装步骤安装即可。


6、搭建mysql主从


# B机器的mysql为master,A机器上的mysql为slave配置master: vim /usr/local/mysql/my.cnf   #修改或添加:  server-id=1  log-bin=mysql-bin    两个可选参数(2选1):  binlog-do-db=discuz #需要同步的库  binlog-ignore-db=db1,db2 #忽略不同步的库  修改配置文件后,重启mysql  mysql -h227.0.0.1 -uroot   #登陆mysql数据库  >grant replication slave on *.* to 'repl'@'192.168.145.133' identified by '123123';   # 授权slave可以访问master  >flush tables with read lock;   >show master status;        # 会用到前两列的内容 安装(和master步骤相同)和配置slave:  vim /etc/my.cnf     #修改或增加   server-id = 2    #这个数值不能和主一样    两个可选参数(2选1):   replicate-do-db=discuz  #需要同步的库   replicate-ignore-db=db1,db2  #忽略不同步的库    mysql -h227.0.0.1 -uroot   #登陆mysql数据库    slave stop;     change master to master_host='192.168.145.134', master_port=3306, master_user='repl',   master_password='123123', master_log_file='mysql-bin.000006', master_log_pos=474952;     slave start;    主上: mysql -uroot -S /tmp/mysql2.sock -p123456 -e "unlock tables"     从上查看从的状态:show slave status\G    当看到     Slave_IO_Running: Yes                          Slave_SQL_Running: Yes                          Replicate_Do_DB: discuz               则表示mysql主从搭建成功。更进一步的验证方法是在master的discuz库里创建一个表,然后去slave    查看此表是否出现在slave的discuz库。

看完以上关于LNAMP环境下如何搭建discuz论坛并实现mysql主从部署,很多读者朋友肯定多少有一定的了解,如需获取更多的行业知识信息 ,可以持续关注我们的行业资讯栏目的。

设备 配置 数据 数据库 主从 环境 文件 同步 论坛 主机 拷贝 步骤 脚本 虚拟主机 登陆 两个 内容 参数 地址 时候 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网科技工作委员会 互联网科技工作委员会毛军 互联网扶贫科技 中资互联网科技 金融科技 互联网金融 上海挚品互联网科技 科技大学互联网专业好不好 深圳互联网科技怎么样 汉立互联网科技有限公司联系电话 宁夏众和广鑫互联网科技有限公司 栖莱科技互联网股份有限公司 互联网和黑科技的看法 昊天互联网科技有限公司 华夏互联网科技业 小米互联网科技园入驻 万物互联网智能科技 互联网公司属于科技吗 互联网企业和网络科技有限公司 每日互联网科技新闻 武汉亿视互联网科技有限公司 科技赋能下的互联网金融 互联网科技保险 互联网 科技 互联网金融 金融科技 互联网和黑科技的看法 南平创想时代互联网科技有限公司 深圳市优智互联网科技有限公司 北京互联网科技类企业分布 唐山双旺合互联网科技产业园 六子台科技互联网展会
0