本文主要給大家介紹LNAMP環(huán)境下如何搭建discuz論壇并實(shí)現(xiàn)MySQL主從部署,文章內(nèi)容都是筆者用心摘選和編輯的,具有一定的針對(duì)性,對(duì)大家的參考意義還是比較大的,下面跟筆者一起了解下LNAMP環(huán)境下如何搭建discuz論壇并實(shí)現(xiàn)mysql主從部署吧。
創(chuàng)新互聯(lián)主要從事成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)梅州,十余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):13518219792
實(shí)驗(yàn)環(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
實(shí)驗(yàn)步驟:
1、在B設(shè)備上安裝mysql數(shù)據(jù)庫(kù)
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ù)庫(kù)初始化 cp support-files/my-large.cnf /etc/my.cnf #拷貝數(shù)據(jù)庫(kù)配置文件 cp support-files/mysql.server /etc/init.d/mysqld #拷貝數(shù)據(jù)庫(kù)啟動(dòng)腳本 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ù)庫(kù) >create database discuz; #創(chuàng)建discuz庫(kù) >grant all on discuz.* to 'xaioyuan'@'192.168.145.133' identified by '123456'; #這條語(yǔ)句是授權(quán)ip為192.168.145.133的xiaoyuan用戶可以訪問(wèn)discuz庫(kù),訪問(wèn)密碼為123456 >quit #退出數(shù)據(jù)庫(kù)
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的啟動(dòng)腳本 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的時(shí)候如果遇到反復(fù)報(bào)錯(cuò),則應(yīng)該觀察編譯選項(xiàng)是否在不該出現(xiàn)空格的時(shí)候出現(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 (檢查錯(cuò)誤) 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 #編寫啟動(dòng)腳本: #!/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ù)啟動(dòng): 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ī)訪問(wèn)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 兩個(gè)可選參數(shù)(2選1): binlog-do-db=discuz #需要同步的庫(kù) binlog-ignore-db=db1,db2 #忽略不同步的庫(kù) 修改配置文件后,重啟mysql mysql -h227.0.0.1 -uroot #登陸mysql數(shù)據(jù)庫(kù) >grant replication slave on *.* to 'repl'@'192.168.145.133' identified by '123123'; # 授權(quán)slave可以訪問(wèn)master >flush tables with read lock; >show master status; # 會(huì)用到前兩列的內(nèi)容 安裝(和master步驟相同)和配置slave: vim /etc/my.cnf #修改或增加 server-id = 2 #這個(gè)數(shù)值不能和主一樣 兩個(gè)可選參數(shù)(2選1): replicate-do-db=discuz #需要同步的庫(kù) replicate-ignore-db=db1,db2 #忽略不同步的庫(kù) mysql -h227.0.0.1 -uroot #登陸mysql數(shù)據(jù)庫(kù) 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)一步的驗(yàn)證方法是在master的discuz庫(kù)里創(chuàng)建一個(gè)表,然后去slave 查看此表是否出現(xiàn)在slave的discuz庫(kù)。
看完以上關(guān)于LNAMP環(huán)境下如何搭建discuz論壇并實(shí)現(xiàn)mysql主從部署,很多讀者朋友肯定多少有一定的了解,如需獲取更多的行業(yè)知識(shí)信息 ,可以持續(xù)關(guān)注我們的行業(yè)資訊欄目的。
新聞標(biāo)題:LNAMP環(huán)境下如何搭建discuz論壇并實(shí)現(xiàn)mysql主從部署
網(wǎng)站鏈接:http://www.rwnh.cn/article46/igjphg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、虛擬主機(jī)、App開發(fā)、響應(yīng)式網(wǎng)站、商城網(wǎng)站、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)