ubuntu 配置 vnc server

通过将服务器配置成VNC SERVER,可以让其他主机使用图形方式登录这台服务器。 在ubuntu下配置vnc server很简单,方法如下: 服务器端: 1、先安装VNC服务程序: $ sudo apt-get install vnc4-common vnc4server 2、给当前用户设置vnc登录密码: $ vncpasswd 3、修改vnc的默认设置,使启动时运行gnome作为X的桌面(如果不设置,vnc将使用twm,你可以试试,相信你会很不习惯的): $ vncserver :1 $ vncserver -kill :1 注意:里面的":1"代表display号,客户登录的时候得写相同的display号才能登录(见后面客户端部分)。 修改~/.vnc/xstartup文件:(红字是修改和增加的东西) #!/bin/sh # Uncomment the following two lines for normal desktop: # unset SESSION_MANAGER # exec /etc/X11/xinit/xinitrc [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources xsetroot -solid grey vncconfig -iconic & xterm -geometry 80x24+10+10 -ls -title “$VNCDESKTOP Desktop” & # twm & gnome-session & 上面修改的意思是将默认启动的twm程序改为gnome,如果想用KDE作为桌面的,可以改为:startkde & 然后再次启动VNC SERVER: $ vncserver :1 客户端: 1、安装VNC客户程序: $ sudo apt-get install vnc4-common xvnc4viewer 2、然后你就通过Terminal Server Client登录了:Applications -> Internet -> Terminal Server Client;Computer为:服务器IP:display#,例如:12.34.56.78:1;protocol选择:VNC。

2009-11-06 · 1 min · 98 words · kevin

国产Linux发行版 CDLinux

CDlinux 是一种小型的迷你 GNU/Linux 发行版,其名称取自英文的 “Compact Distro Linux“。CDlinux 的体形小巧,功能却挺强大。 CDlinux 包含了最新的 Linux 内核,Xorg 图形界面,XFce 窗口管理器,和许多其它流行软件,如 Firefox 浏览器,Pidgin 即时通讯程序等等。并且 CDlinux 发行版中还包含了各种重要的、常用的库文件,用户可以很方便地按自己的需要扩展 CDlinux。 CDlinux 能很好地支持国际化(i18n)和各种语言、locale,目前对简体中文(zh_CN)、传统中文(zh_TW)和英文(en_US)提供全面支持。用户也可以很方便地定制 CDlinux 以支持他们自己的语言、locale。 CDlinux 能自动检测出自己被安装在什么设备上。你可以把 CDlinux 安装到 CD、DoC、Flash、HD 或者 MD 等类型的驱动器上,这些驱动器可以连接在 ATA、SATA、SCSI、USB 或者 IEEE1394 等总线上。在绝大多数情况下,CDlinux 都能自动识别这些设备并找到自己。 CDlinux 支持多种文件系统,你可以把它安装到 ext2、ext3、jfs、reiserfs、xfs、isofs、udf 及 hfs、hfsplus、fat、ntfs 等等分区上,CDlinux 都能自动挂载它们、找到自己并正常启动。 CDlinux 是高度灵活、可定制的。你可以拿它作为一个功能强大的系统修复、维护工具;你也可以加上自己需要的软件把它扩展成一个功能全面的桌面操作系统;还可以去掉 自己不需要的功能,把 CDlinux 裁减成一个嵌入式系统。完全可以按需定制你自己的 CDlinux。

2009-11-05 · 1 min · 50 words · kevin

svn库中添加、删除、提交文件的脚本

#!/bin/bash COUNT=`svn status | grep ‘^?’ |wc -l` until [ $COUNT -lt “1” ] do CURRENT=`svn status | grep ‘^?’ |awk {‘print $2’} | head -$COUNT | tail -1` echo “Do you want to add $CURRENT? (y/n): " read ANS if [ $ANS = “y” ] then svn add $CURRENT echo “$CURRENT added to repository” COUNT=`expr $COUNT - 1 ` elif [ $ANS = “n” ] then COUNT=`expr $COUNT - 1 ` fi done ...

2009-11-04 · 1 min · 159 words · kevin

How To Create A Cluster Testbed Using CentOS 5 Vir

A. Overview This guide attempts to provide a Xen based test environment where you can practice setting up a two node cluster (cluster setup itself is not discussed here - I’m merely giving you what you need to set it up). XEN can host two type of guest systems para-virtualized and fully-virtualized: for para-virtualized guests you require the Red Hat Enterprise Linux 5 installation tree available over NFS, FTP or HTTP. for fully-virtualized guest installations you will require DVD or CD-ROM distribution media or a bootable .iso file and a network accessible installation tree For details, please refer to the RHEL5 Virtualization Manual. I’ll be using para-virtualized guests here in my setup. There will be three systems involved here: node00 - physical system virtual IPs: 192.168.222.1 (public1 vlan) 192.168.100.1 (private1 vlan) node01 - para-virtualized guest 1 virtual IPs: 192.168.222.10 (public1 vlan) 192.168.100.10 (private1 vlan) node02 - para-virtualized guest 1 virtual IPs: 192.168.222.20 (public1 vlan) 192.168.100.20 (private1 vlan) B. What I used an HP Blade bl25p machine with 4G of RAM (this is actually an AMD64 blade machine). A machine with decent amount of RAM and processing speed should do. Centos i386 5 update 1 www.centos.org DVD ISO downloaded HTTP, NFS and FTP installation sources were created from this iso. Also, the yum repository that can be used by host and guest systems will be generated from the centos iso image. logical volumes hosting the guests and the “virtual luns” via iscsi (you can also use disk partitions - please refer to the virtualization guide for details). 1. My LVM setup The following is my LVM configuration. The lvLUN0* entries are the ones I used for iSCSI setup and will be shared by the two virtual guest systems. lvs LV VG Attr LSize origin Snap% Move Log Copy% lvLUN01 Virtual00VG -wi-ao 50.00G lvLUN02 Virtual00VG -wi-ao 50.00G lvNODE01 Virtual00VG -wi-ao 30.00G lvNODE02 Virtual00VG -wi-ao 30.00G lvNODE03 Virtual00VG -wi-ao 15.00G lvsys00 vg00 -wi-ao 512.00M lvsys01 vg00 -wi-ao 8.00G lvsys02 vg00 -wi-ao 8.00G lvsys03 vg00 -wi-ao 512.00M lvsys04 vg00 -wi-ao 128.00M lvsys05 vg00 -wi-ao 1.00G lvsys06 vg00 -wi-ao 256.00M C. Host Preparation I’m assuming that you know how to install CentOS or other RHEL based distributions and that you are familiar with rpm installation. Since I do a lot of setup for test/dev environments at work, I already have an installation server making it easy to do a network based install via PXE. The kickstart file for node00 is provided below. You can do a local media install (you have the ISO so you can burn it to a DVD) and just refer to the kickstart file for some of the configuration. The list of packages I used is in the %packages section of node00’s kickstart file. You can install them manually using yum, like: # will list centos installation groups yum grouplist # will install Virtualization group yum groupinstall Virtualization 1. ks file and installation 1.a kickstart file I use for the host (node00) You’ll have to modify the following to suit your setup. ## START node00_ks.cfg #modify for your own settings install nfs –server=remote_server –dir=/path/to/CENTOS5U1/i386 lang en_US.UTF-8 keyboard us skipx reboot network –device eth2 –bootproto static –ip a.b.c.1 –netmask 255.255.255.0 –gateway a.b.c.2 –nameserver x.y.z.n –hostname node00.example.com # grub and root password is a1s2d3f4g5 rootpw –iscrypted $1$3CXK2$CG9WlX2PuPpp7nxYMQGwP0 firewall –disabled authconfig –enableshadow selinux –disabled timezone Asia/Singapore bootloader –location=mbr –driveorder=cciss/c0d0 –append=“rhgb quiet” –md5pass=$1$3CXK2$CG9WlX2PuPpp7nxYMQGwP0 clearpart –all –initlabel –drives=cciss/c0d0 part /boot –fstype ext3 –size=100 –ondisk=cciss/c0d0 part pv.100000 –size=100 –grow –ondisk=cciss/c0d0 –asprimary volgroup vg00 –pesize=32768 pv.100000 logvol /tmp –fstype ext3 –name=lvsys05 –vgname=vg00 –size=1024 logvol /opt –fstype ext3 –name=lvsys04 –vgname=vg00 –size=128 logvol /var –fstype ext3 –name=lvsys03 –vgname=vg00 –size=512 logvol /usr –fstype ext3 –name=lvsys02 –vgname=vg00 –size=8192 logvol swap –fstype swap –name=lvsys01 –vgname=vg00 –size=8192 logvol /home –fstype ext3 –name=lvsys06 –vgname=vg00 –size=256 logvol / –fstype ext3 –name=lvsys00 –vgname=vg00 –size=512 %packages @development-libs @editors @system-tools @text-internet @x-software-development @virtualization @dns-server @core @base @ftp-server @network-server @legacy-software-development @base-x @web-server @printing @server-cfg @sql-server @admin-tools @development-tools lsscsi createrepo audit net-snmp-utils iptraf tftp lynx mesa-libGLU-devel kexec-tools bridge-utils device-mapper-multipath vnc-server xorg-x11-server-Xnest xorg-x11-server-Xvfb imake openmotif -vim-enhanced -zisofs-tools -zsh -bluez-hcidump -sysreport ## END of node00_ks.cfg 2. Host configuration Setting up an HTTP, NFS and FTP installation server: 2.a web server #/etc/httpd/conf.d/centos5u1.conf Alias /centos5u1 /var/ftp/pub/centos5u1 Options Indexes FollowSymLinks MultiViews IndexOptions FancyIndexing Order deny,allow Deny from all Allow from 127.0.0.1 ::1 all Then start the httpd service and make sure it does during startup: service httpd start chkconfig httpd on 2.b NFS server Edit /etc/exports and put the following into it: # /etc/exports /var/ftp/pub/centos5u1 192.168*(ro) service nfs start chkconfig nfs on 2.c FTP server Since we already have the source in /var/ftp/pub/centos5u1, all that is needed is to start vsftpd: service vsftpd start chkconfig vsftpd on 2.d YUM repository For this setup, I only use a local yum repository from the Centos DVD ISO I downloaded. First, I loopback mount it in /var/ftp/pub/centos5u1/i386/: cd /var/ftp/pub/centos5u1/ mkdir temp mount -o loop CentOS-5.1-i386-bin-DVD.iso temp cp -pr temp i386 umount temp createrepo -g i386 (i386/repodata/ will then be updated.) For RHEL5, it’s different: createrepo -g repodata/comps-rhel5-server-core.xml Server You need to do this inside the i386 directory (after loopback mounting and copying the whole directory structure). 2.d.1 the yum repo configuration: I renamed the default repo files in /etc/yum.repos.d/ to *-repo (instead of *.repo) to disable them. I then created this file: #/etc/yum.repos.d/CentOS5.repo [centos5-Server] name=CentOS5 Server baseurl=http://node00/centos5u1/i386 enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 node00 needs to be defined in /etc/hosts for the above file to work. or just replace node00 with its IP address. 2.e VNC server You won’t be needing a vnc connection if you have local console access to the physical machine. All you need to do is switch into gui mode: telinit 5 and open a gui terminal (like gnome-terminal or kde konsole). But since I do everything remotely, I use vncserver and vncviewer to do gui based stuff. 2.e.1 run vncserver: This will bringvup a vncserver in node00 that is accessible via “vncviewer” at node00:1 (assuming node00 is resolveable from your vncviewer host). vncserver You will require a password to access your desktops. Password: Verify: xauth: creating new authority file /root/.Xauthority New ’node00.example.com:1 (root)’ desktop is node00.example.com:1 Creating default startup script /root/.vnc/xstartup Starting applications specified in /root/.vnc/xstartup Log file is /root/.vnc/node00.example.com:1.log How To Create A Cluster Testbed Using CentOS 5 Virtualization And iSCSI - Page 2 How To Create A Cluster Testbed Using CentOS 5 Virtualization And iSCSI - Page 3 next How To Create A Cluster Testbed Using CentOS 5 Virtualization And iSCSI - Page 2 Copyright ? 2008 roderick tapang

2009-11-03 · 6 min · 1074 words · kevin

Memcached的管理

在以前写过了"搭建nginx + python + django +memcached+ mysql +fastcgi 环境"一文,有不少朋友问我关于memcached的管理的问题,比如查看memcached的运行情况等等,我们知道目前memcached没有直观的工具来查看整个运行情况,不过我们可以通过系统级--shell命令。 1、数据存储(假设key为dbasky.net,value为88888) printf “set dbasky.net 0 0 5\r\n88888\r\n” | nc 127.0.0.1 11211 STORED 2、数据取回(假设key为dbasky.net) printf “get dbasky.net\r\n” | nc 127.0.0.1 11211 VALUE dbasky.net 0 5 88888 END 3、数值增加1(假设key为dbasky.net,并且value为正整数) printf “incr dbasky.net 1\r\n” | nc 127.0.0.1 11211 88889 4、数值减少3(假设key为dbasky.net,并且value为正整数) printf “decr dbasky.net 3\r\n” | nc 127.0.0.1 11211 88886 5、数据删除(假设key为dbasky.net) printf “delete dbasky.net\r\n” | nc 127.0.0.1 11211 DeleteD 6、查看Memcached状态 [root@app3 ~]# printf “stats\r\n” | nc 127.0.0.1 11211 STAT pid 20272 STAT uptime 927901 STAT time 1256541017 STAT version 1.2.8 STAT pointer_size 64 STAT rusage_user 72323.142211 STAT rusage_system 270758.303481 STAT curr_items 2255461 STAT total_items 2237096141 STAT bytes 3865876133 STAT curr_connections 156 STAT total_connections 2662892830 STAT connection_structures 2975 STAT cmd_flush 0 STAT cmd_get 7155551459 STAT cmd_set 2237096141 STAT get_hits 6275571127 STAT get_misses 879980332 STAT evictions 21174550 STAT bytes_read 5936788593022 STAT bytes_written 12278494693042 STAT limit_maxbytes 4294967296 STAT threads 9 STAT accepting_conns 1 STAT listen_disabled_num 0 END 7、模拟top命令,查看Memcached状态: watch “printf ‘stats\r\n’ | nc 127.0.0.1 11211” 或者 watch “echo stats | nc 127.0.0.1 11211” [root@app3 ~]# watch “printf ‘stats\r\n’ | nc 127.0.0.1 11211” Every 2.0s: printf ‘stats\r\n’ | nc 127.0.0.1 11211 Mon Oct 26 16:11:26 2009 STAT pid 20272 STAT uptime 927970 STAT time 1256541086 STAT version 1.2.8 STAT pointer_size 64 STAT rusage_user 72327.750510 STAT rusage_system 270774.932953 STAT curr_items 2255435 STAT total_items 2237240981 STAT bytes 3865771193 STAT curr_connections 269 STAT total_connections 2663066932 STAT connection_structures 2975 STAT cmd_flush 0 STAT cmd_get 7156031867 STAT cmd_set 2237240981 STAT get_hits 6275980308 STAT get_misses 880051559 STAT evictions 21177694 STAT bytes_read 5937174840056 STAT bytes_written 12279303680177 STAT limit_maxbytes 4294967296 STAT threads 9 STAT accepting_conns 1 STAT listen_disabled_num 0 END 下面解释下各项的含意: uptime 是memcached运行的秒数,cmd_get是查询缓存的次数。这两个数据相除一下就能得到平均每秒请求缓存的次数,cmd_set 就是设置key=>value的次数。整个memcached是个大hash,用cmd_get没有找到的内容,就会调用一下cmd_set写进缓存里。紧跟着是get_hits,就是缓存命中的次数。缓存命中率 = get_hits/cmd_get *100%。get_misses的数字加上get_hits应该等于cmd_get。而total_itemscurr_items表示现在在缓存中的键值对个数,在图上total_items == cmd_set == get_misses,不过当可用最大内存用光时,memcached就会删掉一些内容,上面的等式就不成立了。

2009-11-02 · 2 min · 274 words · kevin

硬盘安装Ubuntu 9.10

Ubuntu 9.10已正式发布,在Windows环境下通过硬盘安装Ubuntu 9.10。 1.下载Grub4Dos(注意:如果你想尝试Ext4文件系统,一定要下载最新的支持Ext4文件系统Grub4Dos 0.4.4版本),解压至XP的C盘根下,修改menu.lst文件,在末尾添加如下内容: (注意:Ubuntu 9.10默认的文件系统格式是ext4,而不是ext3,格式分区的时候应注意选择。) title Install Ubuntu root (hd0,0) kernel (hd0,0)/vmlinuz boot=casper iso-scan/filename=/Ubuntu-9.10-desktop-i386.iso ro quiet splash locale=zh_CN.UTF-8 initrd (hd0,0)/initrd.gz 2.修改XP的boot.ini文件(该文件为系统文件,具有只读隐藏属性),在boot.ini末尾添加: C:\grldr=”GRUB” 3.下载Ubuntu 9.10的desktopCD的镜像文件,下载地址参考Ubuntu 9.10官方衍生版本全集,然后将下载好的镜像文件直接放在C: ,将其中的.disk文件夹加压至C: , 将casper目录下的initrd.gz和vmlinuz这两个文件也解压至C: 4.重启计算机,选择Grub,进入Grub引导程序,选择最后一项(Install Ubuntu),稍等即可进入ubuntu的liveCD模式,此时打开一个终端,在里面输入: sudo umount -l /iosdevice 回车,然后点击桌面上的安装图标即可完成安装过程。

2009-10-31 · 1 min · 37 words · kevin

linux主机常用监控脚本

1、查看主机网卡流量 #!/bin/bash #network #Mike.Xu while : ; do time=‘date +%m"-"%d" “%k”:"%M’ day=‘date +%m"-"%d’ rx_before=‘ifconfig eth0|sed -n “8"p|awk ‘{print $2}’|cut -c7-’ tx_before=‘ifconfig eth0|sed -n “8"p|awk ‘{print $6}’|cut -c7-’ sleep 2 rx_after=‘ifconfig eth0|sed -n “8"p|awk ‘{print $2}’|cut -c7-’ tx_after=‘ifconfig eth0|sed -n “8"p|awk ‘{print $6}’|cut -c7-’ rx_result=$[(rx_after-rx_before)/256] tx_result=$[(tx_after-tx_before)/256] echo “$time Now_In_Speed: “$rx_result"kbps Now_OUt_Speed: “$tx_result"kbps” sleep 2 done 2、系统状况监控 #!/bin/sh #systemstat.sh #Mike.Xu IP=192.168.1.227 top -n 2| grep “Cpu” »./temp/cpu.txt free -m | grep “Mem” » ./temp/mem.txt df -k | grep “sda1” » ./temp/drive_sda1.txt #df -k | grep sda2 » ./temp/drive_sda2.txt df -k | grep “/mnt/storage_0” » ./temp/mnt_storage_0.txt df -k | grep “/mnt/storage_pic” » ./temp/mnt_storage_pic.txt time=`date +%m”."%d” “%k”:"%M` connect=`netstat -na | grep “219.238.148.30:80” | wc -l` echo “$time $connect” » ./temp/connect_count.txt 3、监控主机的磁盘空间,当使用空间超过90%就通过发mail来发警告 #!/bin/bash #monitor available disk space SPACE=‘df | sed -n ‘/ \ / $ / p’ | gawk ‘{print $5}’ | sed ’s/%//’ if [ $SPACE -ge 90 ] then fty89@163.com fi 4、 监控CPU和内存的使用情况 #!/bin/bash #script to capture system statistics OUTFILE=/home/xu/capstats.csv DATE=‘date +%m/%d/%Y’ TIME=‘date +%k:%m:%s’ TIMEOUT=‘uptime’ VMOUT=‘vmstat 1 2’ USERS=‘echo $TIMEOUT | gawk ‘{print $4}’ ’ LOAD=‘echo $TIMEOUT | gawk ‘{print $9}’ | sed “s/,//’ ’ FREE=‘echo $VMOUT | sed -n ‘/[0-9]/p’ | sed -n ‘2p’ | gawk ‘{print $4} ’ ’ IDLE=‘echo $VMOUT | sed -n ‘/[0-9]/p’ | sed -n ‘2p’ |gawk ‘{print $15}’ ’ echo “$DATE,$TIME,$USERS,$LOAD,$FREE,$IDLE” » $OUTFILE 5、全方位监控主机 #!/bin/bash # check_xu.sh # 0 * * * * /home/check_xu.sh DAT=”`date +%Y%m%d`” HOUR=”`date +%H`” DIR="/home/oslog/host_${DAT}/${HOUR}” DELAY=60 COUNT=60 # whether the responsible directory exist if ! test -d ${DIR} then /bin/mkdir -p ${DIR} fi # general check export TERM=linux /usr/bin/top -b -d ${DELAY} -n ${COUNT} > ${DIR}/top_${DAT}.log 2>&1 & # cpu check /usr/bin/sar -u ${DELAY} ${COUNT} > ${DIR}/cpu_${DAT}.log 2>&1 & #/usr/bin/mpstat -P 0 ${DELAY} ${COUNT} > ${DIR}/cpu_0_${DAT}.log 2>&1 & #/usr/bin/mpstat -P 1 ${DELAY} ${COUNT} > ${DIR}/cpu_1_${DAT}.log 2>&1 & # memory check /usr/bin/vmstat ${DELAY} ${COUNT} > ${DIR}/vmstat_${DAT}.log 2>&1 & # I/O check /usr/bin/iostat ${DELAY} ${COUNT} > ${DIR}/iostat_${DAT}.log 2>&1 & # network check /usr/bin/sar -n DEV ${DELAY} ${COUNT} > ${DIR}/net_${DAT}.log 2>&1 & #/usr/bin/sar -n EDEV ${DELAY} ${COUNT} > ${DIR}/net_edev_${DAT}.log 2>&1 & 放在crontab里每小时自动执行: 0 * * * * /home/check_xu.sh 这样会在/home/oslog/host_yyyymmdd/hh目录下生成各小时cpu、内存、网络,IO的统计数据。 如果某个时间段产生问题了,就可以去看对应的日志信息,看看当时的主机性能如何。

2009-10-17 · 2 min · 344 words · kevin

阻止SSH暴力破解的方法(DenyHosts)

DenyHosts是Python语言写的一个程序,它会分析sshd的日志文件,当发现重复的攻击时就会记录IP到/etc/hosts.deny文件,从而达到自动屏IP的功能。 DenyHosts官方网站为:http://denyhosts.sourceforge.net 以下是安装记录(以CentOS 5.1, DenyHosts 2.6 为例) 1.安装 #wget http://nchc.dl.sourceforge.net/sourceforge/denyhosts/DenyHosts-2.6-python2.4.noarch.rpm #rpm -ivh DenyHosts-2.6-python2.4.noarch.rpm 给denyhosts做成系统本身的服务 # cd /etc/init.d # ln -s /usr/share/denyhosts/daemon-control-dist denyhosts # chkconfig –add denyhosts 2.配置 默认是安装到/usr/share/denyhosts目录的。 # cd /usr/share/denyhosts/ # cp denyhosts.cfg-dist denyhosts.cfg # vi denyhosts.cfg 根据自己需要进行相应的配置(解释见下文件的配置文件) DenyHosts配置文件: SECURE_LOG = /var/log/secure #ssh 日志文件,它是根据这个文件来判断的。 HOSTS_DENY = /etc/hosts.deny #控制用户登陆的文件 PURGE_DENY = 30m #过多久后清除已经禁止的 BLOCK_SERVICE = sshd #禁止的服务名 DENY_THRESHOLD_INVALID = 1 #允许无效用户失败的次数 DENY_THRESHOLD_VALID = 3 #允许普通用户登陆失败的次数 DENY_THRESHOLD_ROOT = 5 #允许root登陆失败的次数 HOSTNAME_LOOKUP=NO #是否做域名反解 ADMIN_EMAIL = iakuf@163.com #管理员邮件地址,它会给管理员发邮件 DAEMON_LOG = /var/log/denyhosts #自己的日志文件 3.启动服务 让他和系统启动时一起启动 #/etc/ini.d/denyhosts start #chkconfig denyhosts on 可以用一台电脑远程连接过来测试.如果可以看到/etc/hosts.deny内是否有禁止的IP,有的话说明已经安装成功了。 注.我发现时间deny以后,删除ip的时间不是很准.解决的方法是改变DAEMON_PURGE = 这个的时间.我发现系统删除时间是以他为准. DAEMON_PURGE:预设清除:当DenyHosts在预设模式下执行,执行清除机械作用过期最久的HOSTS_DENY,这个会影响PURGE_DENY的间隔

2009-10-13 · 1 min · 91 words · kevin

修改oracle默认端口

oracle更改默认端口号,监听器加密,限制ip访问—打造更安全的oracle系统 2009-06-09 13:31 auther: skate time: 2008/07/19 os:windowsxp sp2 db:oracle10g2 oracle数据库的安全包含两部分: 1.一部分是os的安全 2.网络的安全 2.oracle软件本身的安全 os的安全依赖相应的操作系统及管理员的技术水平,我们这里只谈谈oracle的安全 我了解的oracle软件的安全包含: 1.更改oracle的默认监听端口号 2.给监听器加密码 3.oracle控制ip的连接 下面将针对这三个方面测试学习 ———oracle默认监听端口更改————– 1. 更改oracle的默认监听端口号 修改端口号的整体步骤 1.1 。 查看当前监听的状态 1.2 。 停止监听 1.3 。 修改监听文件的端口号 1.4 。 修改初始化参数local_listener 1.5 . 重启监听器 1.6 。 修改完毕,使用新端口登录测试 实践步骤: 1.1 。 查看当前监听的状态 C:\Documents and Settings\skate_db>lsnrctl status LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 19-7月 -2008 12:1 1:19 Copyright (c) 1991, 2005, oracle. All rights reserved. 正在连接到 (DEION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) LISTENER 的 STATUS ———————— 别名 LISTENER 版本 TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Produ ction 启动日期 19-7月 -2008 11:47:59 正常运行时间 0 天 0 小时 23 分 19 秒 跟踪级别 off 安全性 ON: Password or Local OS Authentication SNMP OFF 监听程序参数文件 E:\oracle\product\10.2.0\db_3\network\admin\listener.o ra 监听程序日志文件 E:\oracle\product\10.2.0\db_3\network\log\listener.log 监听端点概要… (DEION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc))) (DEION=(ADDRESS=(PROTOCOL=tcp)(HOST=skate)(PORT=1522))) 服务摘要.. 服务 “PLSExtProc” 包含 1 个例程。 例程 “PLSExtProc”, 状态 UNKNOWN, 包含此服务的 1 个处理程序… 服务 “orcl” 包含 1 个例程。 例程 “orcl”, 状态 READY, 包含此服务的 1 个处理程序… 服务 “orclXDB” 包含 1 个例程。 例程 “orcl”, 状态 READY, 包含此服务的 1 个处理程序… 服务 “orcl_XPT” 包含 1 个例程。 例程 “orcl”, 状态 READY, 包含此服务的 1 个处理程序… 命令执行成功 1.2 。 停止监听 C:\Documents and Settings\skate_db>lsnrctl stop LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 19-7月 -2008 13:1 6:15 Copyright (c) 1991, 2005, oracle. All rights reserved. 正在连接到 (DEION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) 命令执行成功 1.3 。 修改监听文件的端口号,用于网络连接 把端口号修改为1523 # listener.ora Network Configuration E:\oracle\product\10.2.0\db_3\network\admin\listener.ora # Generated by oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = E:\oracle\product\10.2.0\db_3) (PROGRAM = extproc) ) ) LISTENER = (DEION_LIST = (DEION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) (ADDRESS = (PROTOCOL = TCP)(HOST = skate)(PORT = 1523)) ) ) #—-ADDED BY TNSLSNR 12-7月 -2008 13:26:50— PASSWORDS_LISTENER = 3650F1EB3C37ABD9 #——————————————— 1.4 。 修改初始化参数local_listener ,用于本地连接 C:\Documents and Settings\skate_db>sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on 星期六 7月 19 13:24:02 2008 Copyright (c) 1982, 2005, oracle. All rights reserved. 连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options SQL> show parameter local_listener NAME TYPE ———————————— ———– —————————— local_listener string (address=(protocol=tcp)(host=s kate)(port=1522)) SQL> alter system set local_listener="(address=(protocol=tcp)(host=skate)(port=1 523))"; 系统已更改。 1.5 . 重启监听器 C:\Documents and Settings\skate_db>lsnrctl start LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 19-7月 -2008 13:2 7:44 Copyright (c) 1991, 2005, oracle. All rights reserved. 启动tnslsnr: 请稍候… TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Production 系统参数文件为E:\oracle\product\10.2.0\db_3\network\admin\listener.ora 写入E:\oracle\product\10.2.0\db_3\network\log\listener.log的日志信息 监听: (DEION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc))) 监听: (DEION=(ADDRESS=(PROTOCOL=tcp)(HOST=skate)(PORT=1523))) 正在连接到 (DEION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) LISTENER 的 STATUS ———————— 别名 LISTENER 版本 TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Produ ction 启动日期 19-7月 -2008 13:27:47 正常运行时间 0 天 0 小时 0 分 3 秒 跟踪级别 off 安全性 ON: Password or Local OS Authentication SNMP OFF 监听程序参数文件 E:\oracle\product\10.2.0\db_3\network\admin\listener.o ra 监听程序日志文件 E:\oracle\product\10.2.0\db_3\network\log\listener.log 监听端点概要… (DEION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc))) (DEION=(ADDRESS=(PROTOCOL=tcp)(HOST=skate)(PORT=1523))) 服务摘要.. 服务 “PLSExtProc” 包含 1 个例程。 例程 “PLSExtProc”, 状态 UNKNOWN, 包含此服务的 1 个处理程序… 命令执行成功 1.6 。 修改完毕,使用新端口登录测试 1.6.1。 检查监听端口是否改变 C:\Documents and Settings\skate_db>netstat -an | find “1523” TCP 0.0.0.0:1523 0.0.0.0:0 LISTENING TCP 192.168.0.103:1523 192.168.0.103:2389 ESTABLISHED TCP 192.168.0.103:2389 192.168.0.103:1523 ESTABLISHED 1.6.2。 查看监听器的状态 C:\Documents and Settings\skate_db>lsnrctl status LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 19-7月 -2008 13:2 8:56 Copyright (c) 1991, 2005, oracle. All rights reserved. 正在连接到 (DEION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) LISTENER 的 STATUS ———————— 别名 LISTENER 版本 TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Produ ction 启动日期 19-7月 -2008 13:27:47 正常运行时间 0 天 0 小时 1 分 10 秒 跟踪级别 off 安全性 ON: Password or Local OS Authentication SNMP OFF 监听程序参数文件 E:\oracle\product\10.2.0\db_3\network\admin\listener.o ra 监听程序日志文件 E:\oracle\product\10.2.0\db_3\network\log\listener.log 监听端点概要… (DEION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc))) (DEION=(ADDRESS=(PROTOCOL=tcp)(HOST=skate)(PORT=1523))) 服务摘要.. 服务 “PLSExtProc” 包含 1 个例程。 例程 “PLSExtProc”, 状态 UNKNOWN, 包含此服务的 1 个处理程序… 服务 “orcl” 包含 1 个例程。 例程 “orcl”, 状态 READY, 包含此服务的 1 个处理程序… 服务 “orclXDB” 包含 1 个例程。 例程 “orcl”, 状态 READY, 包含此服务的 1 个处理程序… 服务 “orcl_XPT” 包含 1 个例程。 例程 “orcl”, 状态 READY, 包含此服务的 1 个处理程序… 命令执行成功 1.6.3 。使用新端口号(1523)登录测试一下 C:\Documents and Settings\skate_db>sqlplus SQL*Plus: Release 10.2.0.1.0 - Production on 星期六 7月 19 13:32:15 2008 Copyright (c) 1982, 2005, oracle. All rights reserved. 请输入用户名: sys/oracle@skate:1523/orcl as sysdba 连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options SQL> SQL> select * from v$version; BANNER —————————————————————- Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod PL/SQL Release 10.2.0.1.0 - Production CORE 10.2.0.1.0 Production TNS for 32-bit Windows: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production SQL> select open_mode from v$database; OPEN_MODE ———- READ WRITE SQL> 注意:当修改了oracle默认监听端口后,用tnsping会出错的,因为这个时候,oracle会 读tnsnames。ora这个文件,而这个文件的端口号没有更改,只要更改下这里对应的 端口号就ok。 eg: C:\Documents and Settings\skate_db>tnsping orcl TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 19-7月 - 2008 17:11:05 Copyright (c) 1997, 2005, oracle. All rights reserved. 已使用的参数文件: E:\oracle\product\10.2.0\db_3\network\admin\sqlnet.ora 已使用 TNSNAMES 适配器来解析别名 Attempting to contact (DEION = (ADDRESS = (PROTOCOL = TCP)(HOST = skate)(P ORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl))) TNS-12541: TNS: 无监听程序 在这里可以看到,oracle仍然用端口1521,我们更改下tnsnames.ora的端口号,就ok了。 # tnsnames.ora Network Configuration E:\oracle\product\10.2.0\db_3\network\admin\tnsnames.ora # Generated by oracle configuration tools. ORCL = (DEION = (ADDRESS = (PROTOCOL = TCP)(HOST = skate)(PORT = 1523)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) EXTPROC_CONNECTION_DATA = (DEION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) ) 重启监听器,在tnsping C:\Documents and Settings\skate_db>tnsping orcl TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 19-7月 - 2008 17:22:00 Copyright (c) 1997, 2005, oracle. All rights reserved. 已使用的参数文件: E:\oracle\product\10.2.0\db_3\network\admin\sqlnet.ora 已使用 TNSNAMES 适配器来解析别名 Attempting to contact (DEION = (ADDRESS = (PROTOCOL = TCP)(HOST = skate)(P ORT = 1523)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl))) OK (50 毫秒) ———oracle默认监听端口更改————– ××××××××××××××××××××××××××oracle控制ip的连接×××××××××××××××××××××××× 2 .oracle控制ip的连接(我们也可以用数据库触发器记录用户的登录情况,但是不能记录dba权限的用户) 单纯的设定允许的IP 和 禁止的IP,在oracle9i以前有文档说增加或修改protocol.ora文件, 在9i及以后版本中真正起作用的是sqlnet.ora文件,我们修改sqlnet.ora其实是最好最快的方法 sqlnet.ora文件的功能: 1. Specify the client domain to append to unqualified names 2. Prioritize naming methods 3. Enable logging and tracing features 4. Route connections through specific processes 5. Configure parameters for external naming 6. Configure oracle Advanced Security 7. Use protocol-specific parameters to restrict access to the database 我在这里用的就是第7个功能 在sqlnet.ora中增加如下部分 —————————– tcp.validnode_checking=yes #允许访问的IP tcp.invited_nodes=(ip1,ip2……) #禁止访问的IP tcp.excluded_nodes=(ip1,ip2……) 之后重新启动监听器即可 eg: # sqlnet.ora Network Configuration E:\oracle\product\10.2.0\db_3\network\admin\sqlnet.ora # Generated by oracle configuration tools. # This file is actually generated by netca. But if customers choose to # install “Software Only”, this file wont exist and without the native # authentication, they will not be able to connect to the database on NT. SQLNET.AUTHENTICATION_SERVICES= (NTS) NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT) #skate modify tcp.validnode_checking=yes tcp.invited_nodes=(192.168.0.103) tcp.excluded_nodes=(192.168.0.10) 需要注意的问题: 1、 需要设置参数为YES,这样才能激活。 2、 建议设置允许访问的IP,因为IP地址有可能被随意修改,就不能起到自己的目的。 3、 TCP当参数TCP.INVITED_NODES和TCP.EXCLUDED_NODES设置的地址相同的时候将覆盖TCP.EXCLUDED_NODES设置。 4、 需要重启监听器才能生效。 5、 这个方式只是适合TCP协议。 6、 这个配置适用于9i以上版本。在9i之前的版本使用文件protocol.ora。 7、 在服务器上直接连接数据库不受影响。 8、 这种限制方式事通过监听器来限制的。 9、 这个限制只是针对IP检测,对于用户名检测事不支持的。 ××××××××××××××××××××××××××oracle控制ip的连接×××××××××××××××××××××××× 3. 给监听器加密码

2009-10-13 · 5 min · 1016 words · kevin

linux文件编码转换

在Linux命令行下查看看文件的编码 enca 文件名 linux文件名编码批量转换 convmv -f 源编码 -t 新编码 [选项] 文件名 常用参数: -r 递归处理子文件夹 –notest 真正进行操作,请注意在默认情况下是不对文件进行真实操作的,而只是试验。 –list 显示所有支持的编码 –unescap 可以做一下转义,比如把%20变成空格 比如我们有一个utf8编码的文件名,转换成GBK编码,命令如下: convmv -f UTF-8 -t GBK –notest utf8编码的文件名 Linux下批量转换文件内容编码 1.使用enca,例如要把当前目录下的所有文件都转成utf-8 $enca -x utf-8 * 2,使用iconv 转换 iconv的命令格式如下: iconv -f encoding -t encoding inputfile 比如将一个UTF-8 编码的文件转换成GBK编码 iconv -f GBK -t UTF-8 file1 -o file2

2009-10-13 · 1 min · 53 words · kevin