环境:
N F S: 172.16.0.3 (OS CentOS 7)
node1:172.16.0.5 (OS CentOS 6.7)
node2:172.16.0.6 (OS CentOS 6.7)
浮动IP:172.16.0.168
php php-mysql 安装:
# yum install php php-mysql 俩个节点都安装
Heartbeat 安装:
互信操作:俩边都操作:
# ssh-keygen -t rsa # ssh-copy-id -i .ssh/id_rsa.pub [email protected]
修改主机名:
# cat /etc/sysconfig/network //node2 NETWORKING=yes HOSTNAME=node2.sunshine.com # cat /etc/sysconfig/network //node1 NETWORKING=yes HOSTNAME=node1.sunshine.com
本地/etc/hosts解析:
# cat /etc/hosts | tail -2 172.16.0.5 node2.sunshine.com node2 172.16.0.6 node1.sunshine.com node1 # cat /etc/hosts | tail -2 172.16.0.5 node2.sunshine.com node2 172.16.0.6 node1.sunshine.com node1
同步时间:两边都操作,这里测试就不做crontab 不同时间了:
# service ntpdate start # [root@HA2 ~]# date ;ssh node2 'date' Wed Oct 26 15:28:32 CST 2016 Wed Oct 26 15:28:32 CST 2016
重启:
# shutdown -r now
安装epel源:
# rpm -Uivh ftp://ftp.pbone.net/mirror/dl.iuscommunity.org/pub/ius/archive/Redhat/6/i386/epel-release-6-5.noarch.rpm
安装依赖:
# yum install net-snmp-libs libnet PyXML pygtk2-libglade -y
安装Heartbeat相关程序包:找不到的同学别灰心我的百度云盘:http://pan.baidu.com/s/1boGx6t5
# rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm \ > heartbeat-stonith-2.1.4-12.el6.x86_64.rpm \ > heartbeat-pils-2.1.4-12.el6.x86_64.rpm \ > heartbeat-gui-2.1.4-12.el6.x86_64.rpm
如报以下错误:安装libtool-ltdl 既可以:
error: Failed dependencies: libltdl.so.7()(64bit) is needed by heartbeat-2.1.4-12.el6.x86_64 libltdl.so.7()(64bit) is needed by heartbeat-stonith-2.1.4-12.el6.x86_64 libltdl.so.7()(64bit) is needed by heartbeat-pils-2.1.4-12.el6.x86_64# yum install libtool-ltdl -y //安装libtool-ltdl
-安装支持xshell Xmanger包,否则网络上很方法也是不可用的:
# yum install xorg-x11-xauth //如果不安装使用hb_gui是无法调用x11
ha.cf配置:
# grep -v "#" ha.cf logfile /var/log/heartbeat-log mcast eth0 225.10.210.1 694 1 0 auto_failback on node node1.sunshine.com node node2.sunshine.com crm on ping 172.16.0.1 # grep -v "#" authkeys auth 2 2 sha1 Dn880wJZxfsUpioJWy7FgQ # passwd hacluster //在哪里启动,就在哪里设置hacluster密码 # hb_gui & compression bz2 compression_threshold 2
authkeys配置
[root@node2 ha.d]# cat authkeys | tail -4 | grep -v "#" auth 2 2 sha1 Dn880wJZxfsUpioJWy7FgQ
在node{1|2}清除iptables并关闭selinux
# iptables -F# setenforce 0# cat /etc/selinux/config | tail -3 | head -1 SELINUXTYPE=targeted
httpd 安装:
# yum install httpd -y //node{1|2} # echo "node1
" > /var/www/html/index.html //node1执行 # echo "node2
" > /var/www/html/index.html //node2执行 # curl node{1,2} //访问测试node1
node2
# service httpd stop ;ssh node2 'service httpd stop' Stopping httpd: [ OK ] Stopping httpd: [ OK ] # chkconfig httpd off ;ssh node2 'chkconfig httpd off' //关闭httpd自动启动 # chkconfig httpd --list ;ssh node2 'chkconfig httpd --list'//查看是否关闭 httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
NFS Server搭建:这是在NFS服务器上执行
# groupadd -g 306 mysql # useradd -g 306 -u 306 -M -r mysql # mkdir /data/mydata # chown -R mysql.mysql /data/mydata # cat /etc/exports //编辑需要导出的文件 /data/mydata 172.16.0.0/24(rw,no_root_squash) //no_root_squash表示远端主机root用户不转换nobody用户 # systemctl start nfs.service //启动nfs服务 # cat /etc/rc.local | tail -1 //加入开机启动 /usr/bin/systemctl start nfs.service
PerconaMySQL 安装:
# mount -t nfs 172.16.0.3:/data/mydata /mydata //挂载nfs文件至本地 # yum install openssl-devel -yes //安装openssl-devel包,至此Preconamysql的ssl # cd /usr/lib64 //进入lib64# ln -s libssl.so.1.0.1e libssl.so.6 //软连接,因为Preconamysql要依赖该库,但是我们系统上的是libssl.so.1.0.1e # ln -sv libcrypto.so libcrypto.so.6 //软连接,因为Preconamysql要依赖该库,但是我们系统上的是libcrypto.so # tar xf /usr/local/src/Percona-Server-5.6.27-rel76.0-Linux.x86_64.ssl098e.tar.gz -C /usr/local //解压缩至/usr/local,个人习惯 # cd /usr/local //进入local # ln -sv Percona-Server-5.6.27-rel76.0-Linux.x86_64.ssl098e.tar.gz mysql //不要问为什么,大家都这么做 # groupadd -g 306 mysql //新建组,指定GID306 # useradd -g 306 -u 306 -r -M mysql //新建用户,指定GID,UID为306 # mkdir /mydata //创建NFS挂载点 # cd /usr/local/mysql //进入程序包 # chown -R mysql.mysql ./* //-R递归 # scripts/mysql_install_db --datadir=/mydata/ --user=mysql //初始化 # cp -p support-files/mysql.server /etc/init.d/mysqld //拷贝启动脚本 # vim /etc/my.cnf //mysql的配置文件,里面的参数我调的很小,是因为仅做博客测试使用 # The MySQL server[mysqld] port = 3306 user = mysql datadir = /mydata tmpdir = /dev/shm slave-load-tmpdir = /tmp socket = /mydata/mysql.sock key_buffer_size = 32M max_allowed_packet = 8M # table_cache = 30s join_buffer_size = 16M sort_buffer_size = 16M read_buffer_size = 16M read_rnd_buffer_size = 16M myisam_sort_buffer_size = 32M query_cache_size = 16M query_cache_type = 1 max_tmp_tables = 64 tmp_table_size = 64M max_heap_table_size = 64M thread_cache_size = 32 thread_concurrency = 16 max_connections = 1986 max_user_connections = 0 max_connect_errors = 99999999 wait_timeout = 28800 interactive_timeout = 7200 slow_query_log = 1 long_query_time = 3 log_slow_slave_statements=1 #slow_query_log_timestamp_always =1 slow_query_log_file = /mydata/slow.log back_log = 200 myisam_repair_threads = 1 myisam-recover = DEFAULT expire_logs_days = 20 pid-file = /mydata/mysql.pid binlog_format = mixed init-connect='SET NAMES utf8' character-set-server=utf8 skip-character-set-client-handshake bind-address=0.0.0.0 skip-external-locking #skip-symlink log-slave-updates skip-name-resolve # read_only skip-slave-start server-id = 3306 log-bin = 3306-bin relay-log = 3306-relay-bin log-error=error.log #------------- innodb -------------- innodb_file_format = Barracuda default-storage-engine = InnoDB innodb_buffer_pool_size = 64M innodb_additional_mem_pool_size = 32M innodb_data_file_path = ibdata1:100M:autoextend # innodb_autoextend_increment = 100M innodb_flush_log_at_trx_commit = 0 innodb_log_buffer_size = 8M innodb_log_file_size = 32M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 20 innodb_file_per_table = 1 innodb_flush_method = O_DIRECT innodb_support_xa = 0 innodb_io_capacity = 500 # innodb_buffer_pool_instances = 4 [client] user = mysql port = 3306 socket = /mydata/mysql.sock [myisamchk] key_buffer = 32 sort_buffer_size = 32 read_buffer = 32M write_buffer = 32M
# service mysqld start //测试是否能够启动 # service mysqld stop //然后停止服务 # chkconfig mysqld off //关闭自动启动 ps:node{1|2}都是一样的操作
安装博客
下载程序包
# cd /usr/local/src # wget https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz
解压并设置 777 权限,这边为了方便
# tar xf wordpress-4.5.3-zh_CN.tar.gz -C /var/www/html/ # cd /var/www/html/ # chown -R 777 wordpress
手动启动mysql
# service mysqd start
进入mysql创建wordpress库,提供给wordpress初始化呢使用
# mysql -uroot -p //回车输入自己的密码,没设定密码直接回车 # CREATE DATABASE wordpess;
授权wordpress库权限,生产机建议不要使用通配符
# GRANT ALL ON wordpress.* TO wordpress@‘172.16.%.%' INDENTIFIED BY 'redhat'; # FLUSH PRIVILEGES;
博客初始化:先手动启动mysql,初始化完毕后再手动关闭mysql,这里太简单 不上图了
1、填上mysql地址:也就是我们的浮动IP:172.16.0.168
2、填上用户:在数据库创建的:wordpress
3、填上密码:redhat
4、其它根据自己定义填写即可。
Hearbeat-Gui资源配置:
# hb_gui &
1、Resources新建组资源,并命名,注意Parameters里面的值
2、访问测试
3、节点切换并访问测