本文主要给大家介绍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.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 on3、在设备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 install cp /usr/local/src/php-5.6.12/php.ini-production /usr/local/php/etc/php.ini4、配置apache与php关联
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虚拟主机配置文件在最后添加: <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的运行情况 netstat -lnp | grep httpd5、在设备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服务启动: 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 #创建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/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机器的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主从部署,很多读者朋友肯定多少有一定的了解,如需获取更多的行业知识信息 ,可以持续关注我们的行业资讯栏目的。
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站栏目:LNAMP环境下如何搭建discuz论坛并实现mysql主从部署-创新互联
标题URL:https://www.cdcxhl.com/article0/dhoioo.html
成都网站建设公司_创新互联,为您提供企业网站制作、网站维护、手机网站建设、搜索引擎优化、动态网站、品牌网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联