一、 环境 1、架构图 650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/120F554M-0.jpg" title="111111111.png" alt="wKioL1XRzn6SRVMYAADM1onFESo308.jpg" /> 2、部署详细 10.10.17.26:27000(primary)10.10.17.27:27000(seco
一、环境
1、架构图
2、部署详细
10.10.17.26:27000 (primary) 10.10.17.27:27000 (secondary) 10.10.2.74:27000 (arbiter)
3、软件版本
mongdb :2.6.11 系统:centos 6.6
二、安装配置
1、安装见mongodb安装
2、撰写配置文件
vi /etc/mongod_27000.conf logpath=/data/mongodb/navy_db/log/mongod.log #mongodb日志文件 logappend=true #追加方式写日志文件 fork=true #后台运行 port=27000 #mongodb端口 dbpath=/data/mongodb/navy_db/db pidfilepath=/data/mongodb/navy_db/log/mongod.pid bind_ip=0.0.0.0 rest = true #开启web访问 journal = true #启用日志选项,MongoDB的数据操作将会写入到journal文件夹的文件里 oplogSize=2048 #同步操作记录文件大小(MB) replSet=dbset #副本集名称,同一个副本集,名称必须一致 auth=true #开启验证 keyFile=/data/mongodb/navy_db/password.key #key认证
3、生成keyfile文件
echo "c57a012cf2f8a8e20dd4b21a7fae48b3" >/data/mongodb/navy_db/password.key
4、设置keyfile权限,必须是600
chmod 600 /data/mongodb/navy_db/password.key
5、启动服务
ulimit -s 4096 && ulimit -m 16777216 & numactl --interleave=all /usr/bin/mongod -f /etc/mongod_27000.conf
PS:
在配置集群之前auth和keyFile先注释掉,待集群初始化完成,建立用户(从库上不需要建用户,当集群初始化完成会从主库上同步过来的,如果从库建了用户,集群初始化会报错,提示从库已有数据),然后打开,并重启服务让其生效
三、集群配置
#use到admin use admin 创建配置(dbset是集群名称,必须和配置文件中replSet的值一样) config = { _id:"dbset", members:[ ... ... {_id:1,host:"10.10.11.34:27000"}, ... ... {_id:2,host:"10.10.16.6:27000"} ] ... ... } #初始化集群 rs.initiate(config); #添加仲裁节点 rs.addArb("10.10.2.74:27000") #查看集群状态 rs.status()
PS:其他常用命令
#删除一个节点 rs.remove("10.10.2.74:27000") #查看集群配置信息 rs.conf() #查看当前谁是primary rs.isMaster() #查看主从延时 rs.printSlaveReplicationInfo() #查看rs相关命令 rs.help()
rs.status()结果说明
1. STARTUP:刚加入到复制集中,配置还未加载 2. STARTUP2:配置已加载完,初始化状态 3. RECOVERING:正在恢复,不适用读 4. ARBITER: 仲裁者 5. DOWN:节点不可到达 6. UNKNOWN:未获取其他节点状态而不知是什么状态,一般发生在只有两个成员的架构,脑裂 7. REMOVED:移除复制集 8. ROLLBACK:数据回滚,在回滚结束时,转移到RECOVERING或SECONDARY状态 9. FATAL:出错。查看日志grep “replSet FATAL”找出错原因,重新做同步 10. PRIMARY:主节点 11. SECONDARY:备份节点
四、建立用户(只能在primary节点上操作)
use admin db.addUser('admin','123456') #建立管理员账号 use navy_db #如果navy_db存在就进入库,如果不存在就建立navy_db库,空库show dbs是看不到的 db.addUser('navy_db_pro','123456') #建立navy_db的读写账号 db.addUser('navy_db_sel','123456',true) #建立navy_db的只读账号
五、重启集群
把auth和keyFile的注释去掉,arbiter、secondary、primary三个节点依次重启,让其生效
rs.status() 查看集群状态是否ok
PS:
1、从库默认是不可以读的,如果需要从库提供读业务,需要做一下设置
db.getMongo().setSlaveOk()
2、mongdb的客户端驱动支持这种架构,主库挂了,secondary提升为主,对于应用基本透明
client=MongoClient(“mongdb://navy_db_pro:123456@10.10.17.26:27000,10.10.17.27:27000/navy_db”

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi


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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
