标签:搭建 主服务器 shadow sql数据库 功能 acl struct 开始 src
部署社交平台公司的社交网站采用PHP语言开发,为了管理PHP程序员开发的代码,上级领导要求搭建SVN服务器进行版本控制。社交网站的第个版木部署在LNMP平台之上,前端为Nginx服务器,通过fastcgi 协议访问后端的PHP服务器。为了保证数据安全,要求搭建MySQL数据库主从集群。
社交网站项目包含用户的相册功能,允许用户上传照片,上传照片需要使用共享存储来存放。针对共享存储可用的开源方案有很多,如MFS、FastDFS等。公司快定使用MFS分布式文件系统来实现,并将MFS挂载在PHP服务器的相关目录下。
根据公司的需求,实施过程大致分为以下步骤
[root@localhost ~]# yum install -y subversion
[root@localhost ~]# svnserve --version
svnserve, version 1.7.14 (r1542130)
compiled Nov 20 2015, 19:25:09 #//查看版本
[root@localhost ~]# mkdir -p /opt/svn/repo #//创建目录
[root@localhost ~]# svnadmin create /opt/svn/repo/ #//创建仓库
[root@localhost ~]# ls !$ #//目录创建完成后会生成所需要的配置文件
ls /opt/svn/repo/
conf db format hooks locks README.txt
[root@localhost ~]# vim /opt/svn/repo/conf/svnserve.conf
anon-access = read #//把read改为none匿名用户
auth-access = write #//认证用户具有写入权限
password-db = passwd #//把passwd改为 /opt/svn/repo/conf/passwd 用户密码密码的存放路径
authz-db = authz #//把authz改为 /opt/svn/repo/conf/authz 用户信息存放路径
[root@localhost ~]# cd /opt/svn/repo/conf/
[root@localhost conf]# ls #//对passwd文件和authz文件进行修改
authz passwd svnserve.conf
[root@localhost conf]# vim passwd
[users]
admin = abc123 #//admin是PHP程序员创建的账户密码为abc123
[root@localhost conf]# vim authz #//在文件最后一行创建
[/] #//对repo根目录的操作权限
admin = r #//admin账户具有读取权限
[/webphp] #//对根目录下webphp目录的权限
admin = rw #//admin账户具有读取写入权限
[root@localhost repo]# mkdir webphp #//在repo根目录下创建需要操作的子目录
[root@localhost repo]# svn import webphp file:///opt/svn/repo/webphp/ -m "初始化目录" #//初始化导入webphp目录
Committed revision 1.
[root@localhost repo]# svnserve -d -r /opt/svn/repo/ #//启动svn服务
[root@localhost repo]# netstat -lnupt | grep svnserve #//查看端口
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 1918/svnserve
[root@localhost ~]# yum install keepalived -y
[root@localhost ~]# vim /etc/keepalived/keepalived.conf #//修改配置文件
global_defs {
notification_email {
sysadmin@firewall.loc #//邮箱地址可以改为自己的邮箱地址在一台服务区down掉后会通过邮件发送给你
}
router_id LVS_DEVEL #//可改可不改,从服务器上要改因为不能和主服务器重叠router是唯一标识这边我该为了LVS_A从服务器要改为LVS_B
#//删除router_id下列四行
vrrp_instance VI_1 {
state MASTER #//主服务气味MASTER从服务器为BASKUP
interface eth0 #//网卡改为本服务器网卡centos7的网卡是ens33
virtual_router_id 51 #//keepalived组好主从要相同
priority 100 #//优先级从服务器小于100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.32.188 #//默认有三个去掉两个或者改为自己设定的VIP主从要一样
}
#//把虚拟ip下面的全部删除
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0 #//关闭防火墙和setenforce
[root@localhost ~]# systemctl start keepalived.service
[root@localhost ~]# ps -ef | grep keepalived
root 11384 1 0 13:19 ? 00:00:00 /usr/sbin/keepalived -D
root 11385 11384 0 13:19 ? 00:00:00 /usr/sbin/keepalived -D
root 11386 11384 0 13:19 ? 00:00:00 /usr/sbin/keepalived -D
root 11405 10998 0 13:20 pts/2 00:00:00 grep --color=auto keepalived
[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:3f:7f:08 brd ff:ff:ff:ff:ff:ff
inet 192.168.32.209/24 brd 192.168.32.255 scope global dynamic ens33
valid_lft 1184sec preferred_lft 1184sec
inet 192.168.32.188/32 scope global ens33 #//VIP
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe3f:7f08/64 scope link
valid_lft forever preferred_lft forever
#尝试down主服务器的keepalived看一下188
#的虚拟IP会不会绑定到从服务器上验证一下
#主服务器从新启动keepalived,188
#端口又会回到主服务器上
[root@localhost ~]# yum install pcre-devel zlib-devel gcc gcc-c++ make -y #//安装语言开发包和工具
[root@localhost ~]# tar zxvf /abc/nginx-1.12.0.tar.gz -C /opt/ #//解压源代码包到/opt目录下
[root@localhost ~]# useradd -M -s /sbin/nologin nginx #//创建管理用户不允许本地登录
[root@localhost ~]# cd /opt/nginx-1.12.0/ #//进入nginx解压的文件夹进行编译
[root@localhost nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --user=nginx --group=nginx #//指定安装路径用户和组
[root@localhost nginx-1.12.0]# make && make install #//用make 和 make install 转换为系统可识别的文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
location / {
root html; #//把html改为html/wedphp
index index.html index.htm;
}
#//在地下加入下面这段话
location ~ \.php$ {
root /var/www/html/webphp; #//页面存放位置
fastcgi_pass 192.168.32.209:9000; #//PHP服务器地址
fastcgi_index index.php;
include fastcgi.conf;
[root@localhost ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ #//建立软连接便于启动
[root@localhost ~]# nginx
nginx: [emerg] unexpected end of file, expecting "}" in /usr/local/nginx/conf/nginx.conf:117
#//如果在启动nginx中遇到这种报错说明要在117行加一个这样符号}
[root@localhost ~]# nginx #//启动
[root@localhost ~]# netstat -ntap | grep 80 #//查看端口号
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14066/nginx: master
[root@localhost ~]# tar zxvf /abc/php-5.5.38.tar.gz -C /opt/ #//解压源代码包
[root@localhost ~]# yum -y install > gd > libxml2-devel > libjpeg-devel > libpng-devel > zlib-devel > fontconfig-devel > openssl-devel > bzip2-devel #//首先安装GD库及GD库关联程序
[root@localhost ~]# useradd -M -s /sbin/nologin php #//创建用户不允许本地登录
[root@localhost php-5.5.38]# cp /usr/lib64/mysql/libmysqlclient.so.18 /usr/lib/libmysqlclient.so #//PHP默认去/usr/lib搜索libmysqlclient.so.18
[root@localhost php-5.5.38]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql \
--with-config-file-path=/usr/local/php5 --enable-mbstring --with-jpeg-dir --with-openssl --disable-ipv6 --enable-fpm
------如果在执行操作中出现错误请按照以下操作如果没有请跳过-------------------------------
#注:在执行以上操作是出现一下错误
Note that the MySQL client library is not bundled anymore!
#请查找到mysql.h文件,我们更改参数为--with-mysql=/usr,如果没有的话,请安装mysql-devel包,
[root@localhost php-5.5.6]# find / -name mysql.h
/usr/include/mysql/mysql.h
[root@localhost php-5.5.6]# yum install mysql-devel -y
---------------------------------------------
[root@localhost php-5.5.38]# make && make install #//转换文件类型
[root@localhost php-5.5.38]# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
[root@localhost php-5.5.38]# vim /usr/local/php5/etc/php-fpm.conf
;pid = run/php-fpm.pid #//去掉恰免得冒号
user = nobody #//nobody改为php
group = nobody #//nobody改为php
listen = 127.0.0.1:9000 #//监听地址改为0.0.0.0:9000
pm.max_children = 5 #//改为50
pm.start_servers = 2 #//改为20
pm.min_spare_servers = 1 #//改为5
pm.max_spare_servers = 3 #//改为35
[root@localhost php-5.5.38]# /usr/local/php5/sbin/php-fpm #//启动服务
[root@localhost php-5.5.38]# netstat -ntap | grep 9000
tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 26085/php-fpm: mast
[root@localhost php-5.5.38]# mkdir -p /var/www/html/webphp/ #//创建首页目录
[root@localhost php-5.5.38]# vim /var/www/html/webphp/index.php #//创建首页
<?
phpinfo();
?>
测试:
主,192.168.32.209
![image]
从:192.168.32.220
![image]
VIP:192.168.32.188
![image]
#//yum安装
[root@localhost webphp]# yum -y install mariadb-server mariadb
#//修改配置文件
[root@localhost webphp]# vim /etc/my.cnf
--------------------------------------------------------------------
#//删除以下9行
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
-----------------------------------------------------------------
#//重新指定配置路径
[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=/var/lib/mysql_slow_queris.log
binlog-ignore-db=mysql,information_schema
character_set_server=utf8
log_bin=mysql_bin
server_id=1 #//从服务器要修改server_id
log_slave_updates=true
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
[root@localhost webphp]# systemctl start mariadb.service
#//用mysql命令直接登陆
[root@localhost webphp]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]>
#//主服务器授权给从服务器
MariaDB [(none)]> grant replication slave on *.* to ‘replication‘@‘192.168.32.%‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.00 sec)
#//查看是否授权成功
MariaDB [(none)]> show grants for "replication"@"192.168.32.%";
+-----------------------------------------------------------------------------------------------------------------------------------+
| Grants for replication@192.168.32.% |
+-----------------------------------------------------------------------------------------------------------------------------------+
| GRANT REPLICATION SLAVE ON *.* TO ‘replication‘@‘192.168.32.%‘ IDENTIFIED BY PASSWORD ‘*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9‘ |
+-----------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
#//主服务器查看二进制日志和偏移量
MariaDB [(none)]> show master status;
+------------------+----------+--------------+--------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+--------------------------+
| mysql_bin.000003 | 410 | | mysql,information_schema |
+------------------+----------+--------------+--------------------------+
1 row in set (0.00 sec)
#//从服务器用授权用户密码登录master,通过二进制日志和偏移量开始备份主服务器
MariaDB [(none)]> change master to master_host=‘192.168.32.209‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000003‘,master_log_pos=410;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> slave start;
Query OK, 0 rows affected (0.00 sec)
#//查看IO,SQL线程有没有连接成功,显示为YES表示为成功
MariaDB [(none)]> show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
yum install -y zlib-devel gcc gcc-c++ //安装依赖包环境包
useradd mfs -s /sbin/nologin -M //创建管理用户
tar xzvf mfs-1.6.27-5.tar.gz -C /opt/
cd /opt/mfs-1.6.27/
./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs --disable-mfschunkserver --disable-mfsmount
make && make install
cd /usr/local/mfs/etc/mfs/
cp mfsmaster.cfg.dist mfsmaster.cfg # 主配置文件
cp mfsexports.cfg.dist mfsexports.cfg # 挂载权限
cp mfstopology.cfg.dist mfstopology.cfg # top架构感知
cd /usr/local/mfs/var/mfs/
cp metadata.mfs.empty metadata.mfs #防断裂
/usr/local/mfs/sbin/mfsmaster start //开启
/usr/local/mfs/sbin/mfsmaster -s //停止
netstat -antp | grep mfs
systemctl stop firewalld.service
setenforce 0 //关闭防火墙和安全功能
yum install -y zlib-devel gcc gcc-c++ //安装依赖包环境包
useradd mfs -s /sbin/nologin -M //创建管理用户
tar xzvf mfs-1.6.27-5.tar.gz -C /opt/
cd /opt/mfs-1.6.27/
./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs --disable-mfschunkserver --disable-mfsmount
make && make install
cd /usr/local/mfs/etc/mfs/
cp mfsmaster.cfg.dist mfsmaster.cfg
cp mfsexports.cfg.dist mfsexports.cfg
cp mfsmetalogger.cfg.dist mfsmetalogger.cfg
vim mfsmetalogger.cfg
......
MASTER_HOST = 192.168.43.118 //IP指向master
/usr/local/mfs/sbin/mfsmetalogger start //开启
/usr/local/mfs/sbin/mfsmetalogger -s //停止
netstat -antp | grep mfs
systemctl stop firewalld.service
setenforce 0 //关闭防火墙和安全功能
yum install -y zlib-devel gcc gcc-c++ //安装依赖包环境包
useradd mfs -s /sbin/nologin -M //创建管理用户
tar xzvf mfs-1.6.27-5.tar.gz -C /opt/
cd /opt/mfs-1.6.27/
./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs --disable-mfsmaster --disable-mfsmount
make && make install
cd /usr/local/mfs/etc/mfs/
cp mfschunkserver.cfg.dist mfschunkserver.cfg
cp mfshdd.cfg.dist mfshdd.cfg
vim mfschunkserver.cfg
......
MASTER_HOST = 192.168.43.118 //IP指向master
vim mfshdd.cfg
......
/data //添加一行/data,在这里/data是一个给MFS的分区,生产环境最好使用独立的分区或磁盘挂载到此目录
mkdir /data //创建文件夹
chown -R mfs:mfs /data //属主属组都改为mfs
/usr/local/mfs/sbin/mfschunkserver start //开启
/usr/local/mfs/sbin/mfschunkserver start -s //停止
netstat -antp | grep mfs
systemctl stop firewalld.service
setenforce 0 //关闭防火墙和安全功能
此处PHP服务器是客户端角色,在PHP服务器上搭建
yum install -y zlib-devel gcc gcc-c++ //安装依赖包环境包
tar xzvf fuse-2.9.2.tar.gz -C /opt //mfs客户端依赖于fuse
cd /opt/fuse-2.9.2
./configure
make && make install
vim /etc/profile
#在末尾处插入
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
source /etc/profile //加载立即生效
useradd mfs -s /sbin/nologin -M //创建管理用户
tar xzvf mfs-1.6.27-5.tar.gz -C /opt/
cd /opt/mfs-1.6.27/
./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs --disable-mfschunkserver --enable-mfsmount //注意此处开启客户端
make && make install
将MFS文件系统挂载在前端PHP服务器的/var/www/html/webphp/uploads/photos目录
mkdir -p /var/www/html/webphp/uploads/photos //创建挂载点
modprobe fuse //加载fuse模块到内核
/usr/local/mfs/bin/mfsmount /var/www/html/webphp/uploads/photos -H 192.168.32.211 //挂载MFS
---------建库,授权----------
mysql> CREATE DATABASE bbs; //创建一个数据库//
MariaDB [(none)]> GRANT all ON bbs.* TO ‘bbsuser‘@‘%‘ IDENTIFIED BY ‘admin123‘;
//把bbs数据库里面所有表的权限授予给bbsuser,并设置密码//
MariaDB [(none)]> flush privileges;
//刷新数据库//
---------测试数据库--------------
vi /var/www/html/webphp/index.php
<?php
$link=mysql_connect(‘192.168.32.209‘,‘bbsuser‘,‘admin123‘);
if($link) echo "Success!!";
else echo "Fail!!";
mysql_close();
?>
![image]!
[root@localhost ~]# unzip /abc/Discuz_X2.5_SC_UTF8.zip -d /opt/dis
[root@localhost ~]# cp -r /opt/dis/upload/ /var/www/html/webphp
[root@localhost ~]# cd /var/www/html/webphp
[root@localhost bbs]# chown -R php ./config
[root@localhost bbs]# chown -R php ./data
[root@localhost bbs]# chown -R php ./uc_client
[root@localhost bbs]# chown -R php ./uc_server/data
用http://192.168.32.188/bbs/install/index.php 进入安装页面:
![image]
![image]
安装完成
![image]
用http://192.168.32.188/bbs/index.php访问:
![image]
标签:搭建 主服务器 shadow sql数据库 功能 acl struct 开始 src
原文地址:http://blog.51cto.com/13645280/2153507