前端技术
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
[hosts文件]的搜索结果
这里是文章列表。热门标签的颜色随机变换,标签颜色没有特殊含义。
点击某个标签可搜索标签相关的文章。
点击某个标签可搜索标签相关的文章。
转载文章
...与之精华. 全在配置文件,如果只是将服务搭建起来,那和不搭有什么区别呢. Nagios的配置文件非常多,只要其中一个配置文件出现错误,就会导致Nagios 无法正常工作。也很灵活,但只要掌握了其中的规律,就很简单了 了解Nagios 的各个配置文件 1.主配置文件nagios.cfg nagios默认的配置文件比较少,并且将很主机,主机组,服务,服务组写在同一个文件中. 这样做的好处是配置文件管理比较方便,但是数据量大了之后,很难整理.所以建议将这些配置分开 cfg_file=/usr/local/nagios/etc/objects/commands.cfg cfg_file=/usr/local/nagios/etc/objects/contacts.cfg cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg cfg_file=/usr/local/nagios/etc/objects/templates.cfg cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg cfg_file=/usr/local/nagios/etc/objects/hosts.cfg cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg cfg_file=/usr/local/nagios/etc/objects/services.cfg cfg_file=/usr/local/nagios/etc/objects/servicegroups.cfg 改check_external_commands=0为check_external_commands=1.这行的作用是允许在web 界面下执行重启nagios、停止主机/服务检查等操作。 把command_check_interval的值从默认的1 改成command_check_interval=15s(根据自己的情况定这个命令检查时间间隔,不要太长也不要太短)。 2.资源配置文件resource.cfg 资源文件可以保存用户自定义的宏.资源文件的一个主要用处是用于保存一些敏感的配置信息,如系统口令等不能让CGIs 程序模块获取到的东西 3.CGI配置文件cgi.cfg CGI 配置文件包含了一系列的设置,它们会影响CGIs程序模块.还有一些保存在主配置文件之中,因此CGI 程序会知道你是如何配置的Nagios并且在哪里保存了对象定义.最实际的例子就是,如果你想建立一个只有查看报警权限的用户,或者只有查看其中一些服务 器或者服务状态的权限,通过修改cfi.cfg可以灵活的控制web访问端的权限. 4.主机定义文件 定义你要监控的对象,这里定义的“host_name”被应用到其它的所有配置文件中,这个是我们配置Nagios 必须修改的配置文件. [root@test objects] vim hosts.cfg define host{ host_name Nagios-Server ; 设置主机的名字,该名字会出现在hostgroups.cfg 和services.cfg 中。注意,这个名字可以不是该服务器的主机名。 alias Nagios服务器 ; 别名 address 192.168.81.128 ; 主机的IP 地址 check_command check-host-alive ; 检查使用的命令,需要在命令定义文件定义,默认是定义好的。 check_interval 1 ; 检测的时间间隔 retry_interval 1 ; 检测失败后重试的时间间隔 max_check_attempts 3 ; 最大重试次数 check_period 24x7 ; 检测的时段 process_perf_data 0 retain_nonstatus_information 0 contact_groups sagroup ; 需要通知的联系组 notification_interval 30 ; 通知的时间间隔 notification_period 24x7 ; 通知的时间段 notification_options d,u,r ; 通知的选项 w—报警(warning),u—未知(unkown) c—严重(critical),r—从异常情况恢复正常 } define host{ host_name Nagios-Client alias Nagios客户端 address 192.168.81.129 check_command check-host-alive check_interval 1 retry_interval 1 max_check_attempts 3 check_period 24x7 process_perf_data 0 retain_nonstatus_information 0 contact_groups sagroup notification_interval 30 notification_period 24x7 notification_options d,u,r } 5.主机组定义文件 主机组定义文件,可以方便的将相同功能或者在应用上相同的服务器添加到一个主机组里,在WEB 界面可以通过HOST Group 方便的查看该组主机的状态信息. 将刚才定义的两个主机加入到主机组中,针对生产环境就像把所有的MySQL 服务器加到一个MySQL主机组里,将Oracle 服务器加到一个Oracle 主机组里,方便管理和查看,可以配置多个组. [root@test objects] vim hostgroups.cfg define hostgroup { hostgroup_name Nagios-Example ; 主机组名字 alias Nagios 主机组 ; 主机组别名 members Nagios-Server,Nagios-Client ; 主机组成员,用逗号隔开 } 6.服务定义文件 服务定义文件定义你需要监控的对象的服务,比如本例为检测主机是否存活,在后面会讲到如何监控其它服务,比如服务器负载、内存、磁盘等. [root@test objects] vim services.cfg define service { host_name Nagios-Server ; hosts.cfg 定义的主机名称 service_description check-host-alive ; 服务描述 check_period 24x7 ; 检测的时间段 max_check_attempts 3 ; 最大检测次数 normal_check_interval 3 retry_check_interval 2 contact_groups sagroup ; 发生故障通知的联系人组 notification_interval 10 notification_period 24x7 ; 通知的时间段 notification_options w,u,c,r check_command check-host-alive } define service { host_name Nagios-Client service_description check-host-alive check_period 24x7 max_check_attempts 3 normal_check_interval 3 retry_check_interval 2 contact_groups sagroup notification_interval 10 notification_period 24x7 notification_options w,u,c,r check_command check-host-alive } 7.服务组定义文件 和主机组一样,我们可以按需将相同的服务放入一个服务组,这样有规律的分类,便于我们在WEB端查看. [root@test objects] vim servicegroups.cfg define servicegroup{ servicegroup_name Host-Alive ; 组名 alias Host Alive ; 别名设置 members Nagios-Server,check-host-alive,Nagios-Client,check-host-alive } 8.联系人定义文件 定义发生故障时,需要通知的联系人信息.默认安装完成后,该配置文件已经存在,而且该文件不仅定义了联系人,也定义了联系人组,为了条理化的规划,我们把联系人定义放在contacts.cfg文件里,把联系人组放在contactgroups.cfg文件中. [root@test objects] mv contacts.cfg contacts.cfg.bak [root@test objects] vim contacts.cfg define contact{ contact_name maoxian ; 联系人的名字 alias maoxian ; 别名 service_notification_period 24x7 ; 服务报警的时间段 host_notification_period 24x7 ; 主机报警的时间段 service_notification_options w,u,c,r ; 就是在这四种情况下报警。 host_notification_options d,u,r ;同上。 服务报警发消息的命令,在command.cfg 中定义。 service_notification_commands notify-service-by-email 服务报警发消息的命令,在command.cfg 中定义。 host_notification_commands notify-host-by-email email wangyx088@gmail.com ; 定义邮件地址,也就是接收报警邮件地址。 } 9.联系人组定义文件 联系人组定义文件在实际应用中很有好处,我们可以把报警信息分级别,报联系人分级别存放在联系人组里面.例如:当发生一些警告信息的情况下,只发邮件给系统工程师联系人组即可,但是当发生重大问题,比如主机宕机了,可以发给领导联系人组. [root@test objects] vim contactgroups.cfg define contactgroup{ contactgroup_name sagroup ; 组名 alias Nagios Administrators ; 别名 members maoxian ; 联系人组成员 } 10.命令定义文件 commands.cfg 命令定义文件是Nagios中很重要的配置文件,所有在hosts.cfg还是services.cfg使用的命令都必须在命令定义文件中定义才能使用.默认情况下,范例配置文件已经配置好了日常需要使用的命令,所以一般不做修改. 11.时间段定义文件 timeperiods.cfg 我们在检测、通知、报警的时候都需要定义时间段,默认都是使用7x24,这也是默认配置文件里配置好的,如果你需要周六日不做检测,或者在制定的维护时间不做检测,都可以在该时间段定义文件定义好,这样固定维护的时候,就不会为大量的报警邮件或者短信烦恼 [root@test objects] cat timeperiods.cfg |grep -v "^" |grep -v "^$" 可以根据业务需求来更改 12.启动Nagios 1> 修改配置文件所有者 [root@test objects] chown -R nagios:nagios /usr/local/nagios/etc/objects/ 2> 检测配置是否正确 [root@test objects] /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 如果配置错误,会给出相应的报错信息,可以根据信息查找,注意,如果配置文件中有不可见字符也可以导致配置错误 3> 重载Nagios [root@test objects] service nagios restart 本文出自 “毛线的linux之路” 博客,请务必保留此出处http://maoxian.blog.51cto.com/4227070/756516 本篇文章为转载内容。原文链接:https://blog.csdn.net/gzh0222/article/details/8549202。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-11-16 20:48:42
483
转载
转载文章
...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
94
转载
CSS
...文档中导入插件CSS文件地址。例如,比如我们要运用的插件为“plugin.css”,那么我们可以在head标签中插入以下代码: <link rel="stylesheet" type="text/css" href="plugin.css"> 接下来,我们要开始为插件的元素制定个性化样式规则。首先,我们需要识别插件组件标识符。一般可以通过审查元素的方式来查阅插件元素的属性。 例如,如果我们要调整插件元素的字号和颜色,可以运用以下代码: <style> .plugin-element { font-size: 14px; color: 333; } </style> 以上代码中,“.plugin-element”为插件元素的类名,“font-size”用于设置字号,“color”用于设置字体颜色。 如果想要替代插件元素的默认样式表,我们需要将自定义的样式表放在默认样式表之后,这样我们的样式表才会替代默认样式表。可以运用以下代码来实现: <link rel="stylesheet" type="text/css" href="plugin.css"> <style> .plugin-element { font-size: 14px; color: 333; } </style> 最后,我们还可以运用!important关键字来强制替代其他样式表。例如: .plugin-element { font-size: 14px!important; color: 333!important; } 需要注意的是,运用!important关键字可能会影响到其他样式表的表现,因此应该尽量避免运用。 综上所述,运用CSS样式表替代插件可以让我们更自如地定制网站元素的外观。同时,我们需要注意插件组件标识符,以及运用!important关键字的影响。
2023-05-26 10:19:55
459
编程狂人
Datax
...我们的Datax配置文件。同时呢,我们还得翻翻Datax的官方文档,逛逛社区论坛啥的,这样才能捞到更多的帮助和解决方案。希望这篇文章能对你有所帮助!
2023-05-11 15:12:28
564
星辰大海-t
Kibana
...你的Kibana配置文件存在问题,例如API访问权限设置不正确,或者URL路径与实际不符,都可能导致API调用失败。 bash Kibana配置文件(kibana.yml) elasticsearch.hosts: ["http://localhost:9200"] 2.2 网络连接问题 如果Kibana与Elasticsearch之间的网络连接出现问题,那么API调用自然也会失败。 bash 网络检查 ping http://localhost:9200 2.3 Elasticsearch服务异常 如果Elasticsearch服务出现异常,如服务器未启动或运行过程中发生故障,那么Kibana就无法正常访问其API。 三、解决方法 针对以上的问题,我们提供以下几种解决方案: 3.1 检查配置文件 首先,你需要检查Kibana的配置文件,确保API访问权限设置正确且URL路径符合预期。 3.2 检查网络连接 其次,检查Kibana与Elasticsearch之间的网络连接是否畅通。试试看能不能ping通Elasticsearch的服务地址,如果它没反应,那很可能就是网络出状况了。 3.3 重启Elasticsearch 如果确认网络没有问题,但Kibana仍然无法访问API,可以尝试重启Elasticsearch服务。这样有可能会解决问题。 四、总结 Kibana内部API调用失败是一个比较常见的问题,其主要原因是配置错误、网络连接问题或Elasticsearch服务异常。当你遇到这个问题时,其实解决起来并不复杂。首先,咱们可以翻翻那个配置文件,看看是不是哪里设置得不太对劲;然后,再瞅瞅网络连接是否稳定、畅通无阻;最后,不妨大胆重启一下Elasticsearch服务,很多时候这就跟重启电脑能解决一堆问题一样,非常管用。这样一套操作下来,我们就能妥妥地把这个问题给摆平了。当然啦,假如你在解决这个问题时碰上了别的头疼事,随时欢迎向我们抛出疑问,我们时刻准备为你排忧解难!
2023-10-18 12:29:17
609
诗和远方-t
转载文章
... 1️⃣配置etc/hosts: 192.168.230.101 ouzy 设置-添加目标-手动添加目标-在主机上安装代理- 添加-手动-输入添加主机IP,选择对应平台-下一步-设置安装基目录:/u02/agent 验证填oracle、root用户身份证明信息(默认设置密码Oracle123,方便记忆,密码另存为改为root或者Oracle)-安装部署代理-完成 查看部署日志:(tail -f 文件名)(emcc主机上) tail -f /u02/gc_inst/em/EMGC_OMS1/sysman/agentpush/2019-08-20_20-55-47-PM/applogs/192.168.230.100_deploy.log 1 安装完成后在agent上查看安装情况(oracle) /u02/agent/agent_13.3.0.0.0/bin [oracle@ouzy bin]$ ./emctl status agent [oracle@ouzy bin]$ ./emctl upload agent(手动上传) 删除目标主机: 主机-目标设置-删除目标 全选-移去 代理: 点击无法删除的代理主机-代理-目标设置-取消代理使用(先停止代理agent) 删除目标主机: 主机-目标设置-删除目标 删除主机的时候如果有数据库,会显示主机上对应的应用,可以选择性删除。 ------------------------修改度量 1.新选项打开 2. 编辑阈值 编辑后就可以看到所有的度量 本篇文章为转载内容。原文链接:https://blog.csdn.net/jnrjian/article/details/126827989。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-07-25 18:45:23
131
转载
Nacos
...查看Nacos的日志文件来确认。如果你是Linux用户,可以尝试使用以下命令来查看日志: bash tail -f /path/to/nacos/logs/start.out 如果Nacos服务没有启动,你可能需要检查配置文件或者环境变量是否有误,然后重新启动服务。 3.2 配置错误 另一个常见的原因是配置错误。Nacos的配置文件里头藏了不少关键设定,比如说数据库连接信息啦、端口号之类的。一旦这些配置出错,就可能导致用户无法访问服务。例如,假设你的Nacos配置文件中数据库连接地址写错了,你可以按照如下步骤进行检查和修改: 1. 打开Nacos配置文件,通常是application.properties。 2. 检查spring.datasource.url字段的值是否正确。 3. 确保数据库服务器已经启动并且可以被访问。 举个例子,假设你的配置文件中原本是这样写的: properties spring.datasource.url=jdbc:mysql://wrong-host:3306/nacos_config?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true 你应该将其修改为正确的数据库地址,比如: properties spring.datasource.url=jdbc:mysql://localhost:3306/nacos_config?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true 3.3 网络问题 网络问题也是导致用户无法访问Nacos服务的一个重要原因。有时因为防火墙设错了或网络配置搞砸了,客户端就可能连不上Nacos服务了。解决这类问题的方法通常是检查网络配置,并确保防火墙规则允许必要的端口通信。 举个例子,如果你的Nacos服务运行在服务器上,并且默认监听9848端口,你需要确保该端口在服务器的防火墙中是开放的。你可以使用以下命令来添加防火墙规则(假设你使用的是Ubuntu系统): bash sudo ufw allow 9848/tcp 3.4 客户端配置问题 最后,我们需要检查客户端的配置是否正确。客户端得知道怎么连上Nacos服务,这就得搞清楚服务地址和端口号这些配置信息了。如果这些配置项不正确,客户端将无法成功连接到Nacos服务。 举个例子,假设你的客户端配置文件中原本是这样写的: java ConfigService configService = NacosFactory.createConfigService("http://wrong-host:8848"); 你应该将其修改为正确的Nacos服务地址,比如: java ConfigService configService = NacosFactory.createConfigService("http://localhost:8848"); 四、总结与建议 通过以上几个方面的排查,我们可以逐步缩小问题范围,并最终找到导致用户无法访问Nacos服务的原因。在这期间,咱们得保持耐心,还得细心点儿。当然了,该用的工具和技术也别手软,它们可是咱解决问题的好帮手呢! 希望这篇文章对你有所帮助!如果你还有其他问题或者疑惑,欢迎随时留言讨论。
2025-03-01 16:05:37
68
月影清风
Datax
...据库、数据仓库,甚至文件系统,无论是作为数据的源头还是目的地,都完全不在话下。而且还配备了一系列实用的转换规则和工具箱,这下子,我们就能轻轻松松地进行数据搬家和深度加工,就像在玩乐高积木一样便捷有趣啦! 三、数据量超过预设限制的问题 当我们面对数据量超过预设限制时,首先会遇到的是存储问题。传统的数据库呢,就像个不大不小的仓库,都有它自己的存储极限。你想象一下,要是我们塞进去的数据越来越多,超过了这个仓库的承载能力,那自然就没办法把所有的数据都妥善安置喽。其次,处理数据的速度也会受到限制。当数据量大到像山一样堆起来的时候,就算我们的计算能力已经牛得不行,也可能会因为不能迅速把所有的数据都消化掉,而使得工作效率大打折扣,就跟肚子饿得咕咕叫却只能慢慢吃东西一样。 四、解决方法 Datax 对于数据量超过预设限制的问题,Datax提供了很好的解决方案。通过使用Datax,我们可以将大数据分成多个部分,然后分别处理。这样既可以避免存储问题,也可以提高处理速度。 例如,如果我们有一个包含1亿条记录的大数据集,我们可以将其分成1000个小数据集,每个数据集包含1万条记录。然后,我们可以使用Datax分别处理这1000个小数据集。这样一来,哪怕我们手头上只有一台普普通通的电脑,也能够在比较短的时间内麻溜地把数据处理任务搞定。 以下是使用Datax处理数据的一个简单示例: python 导入Datax模块 import datax 定义数据源和目标 source = "mysql://username:password@host/database" target = "hdfs://namenode/user/hadoop/data" 定义转换规则 trans = [ { "type": "csv", "fieldDelimiter": ",", "quoteChar": "\"" }, { "type": "json", "pretty": True } ] 使用Datax处理数据 datax.run({ "project": "my_project", "stage": "load", "source": source, "sink": target, "transformations": trans }) 在这个示例中,我们首先导入了Datax模块,然后定义了数据源(一个MySQL数据库)和目标(HDFS)。然后,我们捣鼓出一套转换法则,把那些原始数据从CSV格式摇身一变,成了JSON格式,并且让这些数据的样式更加赏心悦目。最后,我们使用Datax运行这段代码,开始处理数据。 总的来说,Datax是一种非常强大的工具,可以帮助我们有效地处理大量数据。无论是存储难题,还是处理速度的瓶颈,Datax都能妥妥地帮我们搞定,给出相当出色的解决方案!因此,如果你在处理大量数据时遇到了问题,不妨尝试一下Datax。
2023-07-29 13:11:36
476
初心未变-t
Go Gin
...你需要提供相应的证书文件路径(如cert.pem和key.pem)。这样,你的Go Gin应用就成功实现了HTTPS强制跳转。 结语(5) 在解决Go Gin框架下的HTTPS强制跳转问题时,我们不仅了解了如何根据实际需求编写自定义中间件,还加深了对HTTPS工作原理的认识。这种带着情感化和技术思考的过程,正是编程的魅力所在。面对每一个技术挑战,只要我们保持探索精神,总能找到合适的解决方案。而Go Gin这个框架,它的灵活性和强大的功能简直就像个超级英雄,在我们实现各种需求的时候,总能给力地助我们一臂之力。
2023-01-14 15:57:07
517
秋水共长天一色
Logstash
...ch配置错误解析:“hosts”必须为单一URI或URI数组 在使用Logstash进行日志收集、过滤和输出的过程中,我们可能会遇到一个常见的配置问题:Invalid setting for output plugin 'elasticsearch': 'hosts' must be a single URI or array of URIs。这篇东西,咱们就专门来聊聊这个问题,我会掰开了揉碎了给你讲清楚它的意思,还会手把手地展示实际的代码实例,深入地跟你探讨解决之道。这样一来,你就能更透彻、更顺溜地理解和运用Logstash与Elasticsearch的集成啦! 1. 错误描述及原因 当你在Logstash的输出配置中指定Elasticsearch服务器地址时,"hosts"参数是至关重要的。这个参数用于告知Logstash到哪里去连接Elasticsearch集群。然而,如果配置不当,Logstash会抛出上述错误提示。这就意味着你在配置文件里填的那个"hosts"设置有点不对劲儿,它得符合一定的格式要求——要么就是一个独立的Uniform Resource Identifier(URI),这个名词听起来可能有点复杂,简单来说就是一个统一资源标识符;要么就是由多个这样的URI串起来组成的数组。就像是你要么提供一个地址,要么就提供一串地址列表,明白不? URI通常以协议(如http或https)开头,接着是主机名(或IP地址)和端口号,例如http://localhost:9200。当你在用Elasticsearch搭建集群,而且这个集群里头包含了多个节点的时候,为了让Logstash能够和整个集群愉快地、准确无误地进行交流沟通,你需要提供一组URI地址。就像是给Logstash一本包含了所有集群节点联系方式的小本本,这样它就能随时找到并联系到任何一个节点了。 2. 错误示例与纠正 错误配置示例: yaml output { elasticsearch { hosts => "localhost:9200, another_host:9200" } } 上述配置会导致上述错误,因为Logstash期望的hosts是一个URI或者URI数组,而不是一个用逗号分隔的字符串。 正确配置示例: yaml output { elasticsearch { hosts => ["http://localhost:9200", "http://another_host:9200"] } } 在这个修正后的示例中,我们将"hosts"字段设置为一个包含两个URI元素的数组,这符合Logstash对于Elasticsearch输出插件的配置要求。 3. 深入探讨与思考 理解并修复此问题的关键在于对Elasticsearch集群架构和Logstash与其交互方式的认识。在大规模的生产环境里,Elasticsearch这家伙更习惯于在一个分布式的集群中欢快地运行。这个集群就像一个团队,每个节点都是其中的一员,你都可以通过它们各自的“门牌号”——特定URI,轻松找到并访问它们。Logstash需要能够同时向所有这些节点推送数据以实现高可用性和负载均衡。 此外,当我们考虑到安全性时,还可以在URI中添加认证信息,如下所示: yaml output { elasticsearch { hosts => ["https://user:password@localhost:9200", "https://user:password@another_host:9200"] ssl => true } } 在此例子中,我们在URI中包含了用户名和密码以便进行基本认证,并通过ssl => true启用SSL加密连接,这对于保证数据传输的安全性至关重要。 4. 结论 总的来说,处理Invalid setting for output plugin 'elasticsearch': 'hosts' must be a single URI or array of URIs这样的错误,其实更多的是对我们如何细致且准确地按照规范配置Logstash与Elasticsearch之间连接的一种考验。你瞧,就像盖房子得按照图纸来一样,我们要想让Logstash和Elasticsearch这对好兄弟之间保持顺畅的交流,就得在设定hosts这个小环节上下功夫,确保它符合正确的语法和逻辑结构。这样一来,它们俩就能麻溜儿地联手完成日志的收集、分析和存储任务,高效又稳定,就跟咱们团队配合默契时一个样儿!希望这篇文章能帮你避免在实践中踩坑,顺利搭建起强大的日志处理系统。
2024-01-27 11:01:43
302
醉卧沙场
Kibana
...见的问题,可能是配置文件错误、依赖服务未启动,或者是资源不足等多方面因素导致。这个错误提示虽然说得有点含糊其辞,但实际上它是在暗示我们得像个侦探那样,把所有可能藏着问题的小角落都给翻出来瞅瞅。 shell $ ./bin/kibana Error: Kibana failed to start with status code: 500. Error: {"message":"An internal server error occurred."} 2. 常见原因与排查步骤 2.1 配置文件问题 (1)Elasticsearch连接设置:Kibana需要正确地连接到Elasticsearch以获取数据。检查kibana.yml中的elasticsearch.hosts配置项是否指向了正确的Elasticsearch地址。 yaml kibana.yml elasticsearch.hosts: ["http://localhost:9200"] (2)端口冲突或未开放:确认Kibana配置的监听端口(默认为5601)是否被其他进程占用,或者防火墙规则是否阻止了该端口的访问。 2.2 Elasticsearch状态检查 确保Elasticsearch服务已经成功启动并运行正常。尝试通过curl命令或者浏览器访问Elasticsearch的API来验证其状态。 shell $ curl -X GET 'http://localhost:9200' 如果返回结果包含"status": 200,说明Elasticsearch运行正常;否则,请检查Elasticsearch日志以找到可能存在的问题。 2.3 资源不足 Kibana在启动过程中可能因为内存不足等原因导致服务器内部错误。检查主机的系统资源状况,包括内存、磁盘空间等。必要时,可以通过增加JVM堆大小来缓解内存压力: yaml kibana.yml server.heap.size: 4g 根据实际情况调整 2.4 Kibana版本与Elasticsearch版本兼容性 不同版本的Kibana和Elasticsearch之间可能存在兼容性问题。记得啊,伙计,在使用Kibana的时候,一定要让它和Elasticsearch的版本“门当户对”。你要是不清楚它们两个该配哪个版本,就翻翻Elastic官方文档里那个兼容性对照表,一切答案就在那里揭晓啦! 2.5 日志分析 在面对上述常见情况排查后仍未能解决问题时,查阅Kibana的logs目录下的错误日志是至关重要的一步。这些详细的错误信息往往能直接揭示问题所在。 shell $ tail -f /path/to/kibana/logs/kibana.log 3. 解决方案与实践经验 经过一系列的排查和理解,我们应该能找到引发“服务器内部错误”的根源。当你遇到具体问题时,就得对症下药,灵活应对。比如说,有时候你可能需要调整一下配置文件,把它“修正”好;有时候呢,就像重启电脑能解决不少小毛病一样,你也可以选择重启相关的服务;再比如,如果软件版本出了问题,那咱就考虑给它来个升级或者降级的操作;当然啦,优化系统资源也是必不可少的一招,让整个系统跑得更加流畅、顺滑。 总结来说,面对Kibana无法启动并报出“服务器内部错误”,我们要有耐心和细致入微的排查精神,就如同侦探破案一样,层层剥茧,找出那个隐藏在深处的“罪魁祸首”。同时,也千万记得要充分运用咱们的社区、查阅各种文档资料,还有那个无所不能的搜索引擎。很多前人总结的经验心得,或者是现成的问题解决方案,都可能成为帮我们破译问题谜团的那把金钥匙呢!
2023-11-01 23:24:34
339
百转千回
Superset
...、API接口、CSV文件或任何其他能够提供结构化或半结构化数据的系统。在本文中,将各种数据库比喻为书架上的书籍,而配置数据源就是让Superset这个图书管理员知道并能访问这些“书籍”。 SQLAlchemy , SQLAlchemy是一个Python SQL工具包和ORM框架,它提供了全套的企业级持久化模式,包括SQL语句构造、自动关系管理以及高效数据处理等功能。在Superset中,用户需要通过SQLAlchemy URI格式来指定如何连接到目标数据库,这一字符串包含了数据库类型、用户名、密码、主机地址、端口号以及数据库名称等信息。 元数据库 , 元数据库是一种特殊的数据库,它存储了关于其他数据库的信息,即“关于数据的数据”。在Superset中,默认的元数据库通常用来存储与数据源、权限、仪表板等相关的信息,帮助管理和维护Superset自身的运行状态和用户数据资源。对于一般用户而言,保持默认的元数据库设置即可满足基本需求,但在一些复杂的部署场景下,可能需要对元数据库进行特殊配置以适应高可用性或安全性要求。
2023-06-10 10:49:30
75
寂静森林
Logstash
...无论是网络流量、日志文件还是数据库里的数据,Logstash都能搞定,简直是数据处理界的多面手啊!哎呀,你知道吗?在我们真正用上这些配置的时候,如果搞错了,可能会让数据审计这事儿全盘皆输。就像你做一道菜,调料放不对,整道菜可能就毁了。这样一来,咱们做决策的时候,参考的数据就不准确了,就好像盲人摸象,摸到的只是一小块,以为这就是大象全貌呢。所以啊,配置这块得细心点,别大意了!本文旨在深入探讨Logstash配置中的常见问题以及如何避免这些问题,确保数据审计的顺利进行。 一、Logstash基础与重要性 Logstash是一个开源的数据处理管道工具,用于实时收集、解析、过滤并发送事件至各种目的地,如Elasticsearch、Kafka等。其灵活性和强大功能使其成为构建复杂数据流系统的核心组件。 二、错误类型与影响 1. 配置语法错误 不正确的JSON语法会导致Logstash无法解析配置文件,从而无法启动或运行。 2. 过滤规则错误 错误的过滤逻辑可能导致重要信息丢失或误报,影响数据分析的准确性。 3. 目标配置问题 错误的目标配置(如日志存储位置或传输协议)可能导致数据无法正确传递或存储。 4. 性能瓶颈 配置不当可能导致资源消耗过大,影响系统性能或稳定性。 三、案例分析 数据审计失败的场景 假设我们正在审计一家电商公司的用户购买行为数据,目的是识别异常交易模式。配置了如下Logstash管道: json input { beats { port => 5044 } } filter { grok { match => { "message" => "%{TIMESTAMP_ISO8601:time} %{SPACE} %{NUMBER:amount} %{SPACE} %{IPORHOST:host}" } } mutate { rename => { "amount" => "transactionAmount" } add_field => { "category" => "purchase" } } } output { elasticsearch { hosts => ["localhost:9200"] index => "purchase_data-%{+YYYY.MM.dd}" } } 在这段配置中,如果elasticsearch输出配置错误,例如将hosts配置为无效的URL或端口,那么数据将无法被正确地存储到Elasticsearch中,导致审计数据缺失。 四、避免错误的策略 1. 详细阅读文档 了解每个插件的使用方法和限制,避免常见的配置陷阱。 2. 单元测试 在部署前,对Logstash配置进行单元测试,确保所有组件都能按预期工作。 3. 代码审查 让团队成员进行代码审查,可以发现潜在的错误和优化点。 4. 使用模板和最佳实践 借鉴社区中成熟的配置模板和最佳实践,减少自定义配置时的试错成本。 5. 持续监控 部署后,持续监控Logstash的日志和系统性能,及时发现并修复可能出现的问题。 五、总结与展望 通过深入理解Logstash的工作原理和常见错误,我们可以更加有效地利用这一工具,确保数据审计流程的顺利进行。嘿,兄弟!听好了,你得记着,犯错不是啥坏事,那可是咱成长的阶梯。每次摔一跤,都是咱向成功迈进一步的机会。咱们就踏踏实实多练练手,不断调整,优化策略。这样,咱就能打造出让人心头一亮的实时数据处理系统,既高效又稳当,让别人羡慕去吧!哎呀,随着科技这艘大船的航行,未来的Logstash就像个超级多功能的瑞士军刀,越来越厉害了!它能干的事儿越来越多,改进也是一波接一波的,简直就是我们的得力助手,帮咱们轻松搞定大数据这滩浑水,让数据处理变得更简单,更高效!想象一下,未来,它能像魔术师一样,把复杂的数据问题变个无影无踪,咱们只需要坐享其成,享受数据分析的乐趣就好了!是不是超期待的?让我们一起期待Logstash在未来发挥更大的作用,推动数据驱动决策的进程。
2024-09-15 16:15:13
151
笑傲江湖
Go-Spring
... 使用环境变量与配置文件进行灵活配置 在软件开发领域,配置管理是构建可扩展、可维护应用的关键环节。嘿,兄弟!如果你在用Go语言搞应用开发,那GoSpring框架绝对是你的超级好帮手!它就像个魔法师,能让你的应用配置变得既高效又灵活,就像是给你的应用穿上了一件超酷的魔法斗篷,让你随心所欲地调整和控制它的各种设置,简直不要太爽!本文将深入探讨如何利用GoSpring通过环境变量和配置文件来实现应用的动态配置,从而提升应用的灵活性和可定制性。 一、引入GoSpring GoSpring是一个基于Go语言的微服务框架,它提供了丰富的功能,如自动路由、健康检查、日志记录等,旨在简化微服务架构的开发和部署。Hey,小伙伴们!GoSpring 这家伙可真聪明,它能理解咱们编程时的各种小秘密,比如环境变量和配置文件这种事儿。这东西就像咱们做饭时的调料,根据不同的场合加点盐,加点酱油,让味道刚刚好。GoSpring 就是这么干的,它让开发者们能轻松地调整应用的行为,不管是在家做饭(开发本地环境)还是去朋友家吃饭(部署到远程服务器),都能得心应手,满足各种口味的需求。是不是觉得它更像一个贴心的朋友,而不是冷冰冰的机器人呢? 二、环境变量的运用 环境变量是操作系统提供的变量,可以在运行时修改程序的行为。在GoSpring中,通过os包的Env变量,可以方便地读取和设置环境变量。例如: go package main import ( "fmt" "os" ) func main() { // 读取环境变量 environment := os.Getenv("ENVIRONMENT") fmt.Printf("当前环境为:%s\n", environment) // 设置环境变量 os.Setenv("ENVIRONMENT", "production") environment = os.Getenv("ENVIRONMENT") fmt.Printf("设置后的环境为:%s\n", environment) } 这段代码展示了如何读取和设置环境变量。哎呀,你知道吗?在咱们的实际操作里,这些变量就像魔法师的魔法棒一样,能帮我们区分出开发、测试、生产这些不同的工作环境。就像是在厨房里,你有专门的调料盒来放做菜时需要用到的不同调料,这样就能确保每道菜的味道都刚刚好。咱们这些变量也是这么个道理,它们帮助我们确保在不同环境下程序运行得既稳定又高效! 三、配置文件的集成 配置文件是存储应用配置信息的一种常见方式。GoSpring通过内置的配置解析器,支持读取JSON、YAML或XML格式的配置文件。下面是一个简单的JSON配置文件示例: json { "app": { "name": "MyApp", "version": "1.0.0", "environment": "development" }, "database": { "host": "localhost", "port": 5432, "username": "myuser", "password": "mypassword", "dbname": "mydb" } } 在Go代码中,我们可以使用yaml或json包来解析这个配置文件: go package main import ( "encoding/json" "fmt" "io/ioutil" "log" "github.com/spf13/viper" ) func main() { viper.SetConfigFile("config.json") // 设置配置文件路径 if err := viper.ReadInConfig(); err != nil { // 读取配置文件 log.Fatalf("Error reading config file: %v", err) } // 获取配置数据 appName := viper.GetString("app.name") appVersion := viper.GetString("app.version") dbHost := viper.GetString("database.host") fmt.Printf("应用名称:%s, 版本:%s, 数据库主机:%s\n", appName, appVersion, dbHost) } 通过这种方式,我们可以在不修改代码的情况下,通过更改配置文件来改变应用的行为,极大地提高了应用的可维护性和灵活性。 四、整合环境变量与配置文件 在实际项目中,通常会结合使用环境变量和配置文件来实现更复杂的配置管理。例如,可以通过环境变量来控制配置文件的加载路径,或者根据环境变量的值来选择使用特定的配置文件: go package main import ( "os" "path/filepath" "testing" "github.com/spf13/viper" ) func main() { // 设置环境变量 os.Setenv("CONFIG_PATH", "path/to/your/config") // 读取配置文件 viper.SetConfigType("yaml") // 根据你的配置文件类型进行设置 viper.AddConfigPath(os.Getenv("CONFIG_PATH")) // 添加配置文件搜索路径 err := viper.ReadInConfig() if err != nil { log.Fatalf("Error reading config file: %v", err) } // 获取配置数据 // ... } 通过这种方式,我们可以根据不同环境(如开发、测试、生产)使用不同的配置文件,同时利用环境变量动态调整配置路径,实现了高度灵活的配置管理。 结语 GoSpring框架通过支持环境变量和配置文件的集成,为开发者提供了强大的工具来管理应用配置。哎呀,这种灵活劲儿啊,可真是帮了大忙!它就像个魔法师,能让你的开发工作变得轻松愉快,效率嗖嗖的往上窜。而且,别看它这么灵巧,稳定性却是一点儿也不含糊。不管是在哪个环境里施展它的魔法,都能保持一贯的好状态,稳如泰山。这就像是你的小伙伴,无论走到哪儿,都能给你带来安全感和惊喜,你说赞不赞?哎呀,兄弟,你懂的,现在咱们的应用就像个大家庭,人多了,事儿也杂了,对吧?这时候,怎么管好这个家庭,让每个人都各司其职,不乱套,就显得特别重要了。这就得靠咱们合理的配置管理策略来搞定。比如说,得有个清晰的分工,谁负责啥,一目了然;还得有规矩,比如更新软件得按流程来,不能随随便便;还得有监控,随时看看家里人都在干啥,有问题能及时发现。这样,咱们的应用才能健健康康地成长,不出岔子。所以,合理的配置管理策略,简直就是咱们应用界的定海神针啊!嘿,兄弟!这篇文章就是想给你开开小灶,让你能轻松掌握 GoSpring 在配置管理这块儿的厉害之处。别担心,我不会用一堆冰冷的术语把你吓跑,咱俩就像老朋友聊天一样,把这玩意儿讲得跟吃饭喝水一样简单。跟着我,你就能发现 GoSpring 配置管理有多牛逼,怎么用都顺手,让你的工作效率嗖嗖地往上涨!咱们一起探索,一起享受技术带来的乐趣吧!
2024-09-09 15:51:14
75
彩虹之上
转载文章
...SQL服务器中的日志文件。 -f, --force, 即使我们在一个表导出期间得到一个SQL错误,继续。 -h, --host=.. 从命名的主机上的MySQL服务器导出数据。缺省主机是localhost。 -l, --lock-tables. 为开始导出锁定所有表。 -t, --no-create-info 不写入表创建信息(CREATE TABLE语句) -d, --no-data 不写入表的任何行信息。如果你只想得到一个表的结构的导出,这是很有用的! --opt 同--quick --add-drop-table --add-locks --extended-insert --lock-tables。 应该给你为读入一个MySQL服务器的尽可能最快的导出。 -pyour_pass, --password[=your_pass] 与服务器连接时使用的口令。如果你不指定“=your_pass”部分,mysqldump需要来自终端的口令。 -P port_num, --port=port_num 与一台主机连接时使用的TCP/IP端口号。(这用于连接到localhost以外的主机,因为它使用 Unix套接字。) -q, --quick 不缓冲查询,直接导出至stdout;使用mysql_use_result()做它。 -S /path/to/socket, --socket=/path/to/socket 与localhost连接时(它是缺省主机)使用的套接字文件。 -T, --tab=path-to-some-directory 对于每个给定的表,创建一个table_name.sql文件,它包含SQL CREATE 命令,和一个table_name.txt文件,它包含数据。 注意:这只有在mysqldump运行在mysqld守护进程运行的同一台机器上的时候才工作。.txt文件的格式根据--fields-xxx和--lines--xxx选项来定。 -u user_name, --user=user_name 与服务器连接时,MySQL使用的用户名。缺省值是你的Unix登录名。 -O var=option, --set-variable var=option设置一个变量的值。可能的变量被列在下面。 -v, --verbose 冗长模式。打印出程序所做的更多的信息。 -V, --version 打印版本信息并且退出。 -w, --where=@where-condition@ 只导出被选择了的记录;注意引号是强制的! "--where=user=@jimf@" "-wuserid>1" "-wuserid<1" 最常见的mysqldump使用可能制作整个数据库的一个备份: mysqldump --opt database > backup-file.sql 但是它对用来自于一个数据库的信息充实另外一个MySQL数据库也是有用的: mysqldump --opt database | mysql --host=remote-host -C database 由于mysqldump导出的是完整的SQL语句,所以用mysql客户程序很容易就能把数据导入了: shell> mysqladmin create target_db_name shell> mysql target_db_name < backup-file.sql 就是 shell> mysql 库名 < 文件名 相关标签:工具 本文原创发布php中文网,转载请注明出处,感谢您的尊重! 本篇文章为转载内容。原文链接:https://blog.csdn.net/weixin_28851659/article/details/114329359。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-02-01 23:51:06
265
转载
转载文章
...ocol的缩写,安全文件传送协议。可以为传输文件提供一种安全的加密方法。SFTP 为 SSH的一部份,是一种传输文件到服务器的安全方式。SFTP是使用加密传输认证信息和传输的数据,所以,使用SFTP是非常安全的。但是,由于这种传输方式使用了加密/解密技术,所以传输效率比普通的FTP要低得多,如果您对网络安全性要求更高时,可以使用SFTP代替FTP(来自百度的解释) JSch是Java Secure Channel的缩写。 JSch是一个SSH2的纯Java实现。它允许你连接到一个SSH服务器,并且可以使用端口转发,X11转发,文件传输等,当然你也可以集成它的功能到你自己的应用程序。 ChannelSftp类是JSch实现SFTP核心类,它包含了所有SFTP的方法,如: put(): 文件上传get(): 文件下载cd(): 进入指定目录ls(): 得到指定目录下的文件列表rename(): 重命名指定文件或目录rm(): 删除指定文件mkdir(): 创建目录rmdir(): 删除目录 1、先引入jar包 <dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>1.2.2</version></dependency> 账号密码类 public interface SFTPDTO {/FTP登录用户名/public static final String username=xxxx;/ FTP登录密码/public static final String password=xxxx;/ 私钥/public static final String privateKey = xxxx;/ FTP服务器地址IP地址/public static final String host=xxxx;/ FTP端口/public static final int port=xxxx;} 重要类,里面包含开启连接和关闭连接。 public class SFTPUtils {private ChannelSftp sftp;private Session session;public void login(){try {JSch jsch = new JSch();if (SFTPDTO.privateKey != null) {jsch.addIdentity(SFTPDTO.privateKey);// 设置私钥}session = jsch.getSession(SFTPDTO.username, SFTPDTO.host, SFTPDTO.port);if (SFTPDTO.password != null) {session.setPassword(SFTPDTO.password);}Properties config = new Properties();config.put("StrictHostKeyChecking", "no");session.setConfig(config);session.connect();Channel channel = session.openChannel("sftp");channel.connect();sftp = (ChannelSftp) channel;} catch (Exception e) {log.error("Cannot connect to specified sftp server : {}:{} \n Exception message is: {}", new Object[]{SFTPDTO.host, SFTPDTO.port, e.getMessage()});} }/ 关闭连接 server/public void logout(){if (sftp != null) {if (sftp.isConnected()) {sftp.disconnect();log.info("sftp is closed already");} }if (session != null) {if (session.isConnected()) {session.disconnect();log.info("sshSession is closed already");} }}/ 将输入流的数据上传到sftp作为文件 @param directory 上传到该目录 @param sftpFileName sftp端文件名 @throws SftpException @throws Exception/public void upload(String directory, String sftpFileName, InputStream input) throws SftpException{try {sftp.cd(directory);} catch (SftpException e) {log.warn("directory is not exist");sftp.mkdir(directory);sftp.cd(directory);}sftp.put(input, sftpFileName);log.info("file:{} is upload successful" , sftpFileName);} } 测试一下 public static void main(){SFTPUtils sftp = new SFTPUtils();sftp.login();String audioUrl = courseSection.getAudioUrl();String temp[] = audioUrl.split("\\\\");String fileName = temp[temp.length - 1];InputStream inputStream = FileUtils.urlInputStream(audioUrl);sftp.upload("/www/website/haha/audio", fileName, inputStream);//上传//拼接最终的urlString newUrl = "https://static.taobao.com/website/ancai/audio/".concat(fileName);sftp.logout();} 把url转成流 public class FileUtils {public static InputStream urlInputStream(String fileUrl){if(StringUtils.isBlank(fileUrl)){return null;}try {URL url = new URL(fileUrl);HttpURLConnection conn = (HttpURLConnection)url.openConnection();//设置超时间为3秒conn.setConnectTimeout(31000);//防止屏蔽程序抓取而返回403错误conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");//得到输入流return conn.getInputStream();} catch (Exception e) {//打印errorlog.error("fileutils.urlinputstream-获取url流失败:",e.getMessage());}return null;} } 实际中,我们使用这个工具类就够用了 public class SFTPUtils {private ChannelSftp sftp;private Session session;public void login(){try {JSch jsch = new JSch();if (SFTPDTO.privateKey != null) {jsch.addIdentity(SFTPDTO.privateKey);// 设置私钥}session = jsch.getSession(SFTPDTO.username, SFTPDTO.host, SFTPDTO.port);if (SFTPDTO.password != null) {session.setPassword(SFTPDTO.password);}Properties config = new Properties();config.put("StrictHostKeyChecking", "no");session.setConfig(config);session.connect();Channel channel = session.openChannel("sftp");channel.connect();sftp = (ChannelSftp) channel;} catch (Exception e) {log.error("Cannot connect to specified sftp server : {}:{} \n Exception message is: {}", new Object[]{SFTPDTO.host, SFTPDTO.port, e.getMessage()});} }/ 关闭连接 server/public void logout(){if (sftp != null) {if (sftp.isConnected()) {sftp.disconnect();log.info("sftp is closed already");} }if (session != null) {if (session.isConnected()) {session.disconnect();log.info("sshSession is closed already");} }}/ 将输入流的数据上传到sftp作为文件 @param directory 上传到该目录 @param sftpFileName sftp端文件名 @throws SftpException @throws Exception/public void upload(String directory, String sftpFileName, InputStream input) throws SftpException{try {sftp.cd(directory);} catch (SftpException e) {log.warn("directory is not exist");sftp.mkdir(directory);sftp.cd(directory);}sftp.put(input, sftpFileName);log.info("file:{} is upload successful" , sftpFileName);}/ 上传单个文件 @param directory 上传到sftp目录 @param uploadFile 要上传的文件,包括路径 @throws FileNotFoundException @throws SftpException @throws Exception/public void upload(String directory, String uploadFile) throws FileNotFoundException, SftpException{File file = new File(uploadFile);upload(directory, file.getName(), new FileInputStream(file));}/ 将byte[]上传到sftp,作为文件。注意:从String生成byte[]是,要指定字符集。 @param directory 上传到sftp目录 @param sftpFileName 文件在sftp端的命名 @param byteArr 要上传的字节数组 @throws SftpException @throws Exception/public void upload(String directory, String sftpFileName, byte[] byteArr) throws SftpException{upload(directory, sftpFileName, new ByteArrayInputStream(byteArr));}/ 将字符串按照指定的字符编码上传到sftp @param directory 上传到sftp目录 @param sftpFileName 文件在sftp端的命名 @param dataStr 待上传的数据 @param charsetName sftp上的文件,按该字符编码保存 @throws UnsupportedEncodingException @throws SftpException @throws Exception/public void upload(String directory, String sftpFileName, String dataStr, String charsetName) throws UnsupportedEncodingException, SftpException{upload(directory, sftpFileName, new ByteArrayInputStream(dataStr.getBytes(charsetName)));}/ 下载文件 @param directory 下载目录 @param downloadFile 下载的文件 @param saveFile 存在本地的路径 @throws SftpException @throws Exception/public void download(String directory, String downloadFile, String saveFile) throws SftpException, FileNotFoundException{if (directory != null && !"".equals(directory)) {sftp.cd(directory);}File file = new File(saveFile);sftp.get(downloadFile, new FileOutputStream(file));log.info("file:{} is download successful" , downloadFile);}/ 下载文件 @param directory 下载目录 @param downloadFile 下载的文件名 @return 字节数组 @throws SftpException @throws Exception/public byte[] download(String directory, String downloadFile) throws SftpException, IOException {if (directory != null && !"".equals(directory)) {sftp.cd(directory);}InputStream is = sftp.get(downloadFile);byte[] fileData = IOUtils.toByteArray(is);log.info("file:{} is download successful" , downloadFile);return fileData;}/ 删除文件 @param directory 要删除文件所在目录 @param deleteFile 要删除的文件 @throws SftpException @throws Exception/public void delete(String directory, String deleteFile) throws SftpException{sftp.cd(directory);sftp.rm(deleteFile);}/ 列出目录下的文件 @param directory 要列出的目录 @return @throws SftpException/public Vector<?> listFiles(String directory) throws SftpException {return sftp.ls(directory);}/public static void main(String[] args) throws SftpException, Exception {SFTPUtils sftp = new SFTPUtils("xxxx", "xxx", "upload.haha.com", 8888);sftp.login();InputStream inputStream = getInputStream("http://qiniu.xinxuanhaoke.com/keqianduwu_1.jpg");sftp.upload("/www/website/ancai/audio", "123.jpg", inputStream);sftp.logout();}/} 方式二、使用HuTool的工具类 先引入jar <dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.4.0</version></dependency><dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.53</version></dependency> public static void main(String[] args) {Sftp sftp = JschUtil.createSftp("ip或者域名", 端口, "账号", "密码");ChannelSftp client = sftp.getClient();String cd = "/www/website/ancai/audio";//要上传的路径try {sftp.cd(cd); //进入指定目录} catch (Exception e) {log.warn("directory is not exist");sftp.mkdir(cd); //创建目录sftp.cd(cd); //进入目录}InputStream inputStream = urlInputStream("http://audio.xinxuanhaoke.com/50bda079e9ef3673bbaeda20321bf932.mp3");//将文件转成流client.put(String.valueOf(inputStream), "1.mp3");//开始上传。} 本文引自:https://www.cnblogs.com/ceshi2016/p/7519762.html 本篇文章为转载内容。原文链接:https://blog.csdn.net/weixin_37862824/article/details/113530683。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-04-04 09:43:38
71
转载
转载文章
... 的库/mysql 文件(历史) 此描述的来源:docs repo 的 mysql/ 目录(历史) 2.4. 如何使用镜像 2.4.1. 启动一个mysql服务器实例 启动 MySQL 实例很简单: $ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag 其中 some-mysql 是您要分配给容器的名称, my-secret-pw 是要为 MySQL root 用户设置的密码,而 tag 是指定您想要的 MySQL 版本的标签。 有关相关标签,请参见上面的列表。 以下是示例(通常要设置时区),注意-v 这里是挂载磁盘,请提前创建目录/var/mysql/data,/var/lib/mysql是容器里的原持久化目录: docker run --name mysql202201 -e MYSQL_ROOT_PASSWORD=123456 -e TZ=Asia/Shanghai -v /var/mysql/data:/var/lib/mysql -d mysql:5.7 2.4.2. 从 MySQL 命令行客户端连接到 MySQL 以下命令启动另一个 mysql 容器实例并针对您的原始 mysql 容器运行 mysql 命令行客户端,允许您针对您的数据库实例执行 SQL 语句: $ docker run -it --network some-network --rm mysql mysql -hsome-mysql -uexample-user -p 其中 some-mysql 是原始 mysql 容器的名称(连接到 some-network Docker 网络)。 此镜像也可以用作非 Docker 或远程实例的客户端: $ docker run -it --rm mysql mysql -hsome.mysql.host -usome-mysql-user -p 有关 MySQL 命令行客户端的更多信息,请参阅 MySQL 文档。 2.4.3. 容器外访问和查看 MySQL 日志 docker exec 命令允许您在 Docker 容器内运行命令。 以下命令行将为您提供 mysql 容器内的 bash shell: $ docker exec -it some-mysql bash 第一次启动一个MySQL容器后,需要对账户进行授权,否则无法远程访问,请先使用上面的命令进入容器内,然后使用以下命令连接到mysql服务: mysql -uroot -p 输入密码回车,进入mysql命令界面mysql> 接着授权root远程访问权限: mysql> GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '123456'; 然后就可以远程用MySQL客户端连接到MySQL容器了。 日志可通过 Docker 的容器日志获得: $ docker logs some-mysql 2.4.4. 使用自定义 MySQL 配置文件 MySQL 的默认配置可以在 /etc/mysql/my.cnf 中找到,其中可能包含额外的目录,例如 /etc/mysql/conf.d 或 /etc/mysql/mysql.conf.d。 请检查 mysql 映像本身中的相关文件和目录以获取更多详细信息。 如果 /my/custom/config-file.cnf 是你的自定义配置文件的路径和名称,你可以这样启动你的 mysql 容器(注意这个命令只使用了自定义配置文件的目录路径): $ docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag 这将启动一个新容器 some-mysql,其中 MySQL 实例使用来自 /etc/mysql/my.cnf 和 /etc/mysql/conf.d/config-file.cnf 的组合启动设置,后者的设置优先 . 没有 cnf 文件的配置 许多配置选项可以作为标志传递给 mysqld。 这将使您可以灵活地自定义容器,而无需 cnf 文件。 例如,如果要将所有表的默认编码和排序规则更改为使用 UTF-8 (utf8mb4),只需运行以下命令: $ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci 如果您想查看可用选项的完整列表,只需运行: $ docker run -it --rm mysql:tag --verbose --help 2.4.5. 环境变量 启动 mysql 镜像时,可以通过在 docker run 命令行中传递一个或多个环境变量来调整 MySQL 实例的配置。 请注意,如果您使用已包含数据库的数据目录启动容器,则以下任何变量都不会产生任何影响:任何预先存在的数据库在容器启动时将始终保持不变。 另请参阅 https://dev.mysql.com/doc/refman/5.7/en/environment-variables.html 以获取 MySQL 的环境变量的文档(尤其是 MYSQL_HOST 等变量,已知与此镜像一起使用时会导致问题)。 MYSQL_ROOT_PASSWORD 此变量是必需的,并指定将为 MySQL root 超级用户帐户设置的密码。 在上面的示例中,它被设置为 my-secret-pw。 MYSQL_DATABASE 此变量是可选的,允许您指定要在映像启动时创建的数据库的名称。 如果提供了用户/密码(见下文),则该用户将被授予对此数据库的超级用户访问权限(对应于 GRANT ALL)。 MYSQL_USER、MYSQL_PASSWORD 这些变量是可选的,用于创建新用户和设置该用户的密码。 该用户将被授予对 MYSQL_DATABASE 变量指定的数据库的超级用户权限(见上文)。 要创建用户,这两个变量都是必需的。 请注意,不需要使用此机制来创建超级用户超级用户,默认情况下会使用 MYSQL_ROOT_PASSWORD 变量指定的密码创建该用户。 MYSQL_ALLOW_EMPTY_PASSWORD 这是一个可选变量。 设置为非空值,例如 yes,以允许使用 root 用户的空白密码启动容器。 注意:除非您真的知道自己在做什么,否则不建议将此变量设置为 yes,因为这将使您的 MySQL 实例完全不受保护,从而允许任何人获得完全的超级用户访问权限。 MYSQL_RANDOM_ROOT_PASSWORD 这是一个可选变量。 设置为非空值,如 yes,为 root 用户生成随机初始密码(使用 pwgen)。 生成的根密码将打印到标准输出(生成的根密码:…)。 MYSQL_ONETIME_PASSWORD 一旦初始化完成,将 root(不是 MYSQL_USER 中指定的用户!)用户设置为过期,强制在第一次登录时更改密码。 任何非空值都将激活此设置。 注意:此功能仅在 MySQL 5.6+ 上受支持。 在 MySQL 5.5 上使用此选项将在初始化期间引发适当的错误。 MYSQL_INITDB_SKIP_TZINFO 默认情况下,入口点脚本会自动加载 CONVERT_TZ() 函数所需的时区数据。 如果不需要,任何非空值都会禁用时区加载。 2.4.6. Docker Secrets 作为通过环境变量传递敏感信息的替代方法,_FILE 可以附加到先前列出的环境变量中,从而导致初始化脚本从容器中存在的文件中加载这些变量的值。 特别是,这可用于从存储在 /run/secrets/<secret_name> 文件中的 Docker 机密中加载密码。 例如: $ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql-root -d mysql:tag 目前,这仅支持 MYSQL_ROOT_PASSWORD、MYSQL_ROOT_HOST、MYSQL_DATABASE、MYSQL_USER和 MYSQL_PASSWORD。 2.4.7. 初始化一个新实例 首次启动容器时,将使用提供的配置变量创建并初始化具有指定名称的新数据库。 此外,它将执行 /docker-entrypoint-initdb.d 中的扩展名为 .sh、.sql 和 .sql.gz 的文件。 文件将按字母顺序执行。 您可以通过将 SQL 转储安装到该目录并提供带有贡献数据的自定义镜像来轻松填充您的 mysql 服务。 SQL 文件将默认导入到 MYSQL_DATABASE 变量指定的数据库中。 2.5. 注意事项 2.5.1. 在哪里存储数据 重要提示:有几种方法可以存储在 Docker 容器中运行的应用程序使用的数据。 我们鼓励 mysql 映像的用户熟悉可用的选项,包括: 让 Docker 通过使用自己的内部卷管理将数据库文件写入主机系统上的磁盘来管理数据库数据的存储。 这是默认设置,对用户来说简单且相当透明。 缺点是对于直接在主机系统(即外部容器)上运行的工具和应用程序,可能很难找到这些文件。 在主机系统(容器外部)上创建一个数据目录,并将其挂载到容器内部可见的目录。 这会将数据库文件放置在主机系统上的已知位置,并使主机系统上的工具和应用程序可以轻松访问这些文件。 缺点是用户需要确保目录存在,例如主机系统上的目录权限和其他安全机制设置正确。 Docker 文档是了解不同存储选项和变体的一个很好的起点,并且有多个博客和论坛帖子在该领域讨论和提供建议。 我们将在这里简单地展示上面后一个选项的基本过程: 在主机系统上的合适卷上创建数据目录,例如 /my/own/datadir。 像这样启动你的 mysql 容器: $ docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag 命令的 -v /my/own/datadir:/var/lib/mysql 部分将底层主机系统中的 /my/own/datadir 目录挂载为容器内的 /var/lib/mysql ,默认情况下 MySQL 将 写入其数据文件。 2.5.2. 在 MySQL 初始化完成之前没有连接 如果容器启动时没有初始化数据库,则会创建一个默认数据库。 虽然这是预期的行为,但这意味着在初始化完成之前它不会接受传入的连接。 在使用同时启动多个容器的自动化工具(例如 docker-compose)时,这可能会导致问题。 如果您尝试连接到 MySQL 的应用程序没有处理 MySQL 停机时间或等待 MySQL 正常启动,那么在服务启动之前放置一个连接重试循环可能是必要的。 有关官方图像中此类实现的示例,请参阅 WordPress 或 Bonita。 2.5.3. 针对现有数据库的使用 如果您使用已经包含数据库的数据目录(特别是 mysql 子目录)启动 mysql 容器实例,则应该从运行命令行中省略 $MYSQL_ROOT_PASSWORD 变量; 在任何情况下都将被忽略,并且不会以任何方式更改预先存在的数据库。 2.5.4. 以任意用户身份运行 如果你知道你的目录的权限已经被适当地设置了(例如对一个现有的数据库运行,如上所述)或者你需要使用特定的 UID/GID 运行 mysqld,那么可以使用 --user 调用这个镜像设置为任何值(root/0 除外)以实现所需的访问/配置: $ mkdir data$ ls -lnd datadrwxr-xr-x 2 1000 1000 4096 Aug 27 15:54 data$ docker run -v "$PWD/data":/var/lib/mysql --user 1000:1000 --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag 2.5.5. 创建数据库转储 大多数普通工具都可以工作,尽管在某些情况下它们的使用可能有点复杂,以确保它们可以访问 mysqld 服务器。 确保这一点的一种简单方法是使用 docker exec 并从同一容器运行该工具,类似于以下内容: $ docker exec some-mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql 2.5.6. 从转储文件恢复数据 用于恢复数据。 您可以使用带有 -i 标志的 docker exec 命令,类似于以下内容: $ docker exec -i some-mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' < /some/path/on/your/host/all-databases.sql 备注 docker安装完MySQL,后面就是MySQL容器在跑,基本上就是当MySQL服务去操作,以前MySQL怎么做现在还是一样怎么做,只是个别操作因为docker包了一层,麻烦一点。 有需要的话,我们也可以基于MySQL官方镜像去定制我们自己的镜像,就比如主从镜像之类的。 本篇文章为转载内容。原文链接:https://blog.csdn.net/muluo7fen/article/details/122731852。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-05-29 17:31:06
101
转载
Docker
...er虚拟环境中的读写文件动作,常用到的方法是在Dockerfile中使用COPY或ADD命令,将本地文件或文件夹复制到虚拟环境中。例如: COPY /path/to/local/file /path/to/container/file 上述命令将本地路径下的文件复制到Docker虚拟环境中指定的路径下。类似地,也可以使用ADD命令完成同样的操作。 除了在Dockerfile中定义文件复制操作外,我们也可以使用Docker的volumes机制来实现虚拟环境与本地文件系统的交互。该机制可以将主机文件系统中的文件夹映射到虚拟环境的对应路径上,实现文件的双向读写。 使用volumes机制,需要在启动虚拟环境时添加相应参数,如下所示: docker run -v /host/path:/container/path -d image-name 上述命令将主机上的路径 /host/path 映射到虚拟环境中的路径 /container/path 上,实现双向文件的传输。 总的来说,Docker提供了多种文件读写的方法,根据不同场景可以选择最为适合的方法,实现高效的虚拟环境应用的开发和运行。
2023-12-30 15:13:37
472
编程狂人
Docker
...ompose.yml文件中使用ports关键字来映射端口。例如: ports: - "8080:80" 此配置将将Nginx虚拟容器的80端口转发到主机的8080端口。 除了上述方法,还有其他方式可以从Docker虚拟容器外部接入应用。如果您想深入了解Docker虚拟容器网络和端口转发的更多细节,请查看Docker官方文档。
2023-06-15 13:54:04
280
编程狂人
MySQL
...样板工具生成HTML文件。 constejs =require('ejs');constfs =require('fs');consttemplate = fs.readFileSync('template.ejs','utf-8');consthtml = ejs.render(template, { data }); fs.writeFileSync('output.html', html); 在上面的代码例子中,我们采用ejs用作样板工具,将检索结果传送到样板中,并将其生成为HTML文件。
2023-12-22 18:05:58
58
编程狂人
MySQL
...:查阅MySQL设置文件 1. 在电脑上搜索MySQL的设置文件my.cnf或my.ini,并开启文件。 2. 在文件中搜索[client]或[mysqldump]部分,通常口令会在该部分中显示。 3. 在该部分中搜索password或passwd的内容,该内容即为MySQL的口令。 方式二:通过MySQL工具查阅口令 1. 开启MySQL命令行工具或其它MySQL客户端。 2. 使用以下命令登录到MySQL服务器:mysql -u root -p。 3. 输入你自己设置的口令以登录到MySQL服务器。 4. 执行以下命令来查阅口令:SELECT user, host, password FROM mysql.user; 方式三:重置MySQL口令 如果以上方式都不能帮助你找回MySQL口令,那么可以考虑重置口令。以下是重置MySQL口令的基本步骤: 1. 停止MySQL服务。 2. 创建一个备份文件。 3. 启动MySQL服务,并跳过权限验证。 4. 使用UPDATE语句更新用户口令。 5. 停止MySQL服务并重新启动,以使更改生效。 总结 在工作中,有时候需要查阅自己电脑MySQL的口令,可以使用上述方式来实现。无论是通过查阅设置文件还是登录MySQL服务器,都十分简单。如果以上方式都不能找回口令,那么重置口令是最后的手段。希望这篇文章能够帮助到你。
2024-02-18 15:42:33
121
码农
转载文章
...ystem/etc/hosts c:/hosts (将hosts文件从手机拉取到本地,其中c:/hosts 为本地目标地址) 4.修改c:/hosts文件 5.adb push c:/hosts /system/etc/hosts (将c盘的hosts文件替换手机指定位置的hosts文件) 验证: 1.adb shell 2.cat /system/etc/hosts (看是否是修改之后的内容,如果是就说明替换成功,否则失败。) 本篇文章为转载内容。原文链接:https://blog.csdn.net/zgjswp/article/details/101572924。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-06-01 08:27:48
100
转载
站内搜索
用于搜索本网站内部文章,支持栏目切换。
知识学习
实践的时候请根据实际情况谨慎操作。
随机学习一条linux命令:
cal
- 显示当前月份的日历。
推荐内容
推荐本栏目内的其它文章,看看还有哪些文章让你感兴趣。
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
历史内容
快速导航到对应月份的历史文章列表。
随便看看
拉到页底了吧,随便看看还有哪些文章你可能感兴趣。
时光飞逝
"流光容易把人抛,红了樱桃,绿了芭蕉。"