LNAMP環(huán)境下如何搭建discuz論壇并實現(xiàn)mysql主從部署-創(chuàng)新互聯(lián)

本文主要給大家介紹LNAMP環(huán)境下如何搭建discuz論壇并實現(xiàn)mysql主從部署,文章內(nèi)容都是筆者用心摘選和編輯的,具有一定的針對性,對大家的參考意義還是比較大的,下面跟筆者一起了解下LNAMP環(huán)境下如何搭建discuz論壇并實現(xiàn)mysql主從部署吧。

在新都等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供做網(wǎng)站、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作按需定制制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都營銷網(wǎng)站建設(shè),成都外貿(mào)網(wǎng)站建設(shè)公司,新都網(wǎng)站建設(shè)費用合理。

實驗環(huán)境:

1、VMware Workstation 10

2、真機(jī)IP:192.168.0.113

2、設(shè)備A:nginx+apache+php+discuz+mysql,IP地址:192.168.145.133,host:master1

3、設(shè)備B:

mysql,IP地址 192.168.145.134,host:master2

4、Linux發(fā)行版: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設(shè)備master)

  mysql-5.1.73-linux-x86_64-glibc23.tar.gz(A設(shè)備slave)

9、discuz:Discuz_X3.2_SC_UTF8.zip

LNAMP環(huán)境下如何搭建discuz論壇并實現(xiàn)mysql主從部署

實驗步驟:

1、在B設(shè)備上安裝mysql數(shù)據(jù)庫

   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 #數(shù)據(jù)庫初始化        cp support-files/my-large.cnf /etc/my.cnf   #拷貝數(shù)據(jù)庫配置文件        cp support-files/mysql.server /etc/init.d/mysqld   #拷貝數(shù)據(jù)庫啟動腳本        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       #登陸數(shù)據(jù)庫        >create database discuz;   #創(chuàng)建discuz庫        >grant all on discuz.* to 'xaioyuan'@'192.168.145.133' identified by '123456';        #這條語句是授權(quán)ip為192.168.145.133的xiaoyuan用戶可以訪問discuz庫,訪問密碼為123456        >quit   #退出數(shù)據(jù)庫

2、在設(shè)備A上安裝apache

tar jxvf /usr/local/src/httpd-2.2.27.tar.bz2 cd /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=shared make & make install cp /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、在設(shè)備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的時候如果遇到反復(fù)報錯,則應(yīng)該觀察編譯選項是否在不該出現(xiàn)空格的時候出現(xiàn)了空格,如: “\--with-mysql=mysqlnd \--with-mysqli=mysqlnd”寫成了“\--with-mysql=mysqlnd \  --with -mysqli=mysqlnd”。 make && make install cp /usr/local/src/php-5.6.12/php.ini-production /usr/local/php/etc/php.ini

4、配置apache與php關(guān)聯(lián)

vim /usr/local/apache2/conf/httpd.conf  找到:AddType application/x-gzip .gz .tgz 在其下面添加:AddType application/x-httpd-php .php 找到: <IfModule dir_module> DirectoryIndex index.html /IfModule> 將其改為: <IfModule dir_module> DirectoryIndex index.html index.htm index.php </IfModule> 找到:#ServerName www.example.com:80 修改為:ServerName localhost:88 找到:listen:80 修改為:listen:88 找到: <Directory />      Options FollowSymLinks      AllowOverride None      Order deny,allow      Deny from all </Directory> 改為: <Directory />      Options FollowSymLinks      AllowOverride None      Order deny,allow      Allow from all </Directory> 找到:#Include conf/extra/httpd-vhosts.conf 把最前面的#去掉 查看是否存在modules/libphp5.so vim /usr/local/apache2/conf/extra/httpd-vhosts.conf     #打開apache虛擬主機(jī)配置文件在最后添加: <VirtualHost *:88>          DocumentRoot "/date/discuz/"          ServerName bbs.xiaoyua.com          ErrorLog "logs/bbs.xiaoyuan.com-error_log"          CustomLog "logs/bbs.xiaoyuan.com-access_log" common </VirtualHost> service httpd -t (檢查錯誤) service httpd graceful(加載配置) 查看httpd的運(yùn)行情況 netstat -lnp | grep httpd

5、在設(shè)備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 instal vim /etc/init.d/nginx    #編寫啟動腳本: #!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # Nginx Settings NGINX_SBIN="/usr/local/nginx/sbin/nginx" NGINX_CONF="/usr/local/nginx/conf/nginx.conf" NGINX_PID="/usr/local/nginx/logs/nginx.pid" RETVAL=0 prog="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=1 esac exit $RETVAL 將nginx服務(wù)啟動: chmod a+x /etc/init.d/nginx chkconfig --add nginx chkconfig 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    #創(chuàng)建nginx虛擬主機(jī)          vim /usr/local/nginx/conf/vhosts/bbs.conf   ##配置nginx虛擬主機(jī)(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; ##只允許真機(jī)訪問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;     }     #設(shè)置靜態(tài)緩存     location ~ .*\.(js|css)?$     {           expires      24h;           access_log off;     }     #設(shè)置防盜鏈     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、在設(shè)備A上安裝discuz

mkdir /data/discuz cd /data/discuz wget  unzip Discuz_X3.2_SC_UTF8.zip  mv upload/* . 在瀏覽器中輸入:bbs.xiaoyuan.com/install cd /data/bbs chown -R daemon.daemon config/ data/ uc_client/data/ uc_server/data/ 按照提示的安裝步驟安裝即可。

6、搭建mysql主從

# B機(jī)器的mysql為master,A機(jī)器上的mysql為slave 配置master:  vim /usr/local/mysql/my.cnf   #修改或添加:    server-id=1    log-bin=mysql-bin      兩個可選參數(shù)(2選1):    binlog-do-db=discuz #需要同步的庫    binlog-ignore-db=db1,db2 #忽略不同步的庫    修改配置文件后,重啟mysql    mysql -h227.0.0.1 -uroot   #登陸mysql數(shù)據(jù)庫    >grant replication slave on *.* to 'repl'@'192.168.145.133' identified by '123123';     # 授權(quán)slave可以訪問master    >flush tables with read lock;     >show master status;        # 會用到前兩列的內(nèi)容   安裝(和master步驟相同)和配置slave:   vim /etc/my.cnf     #修改或增加     server-id = 2    #這個數(shù)值不能和主一樣      兩個可選參數(shù)(2選1):     replicate-do-db=discuz  #需要同步的庫     replicate-ignore-db=db1,db2  #忽略不同步的庫      mysql -h227.0.0.1 -uroot   #登陸mysql數(shù)據(jù)庫      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"       從上查看從的狀態(tài):show slave status\G      當(dāng)看到     Slave_IO_Running: Yes                            Slave_SQL_Running: Yes                            Replicate_Do_DB: discuz                 則表示mysql主從搭建成功。更進(jìn)一步的驗證方法是在master的discuz庫里創(chuàng)建一個表,然后去slave      查看此表是否出現(xiàn)在slave的discuz庫。

看完以上關(guān)于LNAMP環(huán)境下如何搭建discuz論壇并實現(xiàn)mysql主從部署,很多讀者朋友肯定多少有一定的了解,如需獲取更多的行業(yè)知識信息 ,可以持續(xù)關(guān)注我們的行業(yè)資訊欄目的。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)站欄目:LNAMP環(huán)境下如何搭建discuz論壇并實現(xiàn)mysql主從部署-創(chuàng)新互聯(lián)
標(biāo)題URL:http://www.muchs.cn/article0/dhoioo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、網(wǎng)站維護(hù)、手機(jī)網(wǎng)站建設(shè)、搜索引擎優(yōu)化動態(tài)網(wǎng)站、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)