1、基础环境 vip(虚拟IP):192.168.100.222 iscsi(存储):192.168.100.200 node1(节点一):192.168.100.192 node2(节点二):192.168.100.195 新建highgo操作系统用户,要求三台机器highgo用户的uid、gid相同 2、三台机器均关闭防火墙和SELINUX (以n
1、基础环境
<code> vip(虚拟IP):192.168.100.222 iscsi(存储):192.168.100.200 node1(节点一):192.168.100.192 node2(节点二):192.168.100.195 新建highgo操作系统用户,要求三台机器highgo用户的uid、gid相同 </code>
2、三台机器均关闭防火墙和SELINUX (以node1为例)
3、三台机器均SSH互信 (以iscsi为例)
(1)修改/etc/hosts
(2)root用户执行
(3)highgo用户执行
4、ISCSI配置
(1)服务器端(iscsi)
<code class=" hljs lasso"><span class="hljs-subst">>>></span>首先安装scsi<span class="hljs-attribute">-target</span><span class="hljs-attribute">-utils</span>: yum <span class="hljs-attribute">-y</span> install scsi<span class="hljs-attribute">-target</span><span class="hljs-attribute">-utils</span> <span class="hljs-subst">>>></span>编辑/etc/tgt/targets<span class="hljs-built_in">.</span>conf,添加:(/dev/sda是新添加的用来共享的磁盘,为原生的未经过格式化的盘) <span class="hljs-subst"><</span>target iqn<span class="hljs-number">.201605</span><span class="hljs-built_in">.</span>dev:server<span class="hljs-built_in">.</span>target1<span class="hljs-subst">></span> backing<span class="hljs-attribute">-store</span> /dev/sda <span class="hljs-subst"><</span>/target<span class="hljs-subst">></span> <span class="hljs-subst">>>></span>启动服务,并配置开机自启动: service tgtd start chkconfig tgtd <span class="hljs-keyword">on</span></code>
(2)客户端(node1、node2)
<code class=" hljs lasso"><span class="hljs-subst">>>></span>首先安装iscsi<span class="hljs-attribute">-initiator</span><span class="hljs-attribute">-utils</span> yum <span class="hljs-attribute">-y</span> install iscsi<span class="hljs-attribute">-initiator</span><span class="hljs-attribute">-utils</span> <span class="hljs-subst">>>></span>编辑/etc/iscsi/initiatorname<span class="hljs-built_in">.</span>iscsi,添加: InitiatorName<span class="hljs-subst">=</span>iqn<span class="hljs-number">.201605</span><span class="hljs-built_in">.</span>dev:server<span class="hljs-built_in">.</span>target1 <span class="hljs-subst">>>></span>配置服务: chkconfig iscsi <span class="hljs-keyword">on</span> chkconfig iscsid <span class="hljs-keyword">on</span> service iscsi restart service iscsid restart</code>
启动服务时出现失败的情况,正常
5、安装数据库(node1、node2)
node1安装过程:
(1)创建目录(挂载点)
<code class=" hljs perl"><span class="hljs-keyword">mkdir</span> /install/hgdb -p</code>
(2)发现服务器端有磁盘共享,并登录
(3)查询本地多一块磁盘
(4)格式化磁盘并挂载
注意:若挂载时出现以下错误,即为没有格式化磁盘所致
(5)切换到highgo登录系统,执行安装
<code class=" hljs bash">>>>编辑.bash_profile,添加: <span class="hljs-keyword">export</span> HG_HOME=/home/highgo/hgdb</code>
注意:数据目录的选择,即将data目录置于共享磁盘中
(6)安装完成后,注销highgo,切换回root,执行关闭数据库服务、设置开机不自动启动数据库服务、卸载挂载的目录
<code class=" hljs vbnet">service hgdb-se2<span class="hljs-number">.0</span><span class="hljs-number">.4</span> <span class="hljs-keyword">stop</span> chkconfig hgdb-se2<span class="hljs-number">.0</span><span class="hljs-number">.4</span> <span class="hljs-keyword">off</span> umount /install/hgdb</code>
node2安装过程:
(1)创建目录(挂载点)
<code class=" hljs perl"><span class="hljs-keyword">mkdir</span> /install/hgdb -p</code>
(2)发现服务器端有磁盘共享,并登录
(3)挂载磁盘
注意:/dev/sdb为共享磁盘,在node1安装数据库时已经格式化并将data目录置于其下,此时只需要挂载即可看到data目录
(4)切换到highgo登录系统,执行安装
注意:不作为系统服务安装(这样安装时不会有data目录选项出现)
(5)注销highgo,切换回root,执行卸载挂载的目录
<code class=" hljs cmake">umount /<span class="hljs-keyword">install</span>/hgdb</code>
6、HA配置
(1)node1、node2安装
<code class=" hljs cmake">yum -y <span class="hljs-keyword">install</span> pacemaker corosync pcs</code>
(2)在一个节点配置文件,并将文件拷贝到另一节点(以node1为例)
<code class=" hljs ruby">密钥文件: corosync-keygen scp /etc/corosync/authkey root<span class="hljs-variable">@node1</span><span class="hljs-symbol">:/etc/corosync</span></code>
<code class=" hljs avrasm">corosync<span class="hljs-preprocessor">.conf</span>文件: cd /etc/corosync <span class="hljs-keyword">cp</span> corosync<span class="hljs-preprocessor">.conf</span><span class="hljs-preprocessor">.example</span> corosync<span class="hljs-preprocessor">.conf</span> vi corosync<span class="hljs-preprocessor">.conf</span></code>
<code class=" hljs bash">pacemaker服务启动脚本: <span class="hljs-built_in">cd</span> service.d vi pcmd</code>
<code class=" hljs vbnet">corosync、pacemaker服务启停: chkconfig corosync <span class="hljs-keyword">on</span> service corosync start chkcofig pacemaker <span class="hljs-keyword">off</span> servicepacemaker <span class="hljs-keyword">stop</span></code>
7、集群资源配置
<code class=" hljs sql">首先启动服务:service corosync <span class="hljs-operator"><span class="hljs-keyword">start</span> (node1、node2)</span></code>
查看集群状态:
在一个节点上完成资源的配置即可
<code class=" hljs lasso">任何情况集群资源继续运行 pcs property <span class="hljs-built_in">set</span> no<span class="hljs-attribute">-quorum</span><span class="hljs-attribute">-policy</span><span class="hljs-subst">=</span>ignore 禁用stonith pcs property <span class="hljs-built_in">set</span> stonith<span class="hljs-attribute">-enabled</span><span class="hljs-subst">=</span><span class="hljs-literal">false</span></code>
<code class=" hljs sql">配置vip pcs resource <span class="hljs-operator"><span class="hljs-keyword">create</span> vip ocf:heartbeat:IPaddr params ip=<span class="hljs-string">"192.168.100.222"</span> nic=<span class="hljs-string">"eth0"</span> cidr_netmask=<span class="hljs-string">"24"</span> op monitor <span class="hljs-keyword">interval</span>=<span class="hljs-number">20</span>s timeout=<span class="hljs-number">30</span>s</span></code>
查看集群状态
<code class=" hljs sql">配置sdisk(共享存储) pcs resource <span class="hljs-operator"><span class="hljs-keyword">create</span> sdisk ocf:heartbeat:Filesystem params device=<span class="hljs-string">"/dev/sdb"</span> directory=<span class="hljs-string">"/install/hgdb "</span> fstype=<span class="hljs-string">"ext4"</span> op <span class="hljs-keyword">start</span> timeout=<span class="hljs-number">60</span>s op stop timeout=<span class="hljs-number">60</span>s op monitor <span class="hljs-keyword">interval</span>=<span class="hljs-number">20</span>s timeout=<span class="hljs-number">60</span>s</span></code>
查看集群状态
<code class=" hljs sql">配置数据库服务 pcs resource <span class="hljs-operator"><span class="hljs-keyword">create</span> dbserver ocf:heartbeat:pgsql params pghost=<span class="hljs-number">192.168</span><span class="hljs-number">.100</span><span class="hljs-number">.222</span> pgport=<span class="hljs-number">5866</span> pgdba=highgo pgctl=/home/highgo/hgdb/bin/pg_ctl start_opt=<span class="hljs-string">"-D /install/hgdb/data"</span> psql=/home/highgo/hgdb/bin/psql pgdata=/install/hgdb/data monitor_user=highgo monitor_password=highgo123 op <span class="hljs-keyword">start</span> timeout=<span class="hljs-number">120</span>s <span class="hljs-keyword">interval</span>=<span class="hljs-number">120</span>s op stop timeout=<span class="hljs-number">120</span>s <span class="hljs-keyword">interval</span>=<span class="hljs-number">120</span>s op status timeout=<span class="hljs-number">60</span>s <span class="hljs-keyword">interval</span>=<span class="hljs-number">60</span>s</span></code>
<code class=" hljs oxygene">配置三个资源在一个组 pcs resource <span class="hljs-keyword">group</span> <span class="hljs-keyword">add</span> hgdb_group sdisk pcs resource <span class="hljs-keyword">group</span> <span class="hljs-keyword">add</span> hgdb_group vip pcs resource <span class="hljs-keyword">group</span> <span class="hljs-keyword">add</span> hgdb_group dbserver </code>
<code class=" hljs ocaml">配置资源在两节点中的优先级 pcs <span class="hljs-keyword">constraint</span> location sdisk prefers node1=<span class="hljs-number">50</span> pcs <span class="hljs-keyword">constraint</span> location sdisk prefers node2=<span class="hljs-number">40</span> pcs <span class="hljs-keyword">constraint</span> location vip prefers node1=<span class="hljs-number">50</span> pcs <span class="hljs-keyword">constraint</span> location vip prefers node2=<span class="hljs-number">40</span> pcs <span class="hljs-keyword">constraint</span> location dbserver prefers node1=<span class="hljs-number">50</span> pcs <span class="hljs-keyword">constraint</span> location dbserver prefers node2=<span class="hljs-number">40</span></code>
<code class=" hljs sql">配置资源在节点中的启动顺序 pcs constraint order <span class="hljs-operator"><span class="hljs-keyword">start</span> vip <span class="hljs-keyword">then</span> <span class="hljs-keyword">start</span> sdisk <span class="hljs-keyword">then</span> <span class="hljs-keyword">start</span> dbserver</span></code>
<code class=" hljs vbnet">配置psql文件(node1、node2) vi /usr/<span class="hljs-keyword">lib</span>/ocf/resource.d/heartbeat/pgsql</code>
需要确认的错误情况及解决方法:
node1重启corosync服务时,出现下面的状况,而node2可以重启
查看日志文件
切换到highgo用户重新启动停止了服务(之前安装完数据库停掉服务后有新修改postgresql.conf和pg_hba.conf文件,设置了远程访问),再重启corosync服务成功
查看集群状态
8、验证
(1)正常状态下
在node1用虚拟ip可访问数据库
查看共享盘挂载情况
(2)模拟node1崩溃
此时在node2能用虚拟ip访问数据库
集群状态
共享盘挂载
注意:
在配置前最好设置NetworkManager服务stop,更改system eth0为eth0因为配置vip时为eth0,怕会找不到设备,然后重启network服务

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
