前端技术
HTML
CSS
Javascript
前端框架和UI库
VUE
ReactJS
AngularJS
JQuery
NodeJS
JSON
Element-UI
Bootstrap
Material UI
服务端和客户端
Java
Python
PHP
Golang
Scala
Kotlin
Groovy
Ruby
Lua
.net
c#
c++
后端WEB和工程框架
SpringBoot
SpringCloud
Struts2
MyBatis
Hibernate
Tornado
Beego
Go-Spring
Go Gin
Go Iris
Dubbo
HessianRPC
Maven
Gradle
数据库
MySQL
Oracle
Mongo
中间件与web容器
Redis
MemCache
Etcd
Cassandra
Kafka
RabbitMQ
RocketMQ
ActiveMQ
Nacos
Consul
Tomcat
Nginx
Netty
大数据技术
Hive
Impala
ClickHouse
DorisDB
Greenplum
PostgreSQL
HBase
Kylin
Hadoop
Apache Pig
ZooKeeper
SeaTunnel
Sqoop
Datax
Flink
Spark
Mahout
数据搜索与日志
ElasticSearch
Apache Lucene
Apache Solr
Kibana
Logstash
数据可视化与OLAP
Apache Atlas
Superset
Saiku
Tesseract
系统与容器
Linux
Shell
Docker
Kubernetes
[System.IO命名空间]的搜索结果
这里是文章列表。热门标签的颜色随机变换,标签颜色没有特殊含义。
点击某个标签可搜索标签相关的文章。
点击某个标签可搜索标签相关的文章。
转载文章
...Multi-version Concurrency Control) 支持JSON和XML格式 Postgres-XL缺少的功能 内建的高可用机制 使用外部机制实现高可能,如:Corosync/Pacemaker 有未来功能提升的空间 增加节点/重新分片数据(re-shard)的简便性 数据重分布(redistribution)期间会锁表 可采用预分片(pre-shard)方式解决,在同台物理服务器上建立多个数据节点,每个节点存储一个数据分片。数据重分布时,将一些数据节点迁出即可 某些外键、唯一性约束功能 Postgres-XL架构 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-M9lFuEIP-1640133702200)(./assets/postgre-xl.jpg)] 基于开源项目Postgres-XC XL增加了MPP,允许数据节点间直接通讯,交换复杂跨节点关联查询相关数据信息,减少协调器负载。 多个协调器(Coordinator) 应用程序的数据库连入点 分析查询语句,生成执行计划 多个数据节点(DataNode) 实际的数据存储 数据自动打散分布到集群中各数据节点 本地执行查询 一个查询在所有相关节点上并行查询 全局事务管理器(GTM:Global Transaction Manager) 提供事务间一致性视图 部署GTM Proxy实例,以提高性能 Postgre-XL主要组件 GTM (Global Transaction Manager) - 全局事务管理器 GTM是Postgres-XL的一个关键组件,用于提供一致的事务管理和元组可见性控制。 GTM Standby GTM的备节点,在pgxc,pgxl中,GTM控制所有的全局事务分配,如果出现问题,就会导致整个集群不可用,为了增加可用性,增加该备用节点。当GTM出现问题时,GTM Standby可以升级为GTM,保证集群正常工作。 GTM-Proxy GTM需要与所有的Coordinators通信,为了降低压力,可以在每个Coordinator机器上部署一个GTM-Proxy。 Coordinator --协调器 协调器是应用程序到数据库的接口。它的作用类似于传统的PostgreSQL后台进程,但是协调器不存储任何实际数据。实际数据由数据节点存储。协调器接收SQL语句,根据需要获取全局事务Id和全局快照,确定涉及哪些数据节点,并要求它们执行(部分)语句。当向数据节点发出语句时,它与GXID和全局快照相关联,以便多版本并发控制(MVCC)属性扩展到集群范围。 Datanode --数据节点 用于实际存储数据。表可以分布在各个数据节点之间,也可以复制到所有数据节点。数据节点没有整个数据库的全局视图,它只负责本地存储的数据。接下来,协调器将检查传入语句,并制定子计划。然后,根据需要将这些数据连同GXID和全局快照一起传输到涉及的每个数据节点。数据节点可以在不同的会话中接收来自各个协调器的请求。但是,由于每个事务都是惟一标识的,并且与一致的(全局)快照相关联,所以每个数据节点都可以在其事务和快照上下文中正确执行。 Postgres-XL继承了PostgreSQL Postgres-XL是PostgreSQL的扩展并继承了其很多特性: 复杂查询 外键 触发器 视图 事务 MVCC(多版本控制) 此外,类似于PostgreSQL,用户可以通过多种方式扩展Postgres-XL,例如添加新的 数据类型 函数 操作 聚合函数 索引类型 过程语言 安装 环境说明 由于资源有限,gtm一台、另外两台身兼数职。 主机名 IP 角色 端口 nodename 数据目录 gtm 192.168.20.132 GTM 6666 gtm /nodes/gtm 协调器 5432 coord1 /nodes/coordinator xl1 192.168.20.133 数据节点 5433 node1 /nodes/pgdata gtm代理 6666 gtmpoxy01 /nodes/gtm_pxy1 协调器 5432 coord2 /nodes/coordinator xl2 192.168.20.134 数据节点 5433 node2 /nodes/pgdata gtm代理 6666 gtmpoxy02 /nodes/gtm_pxy2 要求 GNU make版本 3.8及以上版本 [root@pg ~] make --versionGNU Make 3.82Built for x86_64-redhat-linux-gnuCopyright (C) 2010 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. 需安装GCC包 需安装tar包 用于解压缩文件 默认需要GNU Readline library 其作用是可以让psql命令行记住执行过的命令,并且可以通过键盘上下键切换命令。但是可以通过--without-readline禁用这个特性,或者可以指定--withlibedit-preferred选项来使用libedit 默认使用zlib压缩库 可通过--without-zlib选项来禁用 配置hosts 所有主机上都配置 [root@xl2 11] cat /etc/hosts127.0.0.1 localhost192.168.20.132 gtm192.168.20.133 xl1192.168.20.134 xl2 关闭防火墙、Selinux 所有主机都执行 关闭防火墙: [root@gtm ~] systemctl stop firewalld.service[root@gtm ~] systemctl disable firewalld.service selinux设置: [root@gtm ~]vim /etc/selinux/config 设置SELINUX=disabled,保存退出。 This file controls the state of SELinux on the system. SELINUX= can take one of these three values: enforcing - SELinux security policy is enforced. permissive - SELinux prints warnings instead of enforcing. disabled - No SELinux policy is loaded.SELINUX=disabled SELINUXTYPE= can take one of three two values: targeted - Targeted processes are protected, minimum - Modification of targeted policy. Only selected processes are protected. mls - Multi Level Security protection. 安装依赖包 所有主机上都执行 yum install -y flex bison readline-devel zlib-devel openjade docbook-style-dsssl gcc 创建用户 所有主机上都执行 [root@gtm ~] useradd postgres[root@gtm ~] passwd postgres[root@gtm ~] su - postgres[root@gtm ~] mkdir ~/.ssh[root@gtm ~] chmod 700 ~/.ssh 配置SSH免密登录 仅仅在gtm节点配置如下操作: [root@gtm ~] su - postgres[postgres@gtm ~] ssh-keygen -t rsa[postgres@gtm ~] cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys[postgres@gtm ~] chmod 600 ~/.ssh/authorized_keys 将刚生成的认证文件拷贝到xl1到xl2中,使得gtm节点可以免密码登录xl1~xl2的任意一个节点: [postgres@gtm ~] scp ~/.ssh/authorized_keys postgres@xl1:~/.ssh/[postgres@gtm ~] scp ~/.ssh/authorized_keys postgres@xl2:~/.ssh/ 对所有提示都不要输入,直接enter下一步。直到最后,因为第一次要求输入目标机器的用户密码,输入即可。 下载源码 下载地址:https://www.postgres-xl.org/download/ [root@slave ~] ll postgres-xl-10r1.1.tar.gz-rw-r--r-- 1 root root 28121666 May 30 05:21 postgres-xl-10r1.1.tar.gz 编译、安装Postgres-XL 所有节点都安装,编译需要一点时间,最好同时进行编译。 [root@slave ~] tar xvf postgres-xl-10r1.1.tar.gz[root@slave ~] ./configure --prefix=/home/postgres/pgxl/[root@slave ~] make[root@slave ~] make install[root@slave ~] cd contrib/ --安装必要的工具,在gtm节点上安装即可[root@slave ~] make[root@slave ~] make install 配置环境变量 所有节点都要配置 进入postgres用户,修改其环境变量,开始编辑 [root@gtm ~]su - postgres[postgres@gtm ~]vi .bashrc --不是.bash_profile 在打开的文件末尾,新增如下变量配置: export PGHOME=/home/postgres/pgxlexport LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATHexport PATH=$PGHOME/bin:$PATH 按住esc,然后输入:wq!保存退出。输入以下命令对更改重启生效。 [postgres@gtm ~] source .bashrc --不是.bash_profile 输入以下语句,如果输出变量结果,代表生效 [postgres@gtm ~] echo $PGHOME 应该输出/home/postgres/pgxl代表生效 配置集群 生成pgxc_ctl.conf配置文件 [postgres@gtm ~] pgxc_ctl prepare/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxl/pgxc_ctl/pgxc_ctl_bash.ERROR: File "/home/postgres/pgxl/pgxc_ctl/pgxc_ctl.conf" not found or not a regular file. No such file or directoryInstalling pgxc_ctl_bash script as /home/postgres/pgxl/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxl/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxl/pgxc_ctl --configuration /home/postgres/pgxl/pgxc_ctl/pgxc_ctl.confFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxl/pgxc_ctl 配置pgxc_ctl.conf 新建/home/postgres/pgxc_ctl/pgxc_ctl.conf文件,编辑如下: 对着模板文件一个一个修改,否则会造成初始化过程出现各种神奇问题。 pgxcInstallDir=$PGHOMEpgxlDATA=$PGHOME/data pgxcOwner=postgres---- GTM Master -----------------------------------------gtmName=gtmgtmMasterServer=gtmgtmMasterPort=6666gtmMasterDir=$pgxlDATA/nodes/gtmgtmSlave=y Specify y if you configure GTM Slave. Otherwise, GTM slave will not be configured and all the following variables will be reset.gtmSlaveName=gtmSlavegtmSlaveServer=gtm value none means GTM slave is not available. Give none if you don't configure GTM Slave.gtmSlavePort=20001 Not used if you don't configure GTM slave.gtmSlaveDir=$pgxlDATA/nodes/gtmSlave Not used if you don't configure GTM slave.---- GTM-Proxy Master -------gtmProxyDir=$pgxlDATA/nodes/gtm_proxygtmProxy=y gtmProxyNames=(gtm_pxy1 gtm_pxy2) gtmProxyServers=(xl1 xl2) gtmProxyPorts=(6666 6666) gtmProxyDirs=($gtmProxyDir $gtmProxyDir) ---- Coordinators ---------coordMasterDir=$pgxlDATA/nodes/coordcoordNames=(coord1 coord2) coordPorts=(5432 5432) poolerPorts=(6667 6667) coordPgHbaEntries=(0.0.0.0/0)coordMasterServers=(xl1 xl2) coordMasterDirs=($coordMasterDir $coordMasterDir)coordMaxWALsernder=0 没设置备份节点,设置为0coordMaxWALSenders=($coordMaxWALsernder $coordMaxWALsernder) 数量保持和coordMasterServers一致coordSlave=n---- Datanodes ----------datanodeMasterDir=$pgxlDATA/nodes/dn_masterprimaryDatanode=xl1 主数据节点datanodeNames=(node1 node2)datanodePorts=(5433 5433) datanodePoolerPorts=(6668 6668) datanodePgHbaEntries=(0.0.0.0/0)datanodeMasterServers=(xl1 xl2)datanodeMasterDirs=($datanodeMasterDir $datanodeMasterDir)datanodeMaxWalSender=4datanodeMaxWALSenders=($datanodeMaxWalSender $datanodeMaxWalSender) 集群初始化,启动,停止 初始化 pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf init all 输出结果: /bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlStopping all the coordinator masters.Stopping coordinator master coord1.Stopping coordinator master coord2.pg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord1" does not existpg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord2" does not existDone.Stopping all the datanode masters.Stopping datanode master datanode1.Stopping datanode master datanode2.pg_ctl: PID file "/home/postgres/pgxc/nodes/datanode/datanode1/postmaster.pid" does not existIs server running?Done.Stop GTM masterwaiting for server to shut down.... doneserver stopped[postgres@gtm ~]$ echo $PGHOME/home/postgres/pgxl[postgres@gtm ~]$ ll /home/postgres/pgxl/pgxc/nodes/gtm/gtm.^C[postgres@gtm ~]$ pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf init all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlInitialize GTM masterERROR: target directory (/home/postgres/pgxc/nodes/gtm) exists and not empty. Skip GTM initilializationDone.Start GTM masterserver startingInitialize all the coordinator masters.Initialize coordinator master coord1.ERROR: target coordinator master coord1 is running now. Skip initilialization.Initialize coordinator master coord2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/coord/coord2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting coordinator master.Starting coordinator master coord1ERROR: target coordinator master coord1 is already running now. Skip initialization.Starting coordinator master coord22019-05-30 21:09:25.562 EDT [2148] LOG: listening on IPv4 address "0.0.0.0", port 54322019-05-30 21:09:25.562 EDT [2148] LOG: listening on IPv6 address "::", port 54322019-05-30 21:09:25.563 EDT [2148] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"2019-05-30 21:09:25.601 EDT [2149] LOG: database system was shut down at 2019-05-30 21:09:22 EDT2019-05-30 21:09:25.605 EDT [2148] LOG: database system is ready to accept connections2019-05-30 21:09:25.612 EDT [2156] LOG: cluster monitor startedDone.Initialize all the datanode masters.Initialize the datanode master datanode1.Initialize the datanode master datanode2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode1 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting all the datanode masters.Starting datanode master datanode1.WARNING: datanode master datanode1 is running now. Skipping.Starting datanode master datanode2.2019-05-30 21:09:33.352 EDT [2404] LOG: listening on IPv4 address "0.0.0.0", port 154322019-05-30 21:09:33.352 EDT [2404] LOG: listening on IPv6 address "::", port 154322019-05-30 21:09:33.355 EDT [2404] LOG: listening on Unix socket "/tmp/.s.PGSQL.15432"2019-05-30 21:09:33.392 EDT [2404] LOG: redirecting log output to logging collector process2019-05-30 21:09:33.392 EDT [2404] HINT: Future log output will appear in directory "pg_log".Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done.[postgres@gtm ~]$ pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf stop all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlStopping all the coordinator masters.Stopping coordinator master coord1.Stopping coordinator master coord2.pg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord1" does not existDone.Stopping all the datanode masters.Stopping datanode master datanode1.Stopping datanode master datanode2.pg_ctl: PID file "/home/postgres/pgxc/nodes/datanode/datanode1/postmaster.pid" does not existIs server running?Done.Stop GTM masterwaiting for server to shut down.... doneserver stopped[postgres@gtm ~]$ pgxc_ctl/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlPGXC monitor allNot running: gtm masterRunning: coordinator master coord1Not running: coordinator master coord2Running: datanode master datanode1Not running: datanode master datanode2PGXC stop coordinator master coord1Stopping coordinator master coord1.pg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord1" does not existDone.PGXC stop datanode master datanode1Stopping datanode master datanode1.pg_ctl: PID file "/home/postgres/pgxc/nodes/datanode/datanode1/postmaster.pid" does not existIs server running?Done.PGXC monitor allNot running: gtm masterRunning: coordinator master coord1Not running: coordinator master coord2Running: datanode master datanode1Not running: datanode master datanode2PGXC monitor allNot running: gtm masterNot running: coordinator master coord1Not running: coordinator master coord2Not running: datanode master datanode1Not running: datanode master datanode2PGXC exit[postgres@gtm ~]$ pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf init all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlInitialize GTM masterERROR: target directory (/home/postgres/pgxc/nodes/gtm) exists and not empty. Skip GTM initilializationDone.Start GTM masterserver startingInitialize all the coordinator masters.Initialize coordinator master coord1.Initialize coordinator master coord2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/coord/coord1 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/coord/coord2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting coordinator master.Starting coordinator master coord1Starting coordinator master coord22019-05-30 21:13:03.998 EDT [25137] LOG: listening on IPv4 address "0.0.0.0", port 54322019-05-30 21:13:03.998 EDT [25137] LOG: listening on IPv6 address "::", port 54322019-05-30 21:13:04.000 EDT [25137] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"2019-05-30 21:13:04.038 EDT [25138] LOG: database system was shut down at 2019-05-30 21:13:00 EDT2019-05-30 21:13:04.042 EDT [25137] LOG: database system is ready to accept connections2019-05-30 21:13:04.049 EDT [25145] LOG: cluster monitor started2019-05-30 21:13:04.020 EDT [2730] LOG: listening on IPv4 address "0.0.0.0", port 54322019-05-30 21:13:04.020 EDT [2730] LOG: listening on IPv6 address "::", port 54322019-05-30 21:13:04.021 EDT [2730] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"2019-05-30 21:13:04.057 EDT [2731] LOG: database system was shut down at 2019-05-30 21:13:00 EDT2019-05-30 21:13:04.061 EDT [2730] LOG: database system is ready to accept connections2019-05-30 21:13:04.062 EDT [2738] LOG: cluster monitor startedDone.Initialize all the datanode masters.Initialize the datanode master datanode1.Initialize the datanode master datanode2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode1 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting all the datanode masters.Starting datanode master datanode1.Starting datanode master datanode2.2019-05-30 21:13:12.077 EDT [25392] LOG: listening on IPv4 address "0.0.0.0", port 154322019-05-30 21:13:12.077 EDT [25392] LOG: listening on IPv6 address "::", port 154322019-05-30 21:13:12.079 EDT [25392] LOG: listening on Unix socket "/tmp/.s.PGSQL.15432"2019-05-30 21:13:12.114 EDT [25392] LOG: redirecting log output to logging collector process2019-05-30 21:13:12.114 EDT [25392] HINT: Future log output will appear in directory "pg_log".2019-05-30 21:13:12.079 EDT [2985] LOG: listening on IPv4 address "0.0.0.0", port 154322019-05-30 21:13:12.079 EDT [2985] LOG: listening on IPv6 address "::", port 154322019-05-30 21:13:12.081 EDT [2985] LOG: listening on Unix socket "/tmp/.s.PGSQL.15432"2019-05-30 21:13:12.117 EDT [2985] LOG: redirecting log output to logging collector process2019-05-30 21:13:12.117 EDT [2985] HINT: Future log output will appear in directory "pg_log".Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done. 启动 pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf start all 关闭 pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf stop all 查看集群状态 [postgres@gtm ~]$ pgxc_ctl monitor all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlRunning: gtm masterRunning: coordinator master coord1Running: coordinator master coord2Running: datanode master datanode1Running: datanode master datanode2 配置集群信息 分别在数据节点、协调器节点上分别执行以下命令: 注:本节点只执行修改操作即可(alert node),其他节点执行创建命令(create node)。因为本节点已经包含本节点的信息。 create node coord1 with (type=coordinator,host=xl1, port=5432);create node coord2 with (type=coordinator,host=xl2, port=5432);alter node coord1 with (type=coordinator,host=xl1, port=5432);alter node coord2 with (type=coordinator,host=xl2, port=5432);create node datanode1 with (type=datanode, host=xl1,port=15432,primary=true,PREFERRED);create node datanode2 with (type=datanode, host=xl2,port=15432);alter node datanode1 with (type=datanode, host=xl1,port=15432,primary=true,PREFERRED);alter node datanode2 with (type=datanode, host=xl2,port=15432);select pgxc_pool_reload(); 分别登陆数据节点、协调器节点验证 postgres= select from pgxc_node;node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id-----------+-----------+-----------+-----------+----------------+------------------+-------------coord1 | C | 5432 | xl1 | f | f | 1885696643coord2 | C | 5432 | xl2 | f | f | -1197102633datanode2 | D | 15432 | xl2 | f | f | -905831925datanode1 | D | 15432 | xl1 | t | f | 888802358(4 rows) 测试 插入数据 在数据节点1,执行相关操作。 通过协调器端口登录PG [postgres@xl1 ~]$ psql -p 5432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= create database lei;CREATE DATABASEpostgres= \c lei;You are now connected to database "lei" as user "postgres".lei= create table test1(id int,name text);CREATE TABLElei= insert into test1(id,name) select generate_series(1,8),'测试';INSERT 0 8lei= select from test1;id | name----+------1 | 测试2 | 测试5 | 测试6 | 测试8 | 测试3 | 测试4 | 测试7 | 测试(8 rows) 注:默认创建的表为分布式表,也就是每个数据节点值存储表的部分数据。关于表类型具体说明,下面有说明。 通过15432端口登录数据节点,查看数据 有5条数据 [postgres@xl1 ~]$ psql -p 15432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= \c lei;You are now connected to database "lei" as user "postgres".lei= select from test1;id | name----+------1 | 测试2 | 测试5 | 测试6 | 测试8 | 测试(5 rows) 登录到节点2,查看数据 有3条数据 [postgres@xl2 ~]$ psql -p15432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= \c lei;You are now connected to database "lei" as user "postgres".lei= select from test1;id | name----+------3 | 测试4 | 测试7 | 测试(3 rows) 两个节点的数据加起来整个8条,没有问题。 至此Postgre-XL集群搭建完成。 创建数据库、表时可能会出现以下错误: ERROR: Failed to get pooled connections 是因为pg_hba.conf配置不对,所有节点加上host all all 192.168.20.0/0 trust并重启集群即可。 ERROR: No Datanode defined in cluster 首先确认是否创建了数据节点,也就是create node相关的命令。如果创建了则执行select pgxc_pool_reload();使其生效即可。 集群管理与应用 表类型说明 REPLICATION表:各个datanode节点中,表的数据完全相同,也就是说,插入数据时,会分别在每个datanode节点插入相同数据。读数据时,只需要读任意一个datanode节点上的数据。 建表语法: CREATE TABLE repltab (col1 int, col2 int) DISTRIBUTE BY REPLICATION; DISTRIBUTE :会将插入的数据,按照拆分规则,分配到不同的datanode节点中存储,也就是sharding技术。每个datanode节点只保存了部分数据,通过coordinate节点可以查询完整的数据视图。 CREATE TABLE disttab(col1 int, col2 int, col3 text) DISTRIBUTE BY HASH(col1); 模拟数据插入 任意登录一个coordinate节点进行建表操作 [postgres@gtm ~]$ psql -h xl1 -p 5432 -U postgrespostgres= INSERT INTO disttab SELECT generate_series(1,100), generate_series(101, 200), 'foo';INSERT 0 100postgres= INSERT INTO repltab SELECT generate_series(1,100), generate_series(101, 200);INSERT 0 100 查看数据分布结果: DISTRIBUTE表分布结果 postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;xc_node_id | count ------------+-------1148549230 | 42-927910690 | 58(2 rows) REPLICATION表分布结果 postgres= SELECT count() FROM repltab;count -------100(1 row) 查看另一个datanode2中repltab表结果 [postgres@datanode2 pgxl9.5]$ psql -p 15432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= SELECT count() FROM repltab;count -------100(1 row) 结论:REPLICATION表中,datanode1,datanode2中表是全部数据,一模一样。而DISTRIBUTE表,数据散落近乎平均分配到了datanode1,datanode2节点中。 新增数据节点与数据重分布 在线新增节点、并重新分布数据。 新增datanode节点 在gtm集群管理节点上执行pgxc_ctl命令 [postgres@gtm ~]$ pgxc_ctl/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.confFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlPGXC 在服务器xl3上,新增一个master角色的datanode节点,名称是datanode3 端口号暂定5430,pool master暂定6669 ,指定好数据目录位置,从两个节点升级到3个节点,之后要写3个none none应该是datanodeSpecificExtraConfig或者datanodeSpecificExtraPgHba配置PGXC add datanode master datanode3 xl3 15432 6671 /home/postgres/pgxc/nodes/datanode/datanode3 none none none 等待新增完成后,查询集群节点状态: postgres= select from pgxc_node;node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id-----------+-----------+-----------+-----------+----------------+------------------+-------------datanode1 | D | 15432 | xl1 | t | f | 888802358datanode2 | D | 15432 | xl2 | f | f | -905831925datanode3 | D | 15432 | xl3 | f | f | -705831925coord1 | C | 5432 | xl1 | f | f | 1885696643coord2 | C | 5432 | xl2 | f | f | -1197102633(4 rows) 节点新增完毕 数据重新分布 由于新增节点后无法自动完成数据重新分布,需要手动操作。 DISTRIBUTE表分布在了node1,node2节点上,如下: postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;xc_node_id | count ------------+-------1148549230 | 42-927910690 | 58(2 rows) 新增一个节点后,将sharding表数据重新分配到三个节点上,将repl表复制到新节点 重分布sharding表postgres= ALTER TABLE disttab ADD NODE (datanode3);ALTER TABLE 复制数据到新节点postgres= ALTER TABLE repltab ADD NODE (datanode3);ALTER TABLE 查看新的数据分布: postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;xc_node_id | count ------------+--------700122826 | 36-927910690 | 321148549230 | 32(3 rows) 登录datanode3(新增的时候,放在了xl3服务器上,端口15432)节点查看数据: [postgres@gtm ~]$ psql -h xl3 -p 15432 -U postgrespsql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= select count() from repltab;count -------100(1 row) 很明显,通过 ALTER TABLE tt ADD NODE (dn)命令,可以将DISTRIBUTE表数据重新分布到新节点,重分布过程中会中断所有事务。可以将REPLICATION表数据复制到新节点。 从datanode节点中回收数据 postgres= ALTER TABLE disttab DELETE NODE (datanode3);ALTER TABLEpostgres= ALTER TABLE repltab DELETE NODE (datanode3);ALTER TABLE 删除数据节点 Postgresql-XL并没有检查将被删除的datanode节点是否有replicated/distributed表的数据,为了数据安全,在删除之前需要检查下被删除节点上的数据,有数据的话,要回收掉分配到其他节点,然后才能安全删除。删除数据节点分为四步骤: 1.查询要删除节点dn3的oid postgres= SELECT oid, FROM pgxc_node;oid | node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id -------+-----------+-----------+-----------+-----------+----------------+------------------+-------------11819 | coord1 | C | 5432 | datanode1 | f | f | 188569664316384 | coord2 | C | 5432 | datanode2 | f | f | -119710263316385 | node1 | D | 5433 | datanode1 | f | t | 114854923016386 | node2 | D | 5433 | datanode2 | f | f | -92791069016397 | dn3 | D | 5430 | datanode1 | f | f | -700122826(5 rows) 2.查询dn3对应的oid中是否有数据 testdb= SELECT FROM pgxc_class WHERE nodeoids::integer[] @> ARRAY[16397];pcrelid | pclocatortype | pcattnum | pchashalgorithm | pchashbuckets | nodeoids ---------+---------------+----------+-----------------+---------------+-------------------16388 | H | 1 | 1 | 4096 | 16397 16385 1638616394 | R | 0 | 0 | 0 | 16397 16385 16386(2 rows) 3.有数据的先回收数据 postgres= ALTER TABLE disttab DELETE NODE (dn3);ALTER TABLEpostgres= ALTER TABLE repltab DELETE NODE (dn3);ALTER TABLEpostgres= SELECT FROM pgxc_class WHERE nodeoids::integer[] @> ARRAY[16397];pcrelid | pclocatortype | pcattnum | pchashalgorithm | pchashbuckets | nodeoids ---------+---------------+----------+-----------------+---------------+----------(0 rows) 4.安全删除dn3 PGXC$ remove datanode master dn3 clean 故障节点FAILOVER 1.查看当前集群状态 [postgres@gtm ~]$ psql -h xl1 -p 5432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= SELECT oid, FROM pgxc_node;oid | node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id-------+-----------+-----------+-----------+-----------+----------------+------------------+-------------11739 | coord1 | C | 5432 | xl1 | f | f | 188569664316384 | coord2 | C | 5432 | xl2 | f | f | -119710263316387 | datanode2 | D | 15432 | xl2 | f | f | -90583192516388 | datanode1 | D | 15432 | xl1 | t | t | 888802358(4 rows) 2.模拟datanode1节点故障 直接关闭即可 PGXC stop -m immediate datanode master datanode1Stopping datanode master datanode1.Done. 3.测试查询 只要查询涉及到datanode1上的数据,那么该查询就会报错 postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;WARNING: failed to receive file descriptors for connectionsERROR: Failed to get pooled connectionsHINT: This may happen because one or more nodes are currently unreachable, either because of node or network failure.Its also possible that the target node may have hit the connection limit or the pooler is configured with low connections.Please check if all nodes are running fine and also review max_connections and max_pool_size configuration parameterspostgres= SELECT xc_node_id, FROM disttab WHERE col1 = 3;xc_node_id | col1 | col2 | col3------------+------+------+-------905831925 | 3 | 103 | foo(1 row) 测试发现,查询范围如果涉及到故障的node1节点,会报错,而查询的数据范围不在node1上的话,仍然可以查询。 4.手动切换 要想切换,必须要提前配置slave节点。 PGXC$ failover datanode node1 切换完成后,查询集群 postgres= SELECT oid, FROM pgxc_node;oid | node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id -------+-----------+-----------+-----------+-----------+----------------+------------------+-------------11819 | coord1 | C | 5432 | datanode1 | f | f | 188569664316384 | coord2 | C | 5432 | datanode2 | f | f | -119710263316386 | node2 | D | 15432 | datanode2 | f | f | -92791069016385 | node1 | D | 15433 | datanode2 | f | t | 1148549230(4 rows) 发现datanode1节点的ip和端口都已经替换为配置的slave了。 本篇文章为转载内容。原文链接:https://blog.csdn.net/qianglei6077/article/details/94379331。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-01-30 11:09:03
95
转载
转载文章
...nuc/sw/action/DocDownloadAction.java package nuc.sw.action;import java.io.InputStream;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class DocDownloadAction extends ActionSupport { private String downPath;//返回InputStream流方法public InputStream getInputStream() throws Exception{ downPath = new String(downPath.getBytes("ISO8859-1"),"utf-8");//默认从WebAPP根目录下取资源return ServletActionContext.getServletContext().getResourceAsStream(downPath);}public String getDownPath(){return downPath;}public void setDownPath(String downPath){this.downPath=downPath;}public String getDownloadFileName(){//downPath.subString是截取downPath的一部分String downFileName=downPath.substring(7);try{downFileName = new String(downFileName.getBytes("iso8859-1"),"utf-8");//downFileName=new String(downFileName.getBytes(),"utf-8");}catch(Exception e){e.printStackTrace();}return downFileName;}@Overridepublic String execute() throws Exception { return SUCCESS;} } /20171105_shiyan_upanddown/src/nuc/sw/action/DocUploadAction.java package nuc.sw.action;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.util.Date;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class DocUploadAction extends ActionSupport {private String name;private File[] upload;private String[] uploadContentType;private String[] uploadFileName;private String savePath;private Date createTime;public String getName() {return name;}public void setName(String name) {this.name = name;}public File[] getUpload() {return upload;}public void setUpload(File[] upload) {this.upload = upload;}public String[] getUploadContentType() {return uploadContentType;}public void setUploadContentType(String[] uploadContentType) {this.uploadContentType = uploadContentType;}public String[] getUploadFileName() {return uploadFileName;}public void setUploadFileName(String[] uploadFileName) {this.uploadFileName = uploadFileName;}public String getSavePath() {return savePath;}public void setSavePath(String savePath) {this.savePath = savePath;}public Date getCreateTime(){ createTime=new Date();return createTime;}public static void copy(File source,File target){ InputStream inputStream=null;OutputStream outputStream=null;try{inputStream=new BufferedInputStream(new FileInputStream(source));outputStream=new BufferedOutputStream(new FileOutputStream(target));byte[] buffer=new byte[1024];int length=0;while((length=inputStream.read(buffer))>0){outputStream.write(buffer, 0, length);} }catch(Exception e){e.printStackTrace();}finally{if(null!=inputStream){try {inputStream.close();} catch (IOException e2) {e2.printStackTrace();} }if(null!=outputStream){try{outputStream.close();}catch(Exception e2){e2.printStackTrace();} }} }@Overridepublic String execute() throws Exception { for(int i=0;i<upload.length;i++){ String path=ServletActionContext.getServletContext().getRealPath(this.getSavePath())+"\\"+this.uploadFileName[i];File target=new File(path);copy(this.upload[i],target);}return SUCCESS;} } /20171105_shiyan_upanddown/src/nuc/sw/action/LoginAction.java package nuc.sw.action;import java.util.regex.Pattern;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {//属性驱动校验private String username;private String password;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}//手动检验@Overridepublic void validate() {// TODO Auto-generated method stub//进行数据校验,长度6~15位 if(username.trim().length()<6||username.trim().length()>15||username==null) {this.addFieldError("username", "用户名长度不合法!");}if(password.trim().length()<6||password.trim().length()>15||password==null) {this.addFieldError("password", "密码长度不合法!");} }//登陆业务逻辑public String loginMethod() {if(username.equals("chenghaoran")&&password.equals("12345678")) {ActionContext.getContext().getSession().put("user", username);return "loginOK";}else {this.addFieldError("err","用户名或密码不正确!");return "loginFail";} }//手动校验validateXxxpublic void validateLoginMethod() {//使用正则校验if(username==null||username.trim().equals("")) {this.addFieldError("username","用户名不能为空!");}else {if(!Pattern.matches("[a-zA-Z]{6,15}", username.trim())) {this.addFieldError("username", "用户名格式错误!");} }if(password==null||password.trim().equals("")) {this.addFieldError("password","密码不能为空!");}else {if(!Pattern.matches("\\d{6,15}", password.trim())) {this.addFieldError("password", "密码格式错误!");} }} } /20171105_shiyan_upanddown/src/nuc/sw/interceptor/LoginInterceptor.java package nuc.sw.interceptor;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class LoginInterceptor extends AbstractInterceptor {@Overridepublic String intercept(ActionInvocation arg0) throws Exception {// TODO Auto-generated method stub//判断是否登陆,通过ActionContext访问SessionActionContext ac=arg0.getInvocationContext();String username=(String)ac.getSession().get("user");if(username!=null&&username.equals("chenghaoran")) {return arg0.invoke();//放行}else {((ActionSupport)arg0.getAction()).addActionError("请先登录!");return Action.LOGIN;} }} /20171105_shiyan_upanddown/src/struts.xml <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN""http://struts.apache.org/dtds/struts-2.1.7.dtd"><struts><constant name="struts.i18n.encoding" value="utf-8"/><package name="default" extends="struts-default"><interceptors><interceptor name="login" class="nuc.sw.interceptor.LoginInterceptor"></interceptor></interceptors> <action name="docUpload" class="nuc.sw.action.DocUploadAction"><!-- 使用fileUpload拦截器 --><interceptor-ref name="fileUpload"><!-- 指定允许上传的文件大小最大为50000字节 --><param name="maximumSize">50000</param></interceptor-ref><!-- 配置默认系统拦截器栈 --><interceptor-ref name="defaultStack"/><!-- param子元素配置了DocUploadAction类中savePath属性值为/upload --><param name="savePath">/upload</param><result>/showFile.jsp</result><!-- 指定input逻辑视图,即不符合上传要求,被fileUpload拦截器拦截后,返回的视图页面 --><result name="input">/uploadFile.jsp</result></action> <action name="docDownload" class="nuc.sw.action.DocDownloadAction"><!-- 指定结果类型为stream --><result type="stream"><!-- 指定下载文件的文件类型 text/plain表示纯文本 --><param name="contentType">application/msword,text/plain</param><!-- 指定下载文件的入口输入流 --><param name="inputName">inputStream</param><!-- 指定下载文件的处理方式与文件保存名 attachment表示以附件形式下载,也可以用inline表示内联即在浏览器中直接显示,默认值为inline --><param name="contentDisposition">attachment;filename="${downloadFileName}"</param><!-- 指定下载文件的缓冲区大小,默认为1024 --><param name="bufferSize">40960</param></result></action><action name="loginAction" class="nuc.sw.action.LoginAction" method="loginMethod"><result name="loginOK">/uploadFile.jsp</result><result name="loginFail">/login.jsp</result><result name="input">/login.jsp</result></action> </package></struts> /20171105_shiyan_upanddown/WebContent/login.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>登录页</title><s:head/></head><body><s:actionerror/><s:fielderror fieldName="err"></s:fielderror><s:form action="loginAction" method="post"> <s:textfield label="用户名" name="username"></s:textfield><s:password label="密码" name="password"></s:password><s:submit value="登陆"></s:submit></s:form></body></html> /20171105_shiyan_upanddown/WebContent/showFile.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>显示上传文档</title></head><body><center><font style="font-size:18px;color:red">上传者:<s:property value="name"/></font><table width="45%" cellpadding="0" cellspacing="0" border="1"><tr><th>文件名称</th><th>上传者</th><th>上传时间</th></tr><s:iterator value="uploadFileName" status="st" var="doc"><tr><td align="center"><a href="docDownload.action?downPath=upload/<s:property value="doc"/>"><s:property value="doc"/> </a></td><td align="center"><s:property value="name"/></td><td align="center"><s:date name="createTime" format="yyyy-MM-dd HH:mm:ss"/></td></tr></s:iterator></table></center></body></html> /20171105_shiyan_upanddown/WebContent/uploadFile.jsp <%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>多文件上传</title></head><body><center><s:form action="docUpload" method="post" enctype="multipart/form-data"><s:textfield name="name" label="姓名" size="20"/><s:file name="upload" label="选择文档" size="20"/><s:file name="upload" label="选择文档" size="20"/><s:file name="upload" label="选择文档" size="20"/><s:submit value="确认上传" align="center"/></s:form></center></body></html> 本篇文章为转载内容。原文链接:https://blog.csdn.net/qq_34101492/article/details/78811741。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-11-12 20:53:42
141
转载
Docker
...核,但拥有独立的用户空间,从而实现高效、快速且资源占用少的应用部署和运行环境。 Docker run命令 , docker run是Docker CLI(命令行界面)中的一个核心命令,用于创建并启动一个新的Docker容器。当执行该命令时,用户可以指定容器使用的镜像、容器运行时的配置选项以及命名容器等信息。例如,在文中提到的docker run --name my-container docker-image命令,就是用来基于特定的docker-image创建并启动一个名为my-container的新容器。
2023-07-24 13:07:20
782
软件工程师
Docker
...括X Window System和Wayland)的工作原理,将有助于在遇到类似问题时迅速定位原因并找到针对性的解决方案。
2023-09-04 23:41:28
583
电脑达人
转载文章
...23年初,Azul Systems等第三方供应商仍为Java 8提供长期支持,企业用户可根据自身需求选择这些长期支持版以获取必要的安全更新和修复。同时,Oracle强烈推荐开发者和用户迁移到Java 17 LTS(长期支持)版本,该版本不仅具有最新的功能特性,还承诺在未来数年内提供关键的安全性和稳定性更新。 此外,在处理Java环境时,应充分了解操作系统层面的安全最佳实践。例如,对于不再使用的旧版Java,遵循上述命令行卸载步骤进行彻底清理,可以避免潜在的安全风险和磁盘空间浪费。另外,Apple早在多年前就已在Safari浏览器中禁用了NPAPI插件支持,这意味着Java Applet在现代Mac系统上的应用已十分有限,因此移除JavaAppletPlugin.plugin等相关组件显得更为必要。 总之,掌握有效管理Java环境的方法至关重要,这包括但不限于跟踪Java版本更新、及时淘汰不再维护的旧版Java、以及确保系统中仅保留必要且安全的Java组件。通过紧跟业界动态并采取针对性的措施,用户可以在享受Java带来的便利的同时,保障其设备及数据的安全。
2023-10-10 18:15:40
86
转载
Impala
...uted File System) , HDFS是Hadoop项目的核心子项目之一,它提供了一个高度容错性的分布式文件系统,能够支持超大文件存储并运行在廉价硬件上。在文章中提到,用户可以先将大文件压缩后上传至HDFS,再从HDFS加载到Impala中,这样可以显著减少传输时间并降低对网络带宽的需求。 数据分区(Partitioning) , 在数据库和大数据处理领域中,数据分区是一种优化技术,通过将大型表按照一定规则(例如按日期、地区或其他业务关键字段)划分为多个小块(称为分区)。在Impala中使用数据分区功能,可以根据查询条件直接定位到相关分区,从而提高查询和数据操作的速度。例如,在文章中展示的示例中,通过创建一个基于年、月、日分区的表,可以加速数据导入导出以及查询性能。
2023-10-21 15:37:24
512
梦幻星空-t
Hadoop
...式的大脑和海量的存储空间,简直就是处理那些数据海洋的救星,让我们的工作变得又快又顺溜,轻松应对那些看似没完没了的数据挑战。让我们一起深入了解一下如何利用Hadoop来处理大量图像数据。 二、Hadoop简介 Hadoop,源自Apache项目,是一个用于处理大规模数据集的并行计算框架。它由两个核心组件——Hadoop Distributed File System (HDFS) 和 MapReduce 构成。HDFS就像个超级能吃的硬盘大胃王,不管数据量多大,都能嗖嗖嗖地读写,而且就算有点小闪失,它也能自我修复,超级可靠。而MapReduce这家伙,就是那种能把大任务拆成一小块一小块的,然后召集一堆电脑小分队,一块儿并肩作战,最后把所有答案汇总起来的聪明工头。 三、Hadoop与图像数据处理 1. 数据采集与存储 首先,我们需要将大量的图像数据上传到HDFS。你可以轻松地用一个酷酷的命令,就像在玩电脑游戏一样,输入"hadoop fs -put",就能把东西上传到Hadoop里头,操作简单得跟复制粘贴似的!例如: shell hadoop fs -put /local/images/ /user/hadoop/images/ 这里,/local/images/是本地文件夹,/user/hadoop/images/是HDFS中的目标目录。 2. 图像预处理 在处理图像数据前,可能需要进行一些预处理,如压缩、格式转换等。Hadoop的Pig或Hive可以方便地编写SQL-like查询来操作这些数据,如下所示: sql A = LOAD '/user/hadoop/images' USING PigStorage(':'); B = FILTER A BY size(A) > 1000; // 过滤出大于1MB的图像 STORE B INTO '/user/hadoop/preprocessed'; 3. 特征提取与分析 使用Hadoop的MapReduce,我们可以并行计算每个图像的特征,如颜色直方图、纹理特征等。以下是一个简单的MapReduce任务示例: java public class ImageFeatureMapper extends Mapper { @Override protected void map(LongWritable key, Text value, Context context) { // 图像处理逻辑,生成特征值 int[] feature = processImage(value.toString()); context.write(new Text(featureToString(feature)), new IntWritable(1)); } } public class ImageFeatureReducer extends Reducer { @Override protected void reduce(Text key, Iterable values, Context context) { int sum = 0; for (IntWritable val : values) { sum += val.get(); } context.write(key, new IntWritable(sum)); } } 4. 结果聚合与可视化 最后,我们将所有图像的特征值汇总,进行统计分析,甚至可以进一步使用Hadoop的Mahout库进行聚类或分类。例如,计算平均颜色直方图: java final ReduceTask reducer = job.getReducer(); reducer.setNumReduceTasks(1); 然后,用Matplotlib这样的可视化库,将结果呈现出来,便于理解和解读。 四、总结与展望 Hadoop凭借其出色的性能和易用性,为我们处理大量图像数据提供了有力支持。你知道吗,随着深度学习这家伙越来越火,Hadoop这老伙计可能得找个新拍档,比如Spark,才能一起搞定那些高难度的图片数据分析任务,毕竟单打独斗有点力不从心了。不过呢,Hadoop这家伙绝对是咱们面对海量数据时的首选英雄,特别是在刚开始那会儿,简直就是数据难题的救星,让咱们在信息的汪洋大海里也能轻松应对,游得畅快。
2024-04-03 10:56:59
440
时光倒流
Hadoop
...uted File System)提供高容错性、高扩展性的分布式文件系统,以及MapReduce编程模型进行大规模数据处理。 HDFS (Hadoop Distributed File System) , 作为Hadoop的核心组件之一,HDFS是一种设计用于在商用硬件集群上运行的应用程序的数据存储系统。它将大文件分割成多个块,并将这些块分布在整个集群的节点上,从而实现数据的分布式存储与访问,提供高容错性和高吞吐量的数据服务。 差异备份 , 差异备份是数据备份策略的一种,只针对自上次完全备份或增量备份以来发生改变的数据进行备份,而不是备份所有数据。在Hadoop环境中,可以使用如Hadoop DistCp等工具来执行差异备份操作,以减少备份所需的时间和存储空间,提高备份效率。 Hadoop DistCp , DistCp是Hadoop提供的一个工具,全称为Distributed Copy,用于在Hadoop集群内部或跨集群之间高效地复制大量数据。该工具能够并行地从源目录复制数据到目标目录,并支持各种复制策略,包括完全备份和差异备份,以满足不同的数据迁移和备份需求。 点对点恢复 , 在Hadoop中,点对点恢复是指直接从原始数据存储位置进行数据恢复的过程,无需经过其他中间环节。例如,使用Hadoop fsck工具检查并修复HDFS中的数据错误,一旦发现损坏或丢失的块,可以直接从其他副本节点获取数据进行恢复,适用于单个节点故障情况下的快速恢复。
2023-09-08 08:01:47
401
时光倒流-t
Flink
...reamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.setStateBackend(new KafkaStateBackend("localhost:2181")); 在这个例子中,由于没有提供 ZooKeeper 配置,所以状态后端初始化会失败。 2. 状态后端资源不足 如果我们的服务器内存或磁盘空间不足,那么也可能导致状态后端初始化失败。这是因为状态后端需要在服务器上占用一定的资源来存储和管理任务状态。 三、如何解决状态后端初始化错误? 1. 检查并修正状态后端配置 首先,我们需要检查我们的 Flink 作业配置是否正确。具体来说,我们需要确保我们指定了正确的状态后端类型和参数。同时,我们也需要确保我们的服务器有足够的资源来支持状态后端。 2. 增加服务器资源 如果我们的服务器资源不足,那么我们可以考虑增加服务器资源来解决这个问题。简单来说,我们可以通过给服务器“硬件”升级换代,调整服务器的内部设置,让它运行得更加流畅,这两种方法就能有效地提升服务器的整体性能。就像是给电脑换个更强悍的“心脏”和更聪明的“大脑”,让它的表现力蹭蹭上涨。 3. 使用其他状态后端 最后,如果以上方法都无法解决问题,那么我们可以考虑更换状态后端。Flink 提供了多种状态后端选项,每种后端都有其优点和缺点。我们需要根据我们的需求和环境选择最适合的状态后端。 总结: 在使用 Flink 处理大数据时,我们可能会遇到各种各样的问题,其中包括状态后端初始化错误。本文深入讨论了这个错误的原因以及如何解决。通过这篇内容的学习,我们真心期待能帮到大家伙儿,让大家更能透彻地理解 Flink 遇到的问题,并且妥妥地解决它们。
2023-03-27 19:36:30
482
飞鸟与鱼-t
PostgreSQL
...是我们给新创建的索引命名的字符串,是我们想要在其上创建索引的表名,是我们想要在哪个列上创建索引的列名。 例如,我们有一个名为“employees”的表,其中包含员工的信息,如下所示: sql CREATE TABLE employees ( id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL, age INT NOT NULL, address VARCHAR(255) ); 现在,我们想要在“name”列上创建一个索引,以便我们可以更快地查找员工的名字。那么,我们就可以使用以下的SQL语句: sql CREATE INDEX idx_employees_name ON employees (name); 在这个语句中,“idx_employees_name”是我们给新创建的索引命名的字符串,“employees”是我们想要在其上创建索引的表名,“name”是我们想要在哪个列上创建索引的列名。 查看索引 如果我们已经创建了一个索引,但不确定它是否起作用或者我们想要查看所有已存在的索引,我们可以使用以下的SQL语句: sql SELECT FROM pg_indexes WHERE tablename = ''; 在这个语句中,“是我们想要查看其索引的表名。“pg_indexes”是PostgreSQL的一个系统表,它包含了所有的索引信息。 性能优化 虽然索引可以帮助我们加快查询速度,但是过多的索引也会影响数据库的性能。因此,在创建索引时,我们需要权衡索引的数量和查询效率之间的关系。通常来说,当你的表格里头的数据条数蹭蹭地超过10万大关的时候,那就真的得琢磨琢磨给它创建个索引了,这样一来才能让数据查找更溜更快。此外,咱们也得留意一下,别在那些频繁得不得了的列上乱建索引。要知道,这样做的话,索引维护起来可是会让人头疼的,成本噌噌往上涨。 总的来说,索引是提高数据库查询效率的重要手段。在PostgreSQL这个数据库里,我们能够用几句简单的SQL命令轻松创建索引。而且,更酷的是,还可以借助系统自带的索引管理工具,像看菜单一样直观地查看索引的各种状态,甚至还能随心所欲地调整它们,就像给你的数据仓库整理目录一样方便。但是,我们也需要注意不要滥用索引,以免影响数据库的整体性能。
2023-06-18 18:39:15
1326
海阔天空_t
Apache Lucene
...,我们需要更多的内存空间,这样一来,不可避免地会对整个系统的运行速度和效率产生影响。说得通俗点,就像是你的书包,如果放的索引卡片越多,虽然找东西方便了,但书包本身会变得更重,背起来也就更费劲儿,系统也是一样的道理,索引多了,内存空间占用大了,自然就会影响到它整体的运行表现啦。 2. 分片限制 Lucene的内部设计是基于分片进行数据处理的,每一份分片都有自己的索引。不过呢,要是遇到那种超级大的文本文件,这些切分出来的片段也会跟着变得贼大,这样一来,查询速度可就慢得跟蜗牛赛跑似的了。 3. IO操作频繁 当处理大型文本文件时,Lucene需要频繁地进行IO操作(例如读取和写入磁盘),这会极大地降低系统性能。 四、解决办法 既然我们已经了解了Lucene处理大型文本文件的问题所在,那么有什么方法可以解决这些问题呢? 1. 使用分布式存储 如果文本文件非常大,我们可以考虑将其分割成多个部分,然后在不同的机器上分别存储和处理。这样不仅可以减少单台机器的压力,还可以提高整个系统的吞吐量。 2. 使用更高效的索引策略 我们可以尝试使用更高效的索引策略,例如倒排索引或者近似最近邻算法。这些策略可以在一定程度上提高索引的压缩率和查询速度。 3. 优化IO操作 为了减少IO操作的影响,我们可以考虑使用缓存技术,例如MapReduce。这种技术有个绝活,能把部分计算结果暂时存放在内存里头,这样一来就不用老是翻来覆去地读取和写入磁盘了,省了不少功夫。 五、总结 虽然Apache Lucene在处理大量文本数据时可能存在一些问题,但只要我们合理利用现有的技术和工具,就可以有效地解决这些问题。在未来,我们盼着Lucene能够再接再厉,进一步把自己的性能和功能提升到新的高度,这样一来,就能轻轻松松应对更多的应用场景,满足大家的各种需求啦!
2023-01-19 10:46:46
510
清风徐来-t
转载文章
...syncfalse ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);ll a, b, c, d;int main(){syncfalseifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);endifcin>>a>>b>>c>>d;ll ans = 0;for (ll i = max(c+1, a+b); i <= b+c; ++i){ans+=(min(d+1,i)-c)(min(i-b,b)-max(i-c,a)+1);}cout << ans << "\n";return 0;} 本篇文章为转载内容。原文链接:https://blog.csdn.net/qq_53629286/article/details/122591582。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-07-05 12:21:15
46
转载
ZooKeeper
...ralsException异常的过程中,我们进一步认识到正确使用节点类型对于维持分布式系统稳定性和一致性的重要性。实际上,近期在Apache ZooKeeper社区的一篇技术博客(发布于2023年春季)中,开发者们深入探讨了临时节点和永久节点在实际生产环境中的最佳实践,并通过案例分析强调了遵循ZooKeeper设计原则的必要性。 另外,随着云原生和微服务架构的普及,如何有效利用ZooKeeper进行服务治理和协调的问题引起了更广泛的关注。例如,在Kubernetes等容器编排平台中,有些项目尝试将ZooKeeper的临时节点机制与Pod生命周期相结合,实现更为精细化的服务注册与发现策略,从而避免类似NoChildrenForEphemeralsException这样的问题。 此外,有研究者引用Leslie Lamport关于分布式系统一致性的经典论文《Time, Clocks, and the Ordering of Events in a Distributed System》来阐述为何保持数据结构的一致性是分布式系统设计的核心挑战之一,这也从理论上印证了ZooKeeper对临时节点限制的设计合理性。 总之,深入理解并合理运用ZooKeeper的各种特性,不仅能有效防止遇到NoChildrenForEphemeralsException这类异常,还能助力提升现代分布式系统的整体效能和可靠性,使之更好地适应快速发展的云计算环境。
2024-01-14 19:51:17
77
青山绿水
ElasticSearch
...h_after在减少IO操作、节省内存空间方面的技术原理,从而帮助开发者在实际项目中更精准地应用这项关键技术,有效应对日益增长的大数据挑战。
2023-03-26 18:17:46
577
人生如戏-t
PostgreSQL
...M Transactions on Database Systems》上的论文详细探讨了在实际业务场景下,如何根据数据分布特性和查询模式动态调整索引结构,以及如何利用分区、覆盖索引等技术来最大化数据库性能。 此外,随着机器学习和AI技术的发展,智能化数据库管理工具也开始崭露头角,它们能够通过分析历史查询数据和实时负载情况,自动推荐或调整索引配置,从而减轻DBA的工作负担,并确保数据库系统的高效运行。 总之,尽管本文介绍了PostgreSQL中创建显示值索引的基础方法,但数据库索引的世界远比这更为丰富和复杂,不断跟进最新的理论研究成果和技术动态,将有助于我们更好地应对各种实际应用场景中的性能挑战。
2023-07-04 17:44:31
346
梦幻星空_t
Gradle
...avorDimensions(风味维度)、productFlavors(产品风味)以及buildTypes(构建类型)。每个维度上的不同选择,大家可以随意混搭,这样就能创造出各种各样的构建版本,就像是搭配出不同口味的“APK套餐”一样。 例如: groovy android { flavorDimensions 'version', 'platform' productFlavors { free { dimension 'version' } paid { dimension 'version' } android { dimension 'platform' } ios { dimension 'platform' } } buildTypes { debug {} release {} } } 上述配置将会生成四种不同的构建变体:freeAndroidDebug, freeAndroidRelease, paidAndroidDebug, 和 paidAndroidRelease。 (2.2)预期与现实的差距 在理想情况下,根据以上配置,我们会预期生成四个APK。然而,实际情况可能是生成了更多的APK。这是因为Gradle这家伙很贴心,它会为每一个构建变体都生成所有能兼容的不同ABI(应用二进制接口)版本的APK,就像个勤劳的小蜜蜂,确保你的应用在各种设备上都能顺畅运行。例如,针对arm64-v8a, armeabi-v7a等多种CPU架构,每个构建变体都会生成相应的APK。 3. 控制APK生成数量 (3.1) ABI过滤 当我们希望控制生成APK的数量时,可以通过ABI过滤来实现: groovy android { ... splits { abi { enable true reset() include 'x86', 'armeabi-v7a' // 只包含特定的ABI universalApk false // 不生成通用APK } } } (3.2) 精确控制构建变体组合 对于某些不需要的构建变体组合,我们也可以选择禁用: groovy productFlavors { free { ... } paid { ... exclude 'ios' // 禁止付费版生成iOS平台的APK } } 4. 结论与思考 面对Gradle构建变体生成的APK数量不符合预期的情况,我们需要深度理解和掌握Gradle构建系统的规则,尤其是构建变体的组合方式和ABI过滤功能。通过精细地调配,我们能够像玩转魔方一样掌控APK的产出数量,让构建过程嗖嗖加速,同时也能悄无声息地压低维护成本,让一切运转得更顺滑、高效。 在这个过程中,我们需要不断试错、反思,理解每一个配置背后的实际效果。毕竟,Gradle就相当于一位超厉害的大厨,你得摸透他的独门烹饪秘籍,才能确保做出来的“菜”(也就是APK啦)既对味儿(满足各种需求),又能省时省力、性价比超高(高效构建)。所以,对我们每个Android开发者来说,要持续提升自我,掌握Gradle的各种配置诀窍并实际操练起来,绝对是必修的一课,这可不容忽视!
2023-07-24 11:29:47
494
青山绿水
Nginx
...,还有任务是更偏重于IO操作还是CPU运算这些情况,都得好好琢磨一下。 - 内存限制:如果你的服务器内存有限,过多的worker进程可能导致内存溢出,此时应适当减少worker_processes的数量,以保证每个进程有足够的内存空间运行。 - I/O绑定场景:对于大量依赖磁盘I/O或者网络I/O的应用场景,即使CPU核心未被完全利用,也可能因为I/O等待而导致增加更多的worker进程并不能显著提升性能。 2.3 调整策略 面对具体场景时,你可以先采用系统核心数作为基准值,并通过监控工具观察实际运行情况,包括CPU利用率、内存占用率以及系统负载等指标,逐步微调worker_processes的值以达到最优状态。 3. 其他相关配置 worker_connections 除了worker_processes,另一个关键参数是worker_connections,它定义了每个worker进程可同时接受的最大连接数。两者共同决定了Nginx能处理的并发连接总数。 nginx events { worker_connections 1024; 示例:每个worker进程可处理1024个并发连接 } 当你调整worker_processes的同时,也需要合理设定worker_connections,确保总的并发连接能力既能满足业务需求,又不会造成资源浪费。 4. 结语 实践出真知,智慧在调整中升华 关于如何设置Nginx的worker_processes数量,没有一成不变的答案,这是一门结合硬件资源、软件特性及实际应用场景的艺术。只有不断摸爬滚打,像侦探一样洞察秋毫,瞅准时机灵活调校,才能让服务器的潜能发挥到极致,达到最佳性能状态。所以,让我们一起动手实践吧,去感受那份挑战与收获带来的喜悦,就像烹饪一道精美的菜肴,恰到好处的配料和火候才是成就美味的关键所在!
2023-01-30 14:57:18
92
素颜如水_
Linux
Systemd , Systemd是一个在Linux操作系统中广泛使用的系统和服务管理器,它负责启动、停止和管理系统服务以及进行系统初始化。在本文的上下文中,Systemd用于管理和控制名为my_service的服务,通过systemctl命令可以查看服务状态、启动或停止服务,并通过其日志功能帮助运维人员定位服务无法启动的具体原因。 journalctl , journalctl是Systemd自带的日志查看工具,用于查询和展示系统日志信息。在处理my_service服务无法启动的问题时,运维人员使用journalctl -xeu my_service命令来查阅该服务启动过程中的详细日志记录,以便精准定位问题所在。 Unit依赖 , 在Systemd中,Unit依赖是指一个服务(或者目标)与另一个服务(或目标)之间的启动顺序和依赖关系。在配置文件中通过\ After\ 和\ Requires\ 字段声明这些依赖关系,确保在启动某个服务之前,它的所有依赖项已经被正确启动。例如,在文章中提到的my_service.service配置文件里,可能指定了该服务依赖于network.target和database.service,意味着my_service服务只有在网络和数据库服务都已启动后才能成功启动。
2023-06-29 22:15:01
159
灵动之光
Oracle
...byte File System) , ZFS是一种高度先进的文件系统,由Sun Microsystems开发并由Oracle公司进一步优化和完善。它专为大型存储环境设计,具备数据完整性检查、错误校验、自动修复以及高级数据压缩等功能。在Oracle闪存技术中,ZFS通过其独特的存储池管理机制和数据块层级化存储策略,极大地提高了闪存设备上数据读取的效率和整体存储系统的性能。 并发处理能力 , 并发处理能力是指一个系统在同一时间内可以处理多个任务或请求的能力。在数据库领域,尤其是Oracle这样的企业级数据库系统中,高并发处理能力意味着系统能同时响应大量用户的查询请求或事务处理,而不至于造成堵塞或性能瓶颈。Oracle闪存技术通过优化数据访问路径和提高I/O速度,增强了系统并发处理任务的能力,使得在高负载环境下也能保持高效稳定的服务水平。
2023-08-04 10:56:06
158
桃李春风一杯酒-t
Bootstrap
...栅格系统(Grid System) , 栅格系统是Bootstrap用于创建响应式布局的核心组件,它通过将水平空间分割成一系列等宽的列(columns),并嵌套在行(rows)内,形成一种灵活的布局结构。开发者可以根据屏幕尺寸的不同,定义每列所占比例,从而实现在不同设备上的自适应布局。 媒体查询(Media Queries) , 媒体查询是CSS3中的一种特性,允许开发者根据设备的特定条件(如视口宽度、设备像素比等)应用不同的样式规则。在Bootstrap中,媒体查询被用来定义响应式断点,当浏览器窗口大小达到或超过某个预设阈值时,便会触发相应的CSS样式变化,实现界面布局在不同屏幕尺寸下的平滑过渡与适配。 SCSS(Sass Cascading Style Sheets) , SCSS是CSS预处理器 Sass 的语法格式之一,它扩展了原生CSS的功能,提供了变量、嵌套规则、混合宏、继承等更强大的编程功能。在Bootstrap中,源码使用SCSS编写,使得开发者能够更加方便地定制主题、修改样式,并通过编译生成最终的CSS文件,包括响应式布局相关的断点设置等。
2023-06-28 11:25:46
500
青山绿水
Redis
...t编码能有效压缩存储空间,提高读写速度,可通过修改hash-max-ziplist-entries和hash-max-ziplist-value进行配置。 4. 精细化监控与问题排查 定期对Redis服务器进行性能监控和日志分析至关重要。Redis自带的INFO命令能提供丰富的运行时信息,包括内存使用情况、命中率、命令统计等,结合外部工具如RedisInsight、Grafana等进行可视化展示,以便及时发现潜在性能瓶颈。 当遇到性能问题时,我们要像侦探一样去思考和探索:是由于内存不足导致频繁淘汰数据?还是因为某个命令执行过于耗时?亦或是客户端并发过高引发的问题?通过针对性的优化措施,逐步改善Redis服务器的响应时间和性能表现。 总结来说,优化Redis服务器的关键在于深入了解其内部机制,合理配置参数,巧妙利用其特性,以及持续关注和调整系统状态。让我们一起携手,打造更为迅捷、稳定的Redis服务环境吧!
2023-11-29 11:08:17
237
初心未变
Scala
...类型系统(Type System) , 类型系统是编程语言理论的一个核心组成部分,它为程序中的变量、表达式和函数等元素赋予类型,并通过类型检查确保程序在执行前满足一定的语义规则。Scala拥有一个丰富而强大的类型系统,其中包含了诸如存在类型这样的高级特性,旨在提高代码的可读性、安全性和抽象能力。通过类型系统,开发者能够更好地对程序进行静态分析,减少运行时错误,并且可以在设计API时隐藏实现细节,只暴露必要的接口给用户使用。
2023-09-17 14:00:55
42
梦幻星空
站内搜索
用于搜索本网站内部文章,支持栏目切换。
知识学习
实践的时候请根据实际情况谨慎操作。
随机学习一条linux命令:
nc host port
- 通过netcat工具连接到远程主机和端口。
推荐内容
推荐本栏目内的其它文章,看看还有哪些文章让你感兴趣。
2023-04-28
2023-08-09
2023-06-18
2023-04-14
2023-02-18
2023-04-17
2024-01-11
2023-10-03
2023-09-09
2023-06-13
2023-08-07
2023-03-11
历史内容
快速导航到对应月份的历史文章列表。
随便看看
拉到页底了吧,随便看看还有哪些文章你可能感兴趣。
时光飞逝
"流光容易把人抛,红了樱桃,绿了芭蕉。"