作者归档:yangyouji

Raspberry Pi 时间同步及windows 安装 ntp服务器的方法

参考链接

http://www.ronnutter.com/raspberry-pi-ntp-client-setup/

http://www.cnblogs.com/mybook/archive/2012/11/06/2757597.html

一.

Option 1 – sudo raspi-config, select change_timezone

Option 2 – sudo dpkg-reconfigure tzdata, Select the right country/timezone

使用上述方法可以设置时区

二.

pi@raspberrypi:~$ date
Sun Feb 24 14:38:41 CST 2013

使用上述方法查看当前时间

三.

pi@raspberrypi:~$ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*192.168.1.20 LOCAL(0) 13 u 8 64 3 0.304 1.632 1.407

使用上述方法查看当前ntp连接状态

四.

/etc/ntp.conf

文件中设置了ntp服务器的地址

# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will
# pick a different set every time it starts up. Please consider joining the
# pool:
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst

局域网添加IP地址

五.

windows安装ntp-4.2.8p8-win32-setup.exe https://www.meinbergglobal.com/english/sw/ntp.htm

六.

局域网使用LOCAL时间设置方法如下

aaa

七.

Edit NTP Configuration

# restrict default noquery nopeer nomodify notrap
restrict default limited kod nomodify notrap nopeer noquery
# restrict -6 default noquery nopeer nomodify notrap
restrict -6 default limited kod nomodify notrap nopeer noquery

后重启ntp

符:

NTP:ntpq -p参数解释

remote:NTP主机的IP或者是主机名(ntp.conf文件中配置的server和peer主机)
如果有『 * 』代表目前正在作用当中的上层 NTP
如果是『 + 』代表也有连上线,而且可作为下一个提供时间更新的候选者。

refid:参考的上一层 NTP 主机的地址
st:st的值表示的是远程主机的层级(NTP采用分层同步方式,一般第n+1级与第n级时钟源进行同步。NTP最多支持16层同步,即0-15层。多于16层将无法同步。
如果远程主机是当前主机的NTP Server的话,一般情况下本级主机的层级是st+1)。
t:The type of the peer (local, unicast, multicast or broadcast) when the last packet was received
l local (such as a GPS clock)
u unicast (this is the common type) (单播,即NTP client向NTP server发送NTP请求,NTP server回复的模式)
m multicast (多播,可跨子网。)
b broadcast (广播,不可跨子网。NTP server定时向广播地址发送NTP包,NTP client通过广播地址获取NTP包,同步本地时钟)
– netaddr (usually 0) when:自上次时钟同步以来经过了多少秒(当when=poll时,进行一次时钟同步,同时when被清零,从头开始计时。通过when可以知道上一次同步时间
(当前时间- when)和下一次同步时间(当前时间+poll-when))
pool:时钟同步间隔(ntp服务刚启动时,缺省的最小同步间隔是64(minpoll=6)秒,然后依次增加,128, 256, ……, 1024。缺省的最大值是1024(maxpoll=10)秒。
这两个值分别可以通过minpoll和maxpoll参数修改。)
reach:八进制数,表示最近8次时钟同步包接收情况(1表示接收成功,0表示接收失败。每接收一个包左移一位。对于一个运行较长时间的NTP client而言,
这个值应该是377->11,111,111,即最近8次包接收均成功;否则表示有丢包情况发生)
NTP刚启动后Reach变化:

如果最近的一次包接受失败:

delay:表示NTP client从发出NTP请求到接收到NTP服务器回复所经过的时间(毫秒)。
offset:即NTP client的本地时间与NTP服务器时间的差异。也就是NTP client需要调整的时间差异。
disp:表示两次时钟同步之间的offset的差值。
Jitter:Linux 系统时间与 BIOS 硬件时间的差异时间(毫秒)。

windows系统安装git服务器,设置socket5代理使用ssh提交

使用的工具

1.copSSH  Copssh_4.1.0_Installer.zip

2.git           Git-1.9.5-preview20141217.exe

服务器端配置

1.安装 Copssh

安装目录 C:\SSH

解压安装,注意如果重新安装,需要先删除系统用户SvcCOPSSH

2.配置 Copssh

配置Copssh,从开始菜单中打开COPSSH Control Panel

去掉密码认证   Allow password authentication

点击keys 生成公钥与私钥文件

3.安装 Git-1.9.5-preview20141217.exe

将git安装目录下的libexec\git-core文件夹下将git.exe, git-receive-pack.exe, git-upload-archive.exe, git-upload-pack.exe复制到C:\SSH\bin

(后期测试可能有找不到XX.DLL的错误,将缺少的DLL也考进去旧可以了)

4.建立仓库

例如C:\SSH\home\daimingzhuang\myapp

建立方法随意

客户端配置(socket5代理环境)

因为时代理环境,所以配置要负责一些

1.在安装 Git-1.9.5-preview20141217.exe

2.添加代理设置

打开 git bash

新建config文件

vi ~/.ssh/config

添加内容

ProxyCommand connect -S 192.168.1.10:8089 %h %p
Host gitproxy
User Administrator
Port 22
Hostname 109.120.57.25
IdentityFile ~/.ssh/id_rsa
PubkeyAuthentication yes

注:可能git/bin里面没有connect.exe 文件 可以到github里找一下,下载考进去就可以了

https://github.com/msysgit/msysgit/raw/master/mingw/bin/connect.exe

3.添加公钥

将客户端里 ~/.ssh/id_rsa文件中的内容,加入到服务器中~/.ssh/authorized_keysz 中

4.连接测试即可

树莓派3 安装opencv

1.更新
$ sudo apt-get update
$ sudo apt-get upgrade

2.安装开发工具
$ sudo apt-get install build-essential cmake pkg-config

3.安装Image I/O
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev

4.安装video I/O
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev

5.安装GTK
$ sudo apt-get install libgtk2.0-dev

6.安装gfortran 一个新的矩阵运算框架
$ sudo apt-get install libatlas-base-dev gfortran

7.安装python开发框架
$ sudo apt-get install python2.7-dev python3-dev

二。下载opencv
$ cd ~
$ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip
$ unzip opencv.zip

$ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
$ unzip opencv_contrib.zip

三。安装python
1.安装pip
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py

2.安装虚拟环境
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/.cache/pip

3.配置虚拟环境
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

$ echo -e “\n# virtualenv and virtualenvwrapper” >> ~/.profile
$ echo “export WORKON_HOME=$HOME/.virtualenvs” >> ~/.profile
$ echo “source /usr/local/bin/virtualenvwrapper.sh” >> ~/.profile

source ~/.profile

4.建立虚拟环境
mkvirtualenv cv -p python2
python2

mkvirtualenv cv -p python3
python3

以下操作都在虚拟环境中进行
5安装NumPy
pip install numpy

6.编译安装opencv
$ cd ~/opencv-3.1.0/
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \
-D BUILD_EXAMPLES=ON ..

$ make -j4
$ sudo make install
$ sudo ldconfig

for Python 2.7
$ cd ~/.virtualenvs/cv/lib/python2.7/site-packages/
$ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so

for Python 3.4
$ cd /usr/local/lib/python3.4/site-packages/
$ sudo mv cv2.cpython-34m.so cv2.so
$ cd ~/.virtualenvs/cv/lib/python3.4/site-packages/
$ ln -s /usr/local/lib/python3.4/site-packages/cv2.so cv2.so

7.测试
$ source ~/.profile
$ workon cv
$ python
>>> import cv2
>>> cv2.__version__
‘3.1.0’
>>>

8.删除源码,节省空间
$ rm -rf opencv-3.1.0 opencv_contrib-3.1.0

 

树莓派设置代理/修改源

修改/etc/profile或者 /etc/environment

添加如下内容

export http_proxy=”http://<proxyipaddress>:<proxyport>”
export https_proxy=”http://<proxyipaddress>:<proxyport>”
export no_proxy=”localhost,127.0.0.1,192.168.0.0/16″

如果需要时 sudo来运行命令 例如 sudo apt-get update

使用  sudo -E apt-get update

 

修改源

编辑 /etc/apt/sources.list

修改其中的网址为你需要的网址

具体的镜像网站可以在http://www.raspbian.org/RaspbianMirrors中查找

树莓派 设置固定IP/添加用户/修改密码

备份

pi@raspberry: sudo cp /etc/network/interfaces /etc/network/interfaces.sav

修改

pi@raspberry: sudo vi /etc/network/interfaces

iface eth0 inet dhcp ->  #iface eth0 inet dhcp

添加

# The loopback interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
#your static IP
address 192.168.1.118
#your gateway IP
gateway 192.168.1.1
netmask 255.255.255.0
#your network address “family”
network 192.168.1.0
broadcast 192.168.1.255

重启网络

pi@raspberry:sudo /etc/init.d/networking restart

或者

pi@raspberry:sudo /etc/init.d/networking reload

 

添加用户

useradd –g aft –s /sbin/nologin -d /home/pi/aft ftpuser

修改密码

passwd ftpuser

Raspberry Pi 2 使用 Transmission

一。安装

sudo apt-get install transmission-daemon  

二。修改配置

sudo service transmission-daemon stop  
sudo vi /etc/transmission-daemon/settings.json

添加一下代码到文件中

"download-dir": "/mnt/usbel/Torrents/Completed",
"incomplete-dir": "/mnt/usbel/Torrents/Incomplete",
"incomplete-dir-enabled": true,
"rpc-whitelist": "*.*.*.*",
"rpc-whitelist-enabled": false,

设置目录/设置WEB远程连接

三。修改目录权限

sudo usermod -a -G debian-transmission pi
chgrp debian-transmission /mnt/usbel/Torrents/Incomplete
chgrp debian-transmission /mnt/usbel/Torrents/Completed
chmod 770 /mnt/usbel/Torrents/Incomplete
chmod 770 /mnt/usbel/Torrents/Incomplete

四。web远程连接

浏览器输入 http://RASPI.IP.ADDRESS:9091/

默认用户名:密码

transmission:transmission

111

Centos6.5 更新php5.4

1.首页安装Webtatic EL6 YUM源
rpm -Uvh http://repo.webtatic.com/yum/el6/latest.rpm

2.停止web服务器
service nginx stop

3.删除当前的 php 安装 php5.4
yum remove php*
yum install php54w
yum install php54w-fpm php54w-mysql php54w-gd php54w-imap php54w-ldap php54w-odbc php54w-pear php54w-xml php54w-xmlrpc php54w-mbstring php54w-mcrypt php54w-bcmath php54w-mhash

4.配置php-fpm
vi /etc/php-fpm.d/www.conf #编辑
user = nginx #修改用户为需要的
group = nginx #修改组为需要的
:wq #保存退出

5.重启web服务器
service php-fpm restart
service nginx start

6.查看php版本
php -v
PHP 5.4.33 (cli) (built: Sep 19 2014 19:58:27)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

Nginx支持wordpress固定链接

官方给出了新的开启wordpress固定链接的方法,也简单的多。这里假设,我在nginx的conf文件夹下创建个wordpress.conf ,将下面的代码粘贴进去:

location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

搞定

(转载)CentOS设置程序开机自启动的方法

在CentOS或者RedHat其他系统下,如果是后面安装的服务,如httpd、mysqld、postfix等,安装后系统默认不会自动启动的。就算手动执行/etc/init.d/mysqld start启动了服务,只要服务器重启后,系统仍然不会自动启动服务。

在这个时候,我们就需要在安装后做个设置,让系统自动启动这些服务,避免不必要的损失和麻烦。

其实命令很简单的,使用chkconfig即可。比如要将mysqld设置为开机自动启动:

#chkconfig mysqld on

同理,要取消掉某个服务自动启动,只需要将最后的参数“on”变更为“Off”即可。比如要取消postfix的自动启动:

#chkconfig postfix off

值得注意的是,如果这个服务尚未被添加到chkconfig列表中,则现需要使用–add参数将其添加进去:

#chkconfig –add postfix

如果要查询当前所有自动启动的服务,可以输入:

#chkconfig –list

但是这样显示东西太多了,看起来很晕。如果只想看指定的服务怎么办呢?这个时候只需要在“–list”之后加上服务名就好了,比如查看httpd服务是否为自动启动,就输入:

#chkconfig –list httpd

这个时候输出的结果:

httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

此时0~6均为off,则说明httpd服务不会在系统启动的时候自动启动。我们输入chkconfig httpd on后,再次检查输出结果变为:

httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

这个时候2~5都是on,就表明会自动启动了。

 

#让httpd 在机器启动的时候在运行级别上停止

[root@zhangxx etc]# chkconfig –level 345 httpd off

[root@zhangxx etc]# chkconfig –list |grep httpd

httpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭

 

#让httpd 在机器启动的时候在运行级别上启动

[root@zhangxx etc]# chkconfig –level 345 httpd on

[root@zhangxx etc]# chkconfig –list |grep httpd

httpd 0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭

 

可用 ps -ef 來查看有什么程序在运行中.

删除服务

rm /etc/init.d/servername

—————————————————————————————-

1、把写好的启动脚本添加到目录/etc/rc.d/init.d/,然后使用命令chkconfig设置开机启动。
例如:我们把httpd的脚本写好后放进/etc/rc.d/init.d/目录,使用

  1. chkconfig –add httpd
  2. chkconfig httpd on

命令即设置好了开机启动。

——————————————————————————————

chkconfig命令

功能说明:检查、设定系统的各种服务。

语法:chkconfig [–add][–del][–list][系统服务]或
chkconfig [–level<等级代号>][系统服务][on/off/reset]

补充说明:这个是redhat公司遵循gpl规则所开发的程序,它可以查询操作系统在每一个执行等级(runlevel)中,会执行哪些系统服务,其中包括各种daemon。

linux os 将操作环境分为以下7个等级:
0:开机(请不要切换到此等级)
1:单人使用者模式的文字界面
2:多人使用者模式的文字界面,不具有网络档案系统(NFS)功能
3:多人使用者模式的文字界面,具有网络档案系统(NFS)功能
4:某些发行版的linux使用此等级进入x windows system
5:某些发行版的linux使用此等级进入x windows system
6:重新启动

参数:    –add   新增所指定的系统服务
–del 删除所指定的系统服务
–level 指定该系统服务要在哪个执行等级中开启或关闭
–list   列出当前可从chkconfig指令管理的所有系统服务和等级代号
on/off/reset   在指定的执行登记,开启/关闭/重置该系统服务

chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。

语法:

chkconfig –list [name]
chkconfig –add name
chkconfig –del name
chkconfig [–level levels] name <on|off|reset>
chkconfig [–level levels] name

chkconfig 没有参数运行时,显示用法。如果加上服务名,那么就检查这个服务是否在当前运行级启动。如果是,返回true,否则返回false。如果在服务名后面指定 了on,off或者reset,那么chkconfi 会改变指定服务的启动信息。on和off分别指服务被启动和停止,reset指重置服务的启动信息,无论有问题的初始化脚本指定了什么。on和off开 关,系统默认只对运行级3,4,5有效,但是reset可以对所有运行级有效。

–level选项可以指定要查看的运行级而不一定是当前运行级。

需要说明的是,对于每个运行级,只能有一个启动脚本或者停止脚本。当切换运行级时,init不会重新启动已经启动的服务,也不会再次去停止已经停止的服务。

chkconfig –list :显示所有运行级系统服务的运行状态信息(on或off)。如果指定了name,那么只显示指定的服务在不同运行级的状态。

chkconfig –add name:增加一项新的服务。chkconfig确保每个运行级有一项启动(S)或者杀死(K)入口。如有缺少,则会从缺省的init脚本自动建立。

chkconfig –del name:删除服务,并把相关符号连接从/etc/rc[0-6].d删除。

chkconfig [–level levels] name <on|off|reset>:设置某一服务在指定的运行级是被启动,停止还是重置。例如,要在3,4,5运行级停止nfs服务,则命令如下:

chkconfig –level 345 nfs off

运行级文件:

每个被chkconfig管理的服务需要在对应的init.d下的脚本加上两行或者更多行的注释。第一行告诉chkconfig缺省启动的运行级以及启动 和停止的优先级。如果某服务缺省不在任何运行级启动,那么使用 – 代替运行级。第二行对服务进行描述,可以用/ 跨行注释。
例如,random.init包含三行:
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for /
# higher quality random number generation.

附加介绍一下Linux系统的运行级的概念:
Linux中有多种运行级,常见的就是多用户的2,3,4,5 ,很多人知道5是运行X-Windows的级别,而0就是关机了。运行级的改变可以通过init命令来切换。例如,假设你要维护系统进入单用户状态,那 么,可以使用init1来切换。在Linux的运行级的切换过程中,系统会自动寻找对应运行级的目录/etc/rc[0-6].d下的K和S开头的文件, 按后面的数字顺序,执行这些脚本。对这些脚本的维护,是很繁琐的一件事情,Linux提供了chkconfig命令用来更新和查询不同运行级上的系统服 务。

范例:

1.查看在各种不同的执行等级中,各项服务的状况:
$chkconfig –list

2.列出系统服务vsftpd在各个执行等级的启动情况:
$chkconfig –list vsftpd

3.在执行等级3,5时,关闭vsftpd系统服务:
$chkconfig –level 35 vsftpd off

4.在执行等级2,3,5时,开启 vsftpd系统服务:
$chkconfig –level 235 vsftpd on

5.关闭一些自己不需要的服务 ->
如果没有打印机:
chkconfig –level 235 cups off
如果没有局域网:
chkconfig –level 235 smb off
如果不需要远程用户登录的:
chkconfig –level 235 sshd off
如果不需要定时任务的:
chkconfig –level 235 crond off
如果不需要添加新硬件的:
chkconfig –level 235 kudzu off

有些时候我们需要在服务器里设置一个脚本,让他一开机就自己启动。方法如下:

cd /etc/init.d
vi youshell.sh   #将youshell.sh修改为你自己的脚本名

编写自己的脚本后保存退出。
在编写脚本的时候,请先加入以下注释

#add for chkconfig
#chkconfig: 2345 70 30
#description: the description of the shell   #关于脚本的简短描述
#processname: servicename                    #第一个进程名,后边设置自启动的时候会用到

说明:
2345是指脚本的运行级别,即在2345这4种模式下都可以运行,234都是文本界面,5就是图形界面X
70是指脚本将来的启动顺序号,如果别的程序的启动顺序号比70小(比如44、45),则脚本需要等这些程序都启动以后才启动。
30是指系统关闭时,脚本的停止顺序号。

给脚本添加上可执行权限:

chmod +x youshell.sh

利用chkconfig命令将脚本设置为自启动

chkconfig --add servicename

这样你的脚本就可以在开机后自动运行了。

另外,在redhat里也可以使用这个方法来实现开机自启动。

chkconfig的使用方法

chkconfig(check config)

功能说明:检查,设置系统的各种服务。

语  法:chkconfig

[–add][–del][–list][系统服务]或chkconfig[–level<等级代号>][系统服务][on/off/reset]

补充说明:这是RedHat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务。

参数:

–add 增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。
–del 删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据。
–level<等级代号> 指定读系统服务要在哪一个执行等级中开启或关毕

1:chkconfig 命令也可以用来激活和解除服务。chkconfig –list 命令显示系统服务列表,以及这些服务在运行级别0到6中已被启动(on)还是停止(off)。

chkconfig –list

chkconfig –list httpd

httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

2:chkconfig 还能用来设置某一服务在某一指定的运行级别内被启动还是被停运。譬如,要在运行级别3、4、5中停运 nscd 服务,使用下面的命令:

chkconfig –level 345 nscd off

3:由 xinetd 管理的服务会立即被 chkconfig 影响。譬如,如果 xinetd 在运行,finger 被禁用,那么执行了 chkconfig finger on 命令后,finger 就不必手工地重新启动 xinetd 来立即被启用。对其它服务的改变在使用 chkconfig 之后不会立即生效。必须使用service servicename start/stop/restart命令来重起服务

 

第二种方法

编辑  /etc/rc.d/rc.local文件

格式为  程序名  程序路径

例如  a.sh  /home/a.sh