龙空技术网

HA服务器架构-基于CentOS7

落叶丛 70

前言:

此刻姐妹们对“centosruby升级19”大约比较看重,咱们都需要分析一些“centosruby升级19”的相关资讯。那么小编在网摘上搜集了一些关于“centosruby升级19””的相关内容,希望咱们能喜欢,兄弟们快快来了解一下吧!

linux文件夹含义

/bin - 重要的二进制 (binary) 应用程序

/boot - 启动 (boot) 配置文件

/dev - 设备 (device) 文件

/etc - 配置文件、启动脚本等 (etc)

/home - 本地用户主 (home) 目录

/lib - 系统库 (libraries) 文件

/lost+found - 在根 (/) 目录下提供一个遗失+查找(lost+found) 系统

/media - 挂载可移动介质 (media),诸如 CD、数码相机等

/mnt - 挂载 (mounted) 文件系统

/opt - 提供一个供可选的 (optional) 应用程序安装目录

/proc - 特殊的动态目录,用以维护系统信息和状态,包括当前运行中进程 (processes) 信息

/root - root (root) 用户主文件夹,读作“slash-root”

/sbin - 重要的系统二进制 (system binaries) 文件

/sys - 系统 (system) 文件

/tmp - 临时(temporary)文件

/usr - 包含绝大部分所有用户(users)都能访问的应用程序和文件

/var - 经常变化的(variable)文件,诸如日志或数据库等

centos7防火墙操作永久打开一个80端口

firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --reload
启动一个服务:
systemctl start firewalld.service
关闭一个服务:
systemctl stop firewalld.service
重启一个服务:
systemctl restart firewalld.service
显示一个服务的状态:
systemctl status firewalld.service
在开机时启用一个服务:
systemctl enable firewalld.service
在开机时禁用一个服务:
systemctl disable firewalld.service
查看服务是否开机启动:
systemctl is-enabled firewalld.service
查看已启动的服务列表:
systemctl list-unit-files|grep enabled
查看启动失败的服务列表:
systemctl --failed
keeplievedkeeplieved的简介

Keepalived的作用是检测服务器的状态,如果有一台web服务器宕机,或工作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的工作,当服务器工作正常后Keepalived自动将服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人工做的只是修复故障的服务器

keepalievd安装

Keepalived:192.168.3.206 HA1Keepalived:192.168.3.207 HA2
关闭selinux
### 查看[root@dev-server ~]# getenforceDisabled[root@dev-server ~]# /usr/sbin/sestatus -vSELinux status:                 disabled### 临时关闭##设置SELinux 成为permissive模式##setenforce 1 设置SELinux 成为enforcing模式setenforce 0###永久关闭vim /etc/selinux/config###SELINUX=enforcing改为SELINUX=disabled 
下载或者上传 压缩包 wget 解压 &编译
tar -xzvf keepalived-1.3.9.tar.gz#编译cd keepalived-1.3.9/./configure  make  make install
修改Master主机配置

vim /usr/local/etc/keepalived/keepalived.conf

global_defs {   notification_email {     heyapenggz@163.com #管理员邮箱列表   }   notification_email_from root@localhost   smtp_server 127.0.0.1   smtp_connect_timeout 30   router_id HA1 #主机名}vrrp_instance VI_1 {    state MASTER #角色    interface ens33 #网卡编号    virtual_router_id 51    priority 100 #权重    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        192.168.3.210/24 #VIP    }}
修改BACKUP主机配置 vim /usr/local/etc/keepalived/keepalived.conf
global_defs {   notification_email {     heyapenggz@163.com   }   notification_email_from root@localhost   smtp_server 127.0.0.1   smtp_connect_timeout 30   router_id NodeB}vrrp_instance VI_1 {    state BACKUP    interface ens33    virtual_router_id 51    priority 90    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        192.168.3.140/24    }}  
设置开机启动 Centos6
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ mkdir -p /etc/keepalived cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf chmod +x /etc/init.d/keepalived chkconfig –add keepalived chkconfig keepalived on

Centos 7

mkdir -p /etc/keepalived/cp  /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/systemctl enable keepalived.service
常见问题OpenSSL is not properly installed on your system.
  !!! OpenSSL is not properly installed on your system. !!!  !!! Can not include OpenSSL headers files.            !!!

解决办法:

    yum -y install openssl-devel
error: no acceptable C compiler found in $PATH
error: no acceptable C compiler found in $PATH

解决办法:

yum install gcc
Mysql双主双复制集群mysql安装

1.删除系统自带数据库

yum remove mariadb*
安装mysql5.6
rpm -ivh MySQL-server-5.6.21-1.el6.x86_64.rpm
设置开机启动 并启动mysql
chkconfig mysql onservice mysql start
登录root账户并修改root密码
cat /root/.mysql_secretmysql -u root -pset password =PASSWORD('eshu2017');
配置共同账户
CREATE USER 'ha'@'%' IDENTIFIED BY 'eshu2017'; GRANT ALL ON *.* TO 'ha'@'%'; flush privileges;
配置HA1主服务器
server-id = 1log-bin=mysql-bin binlog-do-db = habinlog-ignore-db = mysql#主-主形式需要多添加的部分log-slave-updatessync_binlog = 1auto_increment_offset = 1auto_increment_increment = 2replicate-do-db = hareplicate-ignore-db = mysql,information_schema
配置HA2主服务器
server-id = 2log-bin=mysql-bin replicate-do-db = hareplicate-ignore-db = mysql,information_schema,performance_schema      #主-主形式需要多添加的部分binlog-do-db = habinlog-ignore-db = mysqllog-slave-updatessync_binlog = 1auto_increment_offset = 2auto_increment_increment = 2

8.重启两台服务器 并配置复制账户

修改HOSTS

vim /etc/hosts
在HA1 mysql上运行
grant replication slave on *.* to 'replicate'@'HA2' identified by 'eshu2017';
在HA2 mysql上运行
grant replication slave on *.* to 'replicate'@'HA1' identified by 'eshu2017';
配置复制(分别配置为另一台服务器的slave)
show master status;  #记录下来file   Position 两个值供子节点的 master_log_file =  master_log_pos= 使用stop SLAVE       change  master to master_host='192.168.3.207',master_user='ha',master_password='eshu2017',master_log_file='mysql-bin.000001',master_log_pos=817;  start slave
fastDFS下载

包含两部分 一部分为lib 一部分为fastDFS

	
安装安装lib
tar xf libfastcommon-1.0.7.tar.gzcd libfastcommon-1.0.7./make.sh./make.sh install
安装fastDFS
tar xf fastdfs-5.09.tar.gzcd fastdfs-5.09./make.sh./make.sh install

3.配置

配置文件路径

cd /etc/fdfscp storage.conf.sample storage.confcp tracker.conf.sample tracker.conf
tracker节点配置 tracker.conf
#绑定IPbind_addr=#端口port=22122#连接超时时间connect_timeout=30#日志数据路径base_path=/data/fdfs_tracker#上传文件时选择group的方法#0:轮询,1:指定组,2:选择剩余空间最大store_lookup=2#如果上面的配置是1,那么这里必须指定组名store_group=group2#上传文件时选择server的方法#0:轮询,1:按IP地址排序,2:通过权重排序store_server=0#storage上预留空间reserved_storage_space = 10%
storage节点 storage.conf
#storage server所属组名group_name=group1#绑定IPbind_addr=#storage server的端口port=23000#连接超时时间connect_timeout=30#日志数据路径base_path=/data/fdfs_storage/base#storage path的个数store_path_count=2#根据store_path_count的值,就要有storage0到storage(N-1)个store_path0=/data/fdfs_storage/storage0store_path1=/data/fdfs_storage/storage1#跟踪服务器tracker_server=192.168.1.222:22122tracker_server=192.168.1.233:22122
创建文件夹
mkdir -p /data/fdfs_storage/basemkdir -p /data/fdfs_storage/storage0mkdir -p /data/fdfs_storage/storage1mkdir -p /data/client
打开防火墙端口
firewall-cmd --zone=public --add-port=22122/tcp --permanent firewall-cmd --zone=public --add-port=23000/tcp --permanent 
配置客户端
cd /etc/fdfscp client.conf.sample client.confvi client.conf
#存放日志目录base_path=/data/client#跟踪服务器tracker_server=192.168.1.222:22122tracker_server=192.168.1.233:22122
启动服务并设置开机启动
systemctl start fdfs_trackerd.servicesystemctl start fdfs_storaged.servicesystemctl enable fdfs_storaged.servicesystemctl enable fdfs_trackerd.service
测试文件上传
echo "12345678" >> /data/1.txtfdfs_upload_file /etc/fdfs/client.conf /data/1.txt
文件下载
fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgB3li3a2mAejYPAAAADok0NhY177.txt
追加
echo "hello" >> /data/2.txtfdfs_upload_appender /etc/fdfs/client.conf /data/1.txtfdfs_append_file /etc/fdfs/client.conf group1/M00/00/00/wKgB3li3bxCEAcqhAAAAAIk0NhY869.txt /data/2.txt
删除
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgB3li3a2mAejYPAAAADok0NhY177.txt
查看文件信息
fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/wKgB3li3a2mAejYPAAAADok0NhY177.txt
查看集群
fdfs_monitor /etc/fdfs/client.conf
常用命令
fdfs_appender_testfdfs_appender_test1fdfs_append_filefdfs_crc32fdfs_delete_filefdfs_download_filefdfs_file_infofdfs_monitorfdfs_storagedfdfs_testfdfs_test1fdfs_trackerdfdfs_upload_appenderfdfs_upload_file
两台服务器,各启动三个实例,形成三主三从

实验机器IP: 192.168.3.206 192.168.3.207

系统环境:centos 7

1、安装所需环境和工具

yum -y install wget vim tcl gcc make
2、下载redis 压缩包并解压
cd /usr/local/wget  -zxvf redis-4.0.1.tar.gz
3、编译redis源文件
cd redis-4.0.1make & make install# 测试:make test

(如果 /usr/local/bin/ 文件夹内没有 redis-server 那几个文件,就从 /usr/local/redis-4.0.1/src/ 中拷贝过去,命令:cp redis-server redis-cli redis-sentinel redis-benchmark redis-check-aof redis-check-rdb /usr/local/bin/)

4、配置内核参数

配置 vm.overcommit_memory 为1,这可以避免数据被截断

sysctl -w vm.overcommit_memory=1
5、创建多实例的文件夹,用来存放不同实例的配置文件
cd /usr/local/mkdir clustercd clustermkdir 7000 7001 7002
6、修改配置文件
vim /usr/local/redis-4.0.1/redis.confbind 192.168.2.247(需要不同服务器的节点连通,就不能设置为 127.0.0.1)protected-mode no(需要不同服务器的节点连通,这个就要设置为 no)daemonize yes(设置后台运行redis)cluster-enabled yescluster-node-timeout 5000appendonly yes# 根据不同端口需要设置的地方port 7000pidfile /var/run/redis_7000.pidlogfile /var/log/redis/redis_7000.logdbfilename dump_7000.rdbappendfilename "appendonly_7000.aof"cluster-config-file nodes_7000.conf
7、复制配置文件到各个实例文件夹,并修改相应端口号和参数
cp -f /soft/redis-4.0.1/redis.conf /usr/local/cluster/7000/cp -f /soft/redis-4.0.1/redis.conf /usr/local/cluster/7001/cp -f /soft/redis-4.0.1/redis.conf /usr/local/cluster/7002/mkdir /var/log/redis/
8、启动各个实例
cd /usr/local/redis-4.0.1/src/./redis-server /usr/local/cluster/7000/redis.conf &./redis-server /usr/local/cluster/7001/redis.conf &./redis-server /usr/local/cluster/7002/redis.conf &

使用 ps -ef|grep redis 查看是否都启动成功,IP和端口号都正确

9、防火墙开通端口号策略(这里用centos7默认的firewall-cmd)

firewall-cmd --zone=public --add-port=7000-7002/tcp --permanentfirewall-cmd --zone=public --add-port=17000-17002/tcp

--permanent(必须开集群总线端口,集群总线端口=端口号+10000,例:7000的集群总线端口是17000。这个集群总线端口不开放,集群的时候外部服务器的节点添加不进来)

firewall-cmd --reload

#彻底关闭防火墙

systemctl stop firewalld.service systemctl disable firewalld.service

================================================================================== ====================== 1~9都是要在两台服务器中操作的 =========================== ==================================================================================

10、测试两台服务器是否都能 telnet 得通另一台的 7000~7002 和 17000~17002

yum isntall telnet -ytelnet 192.168.3.206 7000
11、安装 ruby 环境
yum -y install ruby rubygems
12、更新gem源,国外的会被墙,所以换一个国内的
gem sources --remove  --remove  -a  source -lgem cleanupgem list
13、使用gem安装 redis和 ruby接口
gem install redis (或 gem install redis --version 4.0.1)
14、创建集群
cd /usr/local/redis-4.0.1/src/./redis-trib.rb create --replicas 1 192.168.3.206:7000  192.168.3.206:7001 192.168.3.206:7002 192.168.3.207:7000  192.168.3.207:7001 192.168.3.207:7002
留意屏幕,会有一句(type 'yes' to accept),输入 yes ,回车,就是接受自动分配的三主三从 如果最后出现
[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.

说明成功了。

如果是出现 Waiting for the cluster to join........... 一直有 “.”出现,说明另一台服务器的端口策略没通,一直在等那边的节点加入集群,那么恭喜你,要悲剧了.....

15、验证集群节点数

cd /usr/local/redis-4.0.1/src/./redis-cli -h 192.168.2.247 -c -p 7000

CLUSTER NOTES

设置密码

如果集群要设置密码,集群启动后要在各个节点下设置:

config set masterauth abcconfig set requirepass abcconfig rewrite
16、常见问题
redis requires Ruby version >= 2.2.2gem install redis其中 gem install redis命令执行时出现了: redis requires Ruby version >= 2.2.2的报错,查了资料发现是Centos默认支持ruby到2.0.0,可gem 安装redis需要最低是2.2.2解决办法是 先安装rvm,再把ruby版本提升至2.3.3gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3    curl -L get.rvm.io | bash -s stable    find / -name rvm -print                source /usr/local/rvm/scripts/rvm          rvm list known            rvm install 2.3.3      rvm use 2.3.3      rvm use 2.3.3 --default      rvm remove 2.0.0      ruby --version 
snmp安装snmp简介snmp安装
yum install -y net-snmpyum install -y net-snmp-develyum install -y net-snmp-libs
配置修改配置文件

/etc/snmp/snmpd.conf/etc/snmp/snmpd.conf

配置防火墙
firewall-cmd --zone=public --add-port=161/udp --permanent
配置开机启动
nginx 及 FastDfs-nginx-modle安装

分别解压两个文件包

tar -xzvf nginx-1.12.2.tar.gz tar -xzvf fastdfs-nginx-module_v1.16.tar.gz 

修改

vim /home/data/bin/fastdfs-nginx-module/src/configCORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"#去掉local

编译

cd  nginx-1.12.2/./configure --add-module=../fastdfs-nginx-module/srcmake make install

配置插件

cd /home/data/bin/fastdfs-nginx-module/src vim mod_fastdfs.conf

tracker_server=192.168.3.206:22122url_have_group_name = truestore_path_count=2store_path0=/data/fdfs_storage/storage0store_path1=/data/fdfs_storage/storage1

复制fastdfs文件

cp mod_fastdfs.conf /etc/fdfscd /home/data/bin/fastdfs-5.11/confcp anti-steal.jpg http.conf mime.types /etc/fdfs/

配置nginx

vim /usr/local/nginx/conf/nginx.conf

在web中增加配置

location /group1/M00 {    ngx_fastdfs_module;}

启动

/usr/local/nginx/sbin/nginx
注意

在已经安装过 Nginx 的服务器上安装配置 fastdfs-nginx-module 模块?我们直接进入 Nginx 的存放目录,进行配置后编译,就不需要执行最后安装make install这一步了,接着重启就行了。

标签: #centosruby升级19