经过四年的学习和实战经验,打算做一个可以融合大多数学习的知识的毕业设计,所以就给自己的毕设取名:(分布式)桌面化多媒体网站系统。系统采用的构架如图1所示。
图1 系统架构
其中数据库集群目前采用mysql集群,为什么呢,因为目前mysql使用率还是很大的,而且mysql官方文档详细,最大的原因是因为自己笔记本配置不够高,不能搭建oracle集群。业务集群和WEB集群使用dubbo来实现远程调用及服务治理。
本篇文档的主要内容是记录毕设准备工作——环境搭建。
我使用的Linux版本是Ubuntu 14.10,安装在自己电脑的虚拟机中,分配了三个网卡。每个虚拟机和实体机都属于同一个局域网,同时使用虚拟机的内部网卡构建内部虚拟网络。如图2所示。用户使用SSH证书登录(略)。
图2 主机拓扑图
memcached使用的是官方下载的源码包,然后进行编译安装。获取最新的源码包:wget http://memcached.org/latest。
解压:tar -zxvf latest
安装依赖:sudo apt-get install gcc
sudo apt-get install icc-profiles
sudo apt-get install sasl2-bin
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
安装:./configure && make && make test && sudo make install
启动:/usr/local/bin/memcached -d -m 1024 -u root -p 11211 -P /tmp/memcached.pid
为了让memcache开机启动,为它写启动脚本,脚本内容如下:
#!/bin/sh
#
# memcached: MemCached ROOT
#
# chkconfig: - 90 25
# description: MemCached ROOT
#
# Source function library.
#. /etc/rc.d/init.d/functions
#. /etc/sysconfig/network
start()
{
echo -n $"Starting memcached: "
/usr/local/bin/memcached -u root -d -m 4096 -p 11211
echo
}
stop()
{
echo -n $"Shutting down memcached: "
kill -9 `pgrep memcached`
echo
}
[ -f /usr/local/bin/memcached ] || exit 0
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|condrestart}"
exit 1
esac
exit 0
下载:wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
解压:tar -zxvf zookeeper-3.4.6.tar.gz
修改配置:mv zoo_sample.cfg zoo.cfg
vim zoo.cfg
配置内容为:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/home/zookeeper/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
安装:sudo apt-get install chkconfig
sudo apt-get install chkrunlevel
sudo dpkg -i chkconfig_11.0-79.1-2_all.deb
sudo ln -s /usr/lib/insserv/insserv /sbin/insserv
添加服务:
sudo chkconfig --add memcached
sudo chkconfig --level 2345 memcached on
chkconfig --list memcached
sudo chkconfig --add zookeeper
sudo apt-get install apache2-utils
sudo apt-get install apache2
搭建工作:
sudo adduser svnuser
sudo addgroup subversion
sudo addgroup svnuser subversion
sudo mkdir /home/svn
sudo apt-get install libapache2-svn
sudo svnadmin create /home/svn/studio
svnserve -d -r /home/svn/studio/
sudo vim /etc/apache2/mods-available/dav_svn.conf
sudo htpasswd -c /home/svn/project/conf/passwd wms
sudo chown -R www-data:www-data /home/svn/studio/
sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /home/svn/apache2_svn_ssl.pem
sudo a2enmod ssl
集群主要是配置文件很复杂,搞了很久才搞定。一下是配置文件:
Config.ini
#
# Configuration file for MyCluster
#
[NDB_MGMD DEFAULT]
Portnumber=1186
[NDB_MGMD]
NodeId=1
HostName=192.168.56.102
DataDir=/home/data/mysql-cluster/1/
Portnumber=1186
[TCP DEFAULT]
SendBufferMemory=4M
ReceiveBufferMemory=4M
[NDBD DEFAULT]
BackupMaxWriteSize=1M
BackupDataBufferSize=16M
BackupLogBufferSize=4M
BackupMemory=20M
BackupReportFrequency=10
MemReportFrequency=30
LogLevelStartup=15
LogLevelShutdown=15
LogLevelCheckpoint=8
LogLevelNodeRestart=15
DataMemory=1M
IndexMemory=1M
MaxNoOfTables=4096
MaxNoOfTriggers=3500
NoOfReplicas=2
StringMemory=25
DiskPageBufferMemory=64M
SharedGlobalMemory=20M
LongMessageBuffer=32M
MaxNoOfConcurrentTransactions=16384
BatchSizePerLocalScan=512
FragmentLogFileSize=64M
NoOfFragmentLogFiles=16
RedoBuffer=32M
MaxNoOfExecutionThreads=2
StopOnError=false
LockPagesInMainMemory=1
TimeBetweenEpochsTimeout=32000
TimeBetweenWatchdogCheckInitial=60000
TransactionInactiveTimeout=60000
HeartbeatIntervalDbDb=15000
HeartbeatIntervalDbApi=15000
[NDBD]
NodeId=21
HostName=192.168.56.102
DataDir=/home/data/mysql-cluster/21/
[NDBD]
NodeId=22
HostName=192.168.56.103
DataDir=/home/data/mysql-cluster/22/
[MYSQLD DEFAULT]
[MYSQLD]
NodeId=41
HostName=192.168.56.102
[MYSQLD]
NodeId=42
HostName=192.168.56.103
[API]
NodeId=61
HostName=192.168.56.102
[API]
NodeId=62
HostName=192.168.56.103
My.cnf
[mysqld]
#不再进行反解析(ip不反解成域名),这样可以加快数据库的反应时间
skip-name-resolve
log-error=mysqld.42.err
datadir="/home/data/mysql-cluster/42/"
tmpdir="/home/data/mysql-cluster/42/tmp"
basedir="/home/mysql/mysql-cluster/bin/"
port=3306
ndbcluster=on
ndb-nodeid=42
ndb-connectstring=127.0.0.1:1186,
socket="/home/data/mysql-cluster/42/mysql.socket"
解决不能通过mysql.sock连接MySQL问题 这个问题主要提示是,不能通过 ‘/tmp/mysql.sock‘连到服务器,而php标准配置正是用过‘/tmp/mysql.sock‘,但是一些mysql 安装方法 将 mysql.sock放在/var/lib/mysql.sock或者其他的什么地方,用这样的方法:
ln -s /var/lib/mysql /mysql .sock /tmp/mysql.sock
成功了,就是这样ln -s /var/lib/mysql /mysql .sock /tmp/mysql.sock
/home/mysql/mysql-cluster/bin/ndb_mgmd --initial --ndb-nodeid=1 --config-dir=/home/data/mysql-cluster/1 --config-file=/home/data/mysql-cluster/1/config.ini
/home/mysql/mysql-cluster/bin/ndbd --ndb-nodeid=22 --ndb-connectstring=192.168.56.102:1186
/home/mysql/mysql-cluster/scripts/mysql_install_db --user=wms --datadir=/home/data/mysql-cluster/42/
/home/mysql/mysql-cluster/bin/mysqld_safe --defaults-file=/home/data/mysql-cluster/41/my.cnf --basedir=/home/mysql/mysql-cluster/ --log-error=/home/data/mysql-cluster/41/error.log --user=wms &
原文地址:http://blog.csdn.net/wu560130911/article/details/42616557