海运的博客

CentOS调整默认启动的TTY终端数量

发布时间:December 26, 2012 // 分类:CentOS // No Comments

CentOS默认启动6个TTY,在控制台下可用Alt+[F1—F6]键在不同的终端之间切换,通过SSH虚拟终端管理远程服务器是用不到这些的,可减少启动的TTY数量减少系统资源占用。
CentOS5修改配置文件注释禁止启动的TTY即可:

cat /etc/inittab
#2:2345:respawn:/sbin/mingetty tty2
#3:2345:respawn:/sbin/mingetty tty3
#4:2345:respawn:/sbin/mingetty tty4
#5:2345:respawn:/sbin/mingetty tty5
#6:2345:respawn:/sbin/mingetty tty6

CentOS6下修改启动的TTY数量:

sed -i 's/\/dev\/tty\[1-6\]/\/dev\/tty\[1-1\]/g' /etc/init/start-ttys.conf 
sed -i 's/\/dev\/tty\[1-6\]/\/dev\/tty\[1-1\]/g' /etc/sysconfig/init
#修改为启动1个TTY

关闭指定终端:

initctl stop tty TTY=/dev/ttyn

踢出指定终端用户:

pkill -kill -t ttyn

Linux下Git和GitHub基本使用

发布时间:December 15, 2012 // 分类:Git // No Comments

1.创建Github账号,Linux创建SSH密钥:

ssh-keygen

2.将公钥加入到Github账户信息Account Settings,测试验证是否成功。

ssh -T git@github.com
Hi haiyun.me! You've successfully authenticated, but GitHub does not provide shell access.

3.GitHub创建项目。
4.本地配置,新建Git项目并提交到Github。

touch README.md
git init #初始化,建立本地git仓库
git add README.md #添加文件到本地仓库
git status #查看本地代码库状态
git commit -m "first commit" #提交到本地仓库
git remote add origin git@github.com:user/test.git #和远程代码库建立连接
git remote -v #查看连接
git remote rm origin #删除链接
git pull origin master --allow-unrelated-histories #要更新已存的github仓库先拉到本地再提交
git push origin master #将本地仓库文件提交到Github。

5.复制项目到本地:

git clone git://github.com/user/xxx.git

6.删除GitHub文件:

git rm README.md #本地仓库内删除
git commit -m "rm README.md" #提交到本地
git push -u origin master #提交到Github

7.和远程项目连接,注意不要使用https clone:

git clone git@github.com:user/test.git
git add .
git status 
git commit -m "commit"
git push -u origin main

8.删除回滚到最近的commit:

git reflog
git reset --hard commit_id #回滚到的commit id
git push origin master --force

Linux SSH终端terminal配色更改为256色

发布时间:December 15, 2012 // 分类:Xshell // No Comments

一般使用Xshell通过SSH连接管理Centos/Debina服务器终端为8色,通过设置终端类型可开启256色彩以显示更加鲜艳的色彩。
查看当前终端类型:

echo $TERM 
xterm-color

查看当前服务器终端色彩:

tput colors
8

或使用以下脚本检测并以色彩方式:

#!/usr/bin/env python
#检测当前终端支持色彩
import sys
import os

def echo(msg):
    os.system('echo -n "' + str(msg) + '"')

def out(n):
    os.system("tput setab " + str(n) + "; echo -n " + ("\"% 4d\"" % n))
    os.system("tput setab 0")

# normal colors 1 - 16
os.system("tput setaf 16")
for n in range(8):
    out(n)
echo("\n")
for n in range(8, 16):
    out(n)

echo("\n")
echo("\n")

y=16
while y < 231:
    for z in range(0,6):
        out(y)
        y += 1

    echo("\n")

echo("\n")

for n in range(232, 256):
    out(n)
    if n == 237 or n == 243 or n == 249:
        echo("\n")

echo("\n")

配置Linux终端如果支持就调整为256色终端,添加到.bashrc文件内。

if [ -e /usr/share/terminfo/x/xterm-256color ]; then
#debian在/lib/terminfo/x/xterm-256color
        export TERM='xterm-256color'
else
        export TERM='xterm-color'
fi

如不支持xterm-256color安装:

apt-get install ncurses-base
yum install ncurses

扩展阅读:
Colour colour everywhere! 256 colour-mode for Linux consoles:http://www.robmeerman.co.uk/unix/256colours
256 colors in vim:http://vim.wikia.com/wiki/256_colors_in_vim

Windows/Cygwin下安装配置SSH服务器

发布时间:December 5, 2012 // 分类:Cygwin // No Comments

1.Cygwin安装OpenSSH,可使用apt-cyg包管理器快速安装。

apt-cyg install openssh

配置OpenSSH服务,以管理员运行Cygwin Terminal。

$ ssh-host-config
*** Info: Generating /etc/ssh_host_key
*** Info: Generating /etc/ssh_host_rsa_key
*** Info: Generating /etc/ssh_host_dsa_key
*** Info: Generating /etc/ssh_host_ecdsa_key
*** Info: Creating default /etc/ssh_config file
*** Info: Creating default /etc/sshd_config file
*** Info: Privilege separation is set to yes by default since OpenSSH 3.3.
*** Info: However, this requires a non-privileged account called 'sshd'.
*** Info: For more info on privilege separation read /usr/share/doc/openssh/README.privsep.
*** Query: Should privilege separation be used? (yes/no) yes
*** Info: Updating /etc/sshd_config file

*** Query: Do you want to install sshd as a service?
*** Query: (Say "no" if it is already installed as a service) (yes/no) yes
*** Query: Enter the value of CYGWIN for the daemon: [] ssh
*** Info: On Windows Server 2003, Windows Vista, and above, the
*** Info: SYSTEM account cannot setuid to other users -- a capability
*** Info: sshd requires.  You need to have or to create a privileged
*** Info: account.  This script will help you do so.

*** Info: You appear to be running Windows XP 64bit, Windows 2003 Server,
*** Info: or later.  On these systems, it's not possible to use the LocalSystem
*** Info: account for services that can change the user id without an
*** Info: explicit password (such as passwordless logins [e.g. public key
*** Info: authentication] via sshd).

*** Info: If you want to enable that functionality, it's required to create
*** Info: a new account with special privileges (unless a similar account
*** Info: already exists). This account is then used to run these special
*** Info: servers.

*** Info: Note that creating a new user requires that the current account
*** Info: have Administrator privileges itself.

*** Info: No privileged account could be found.

*** Info: This script plans to use 'cyg_server'.
*** Info: 'cyg_server' will only be used by registered services.
*** Query: Do you want to use a different name? (yes/no) yes
*** Query: Enter the new user name: ssh
*** Query: Reenter: ssh

*** Query: Create new privileged user account 'ssh'? (yes/no) yes
*** Info: Please enter a password for new user ssh.  Please be sure
*** Info: that this password matches the password rules given on your system.
*** Info: Entering no password will exit the configuration.
*** Query: Please enter the password:
*** Query: Reenter:

*** Info: User 'ssh' has been created with password 'passwd'.
*** Info: If you change the password, please remember also to change the
*** Info: password for the installed services which use (or will soon use)
*** Info: the 'ssh' account.

*** Info: Also keep in mind that the user 'ssh' needs read permissions
*** Info: on all users' relevant files for the services running as 'ssh'.
*** Info: In particular, for the sshd server all users' .ssh/authorized_keys
*** Info: files must have appropriate permissions to allow public key
*** Info: authentication. (Re-)running ssh-user-config for each user will set
*** Info: these permissions correctly. [Similar restrictions apply, for
*** Info: instance, for .rhosts files if the rshd server is running, etc].


*** Info: The sshd service has been installed under the 'ssh'
*** Info: account.  To start the service now, call `net start sshd' or
*** Info: `cygrunsrv -S sshd'.  Otherwise, it will start automatically
*** Info: after the next reboot.

*** Info: Host configuration finished. Have fun!

启动SSH服务:

cygrunsrv -S sshd

PXE启动KickStart全自动安装系统

发布时间:November 4, 2012 // 分类:PXE // No Comments

关于PXE服务器配置、客户端引导见之前文章:使用TFTP/PXE引导安装Centos系统
通过KickStart自动安装只需修改最后PXE引导菜单配置文件:

cat /tftpboot/pxelinux.cfg/default 
#www.haiyun.me
timeout 5
default menu.c32

menu title ########## PXE Boot Menu ##########
label 1
   menu label ^1) Install CentOS 6
   kernel centos6/vmlinuz
   append initrd=centos6/initrd.img ks=nfs:192.168.1.3:/tftpboot/ks.cf 
#引导获取KickStart配置文件,然后在KickStart文件中配置安装源。

KickStart配置文件可使用图形化配置,需安装桌面或开启X-Windows环境转发

yum install system-config-kickstart 

kickstart图形化配置工具.png
KickStart配置文件示例:

text
install
nfs --server=192.168.1.3 --dir=/mnt
#光盘镜像挂载目录
#url --url=http://192.168.1.3/mnt/ #可使用http或ftp
keyboard us
lang zh_CN.UTF-8
network --device eth0 --bootproto static --ip 192.168.1.30 --netmask 255.255.255.0 
--gateway 192.168.1.1 --nameserver 192.168.1.1 --hostname centos5.7-x64
firewall --disabled
rootpw onovps
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Aisa/Shang_Hai
bootloader --location=mbr
zerombr
clearpart --all --initlabel
part /boot --fstype ext4 --fsoptions="noatime" --size=200
part pv.1 --size 1 --grow
volgroup vg0 --pesize=4096 pv.1
logvol / --fstype ext4 --fsoptions="noatime" --name=root --vgname=vg0 --grow --size=8192
logvol swap --fstype swap --name=swap --vgname=vg0 --size 2048
 
%post
%end
%packages
@base
%end

这样局域网下机器以PXE启动就自动安装为相应的系统了。

分类
最新文章
最近回复
  • opnfense: 谢谢博主!!!解决问题了!!!我之前一直以为内置的odhcp6就是唯一管理ipv6的方式
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...