日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

mysql导出txt到client_mysql导出导入txt以及sftp自动下载(一)

發(fā)布時(shí)間:2024/9/19 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql导出txt到client_mysql导出导入txt以及sftp自动下载(一) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

場(chǎng)景需求:

公網(wǎng)服務(wù)器(以下簡(jiǎn)稱server)mysql數(shù)據(jù)庫(kù)里每五分鐘導(dǎo)出一次統(tǒng)計(jì)數(shù)據(jù),同時(shí)本地內(nèi)網(wǎng)服務(wù)器(以下簡(jiǎn)稱client)每五分鐘通過sftp把導(dǎo)出的txt導(dǎo)入到本地測(cè)試數(shù)據(jù)庫(kù),使用python(highcharts)做數(shù)據(jù)圖形展示。

需求分析:

1.所有實(shí)現(xiàn)命令基于shell環(huán)境編寫

2.公網(wǎng)內(nèi)網(wǎng)服務(wù)器使用ntp服務(wù),保證兩臺(tái)機(jī)器時(shí)間同步

3.需要對(duì)select結(jié)果進(jìn)行本地導(dǎo)出生成xls或者txt等類型文件(考慮到安全問題,公網(wǎng)mysql不對(duì)外開放遠(yuǎn)程權(quán)限,數(shù)據(jù)只能先存儲(chǔ)在本地公網(wǎng)服務(wù)器)

4.時(shí)間同步以后,server與client通過做ssh密鑰,計(jì)劃任務(wù)使用sftp方式達(dá)到自動(dòng)下載數(shù)據(jù)目的

5.實(shí)際操作使用mysqlimport來導(dǎo)入txt文件到本地?cái)?shù)據(jù)庫(kù)

本文將記錄以上五點(diǎn)實(shí)現(xiàn)步驟,python圖形展示本人未負(fù)責(zé)故不記錄,可能內(nèi)容較多分多篇文章記錄

NTP服務(wù)搭建

client:ip:192.168.2.100? 系統(tǒng)版本CentOS release 6.5 (Final)

server:210.72.145.44(中國(guó)國(guó)家授時(shí)中心)

安裝配置

CentOS 6.5系統(tǒng)已經(jīng)自帶了NTPD服務(wù),一般默認(rèn)是安裝了的,如果沒有安裝,先檢查下,然后配置好yum倉(cāng)庫(kù),yum方式安裝下就OK,具體如下:

[root@localhost ~]# rpm -q ntp

ntp-4.2.6p5-1.el6.centos.x86_64 #這表示已安裝,如果沒有安裝這里是空白

如果沒有安裝,yum安裝一下

# yum install ntp

安裝以后設(shè)置開機(jī)啟動(dòng)

# chkconfig ntpd on

# chkconfig --list ntpd

ntpd 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉

在配置前,先使用ntpdate手動(dòng)同步下時(shí)間,免得本機(jī)與外部時(shí)間服務(wù)器時(shí)間差距太大,讓ntpd不能正常同步

[root@localhost ~]# ntpdate -u 202.112.10.36

3 Jul 14:29:58 ntpdate[8237]: adjust time server 202.112.10.36 offset -0.000288 sec

準(zhǔn)備工作做完,后來開始配置ntpd的核心配置文件/etc/ntp.conf文件,參照以下配置好了就OK。

[root@localhost ~]# cat /etc/ntp.conf

# For more information about this file, see the man pages

# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not

# permit the source to query or modify the service on this system.

restrict default kod nomodify notrap nopeer noquery

restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.? This could

# be tightened as well, but to do so would effect some of

# the administrative functions.

restrict 127.0.0.1

restrict -6 ::1

# Hosts on local network are less restricted.

#允許內(nèi)網(wǎng)其他機(jī)器同步時(shí)間

restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

#server 0.centos.pool.ntp.org iburst

#server 1.centos.pool.ntp.org iburst

#server 2.centos.pool.ntp.org iburst

#server 3.centos.pool.ntp.org iburst

#中國(guó)這邊最活躍的時(shí)間服務(wù)器 : http://www.pool.ntp.org/zone/cn

server 210.72.145.44 perfer

server 202.112.10.36

server 59.124.196.83

#broadcast 192.168.1.255 autokey?? ?# broadcast server

#broadcastclient?? ??? ??? ?# broadcast client

#broadcast 224.0.1.1 autokey?? ??? ?# multicast server

#multicastclient 224.0.1.1?? ??? ?# multicast client

#manycastserver 239.255.254.254?? ??? ?# manycast server

#manycastclient 239.255.254.254 autokey # manycast client

# Enable public key cryptography.

#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating

# with symmetric key cryptography.

keys /etc/ntp/keys

# Specify the key identifiers which are trusted.

#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.

#requestkey 8

# Specify the key identifier to use with the ntpq utility.

#controlkey 8

# Enable writing of statistics records.

#statistics clockstats cryptostats loopstats peerstats

參照紅色部分,配置完成,保存退出,重啟服務(wù)

# service ntpd start

查看服務(wù)連接和監(jiān)聽

# netstat -tlunp | grep ntp

udp??????? 0????? 0 192.168.2.100:123?????????? 0.0.0.0:*?????????????????????????????? 2173/ntpd

udp??????? 0????? 0 127.0.0.1:123?????????????? 0.0.0.0:*?????????????????????????????? 2173/ntpd

udp??????? 0????? 0 0.0.0.0:123???????????????? 0.0.0.0:*?????????????????????????????? 2173/ntpd

udp??????? 0????? 0 ::1:123???????????????????? :::*??????????????????????????????????? 2173/ntpd

udp??????? 0????? 0 fe80::290:27ff:fefd:df5b:123 :::*??????????????????????????????????? 2173/ntpd

udp??????? 0????? 0 :::123????????????????????? :::*??????????????????????????????????? 2173/ntpd

紅色加粗部分表示已監(jiān)聽,采用UDP方式,端口123

……

ntpq -p 查看網(wǎng)絡(luò)中的NTP服務(wù)器,同時(shí)顯示客戶端和每個(gè)服務(wù)器的關(guān)系

[root@localhost ~]# ntpq -p

remote refid st t when poll reach delay offset jitter

==============================================================================

210.72.145.44 .STEP. 16 u - 1024 0 0.000 0.000 0.000

*gus.buptnet.edu 10.3.8.150 5 u 1526 1024 372 26.723 -5.993 5.637

59-124-196-83.H .STEP. 16 u - 1024 0 0.000 0.000 0.000

……

ntpstat 命令查看時(shí)間同步狀態(tài),這個(gè)一般需要5-10分鐘后才能成功連接和同步。所以,服務(wù)器啟動(dòng)后需要稍等下。

剛啟動(dòng)的時(shí)候,一般是:

# ntpstat

unsynchronised

time server re-starting

polling server every 64 s

連接并同步后:

synchronised to NTP server (202.112.10.36) at stratum 6

time correct to within 751 ms

polling server every 1024 s

OK,內(nèi)網(wǎng)的NTPD服務(wù)已經(jīng)配置完成,如果所有正常后,開始配置內(nèi)網(wǎng)的其他設(shè)備與這臺(tái)服務(wù)器作為時(shí)間同步服務(wù)。

NTP服務(wù)器搭建參考資料:http://acooly.iteye.com/blog/1993484

總結(jié)

以上是生活随笔為你收集整理的mysql导出txt到client_mysql导出导入txt以及sftp自动下载(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。