RHEL安装jdk包并配置环境变量
一、下载并安装jdk
下载地址http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
安装rpm包:
1 |
rpm -ivh jdk-7u60-linux-x64.rpm |
-i install
-v 显示详细进度
-h 打印50个hash标记
二、查看jdk安装目录
1 |
rpm -ql jdk |
-q query
-l list all packages
三、配置环境变量
1 2 3 4 5 6 7 |
vim /etc/profiles #在done 与 unset之间添加以下内容 JAVA_HOME=/usr/java/jdk1.7.0_60 CLASSPATH=.:$JAVA_HOME/lib.tools.jar PATH=$JAVA_HOME/bin:$PATH export JAVA_HOME CLASSPATH PATH |
四、重启生效
2014年6月24日 Linux 0 Read more >
CentOS安装salt并建立主从机cluster
官方文档:http://docs.saltstack.cn/
一、安装与部署
1.所有机器统一安装epel源
http://www.rackspace.com/knowledge_center/article/installing-rhel-epel-repo-on-centos-5x-or-6x
2.安装MASTER机
安装salt-master
1 |
yum install salt-master |
3.安装SLAVER(minion)机
1 |
yum install salt-minion |
二、配置
1.slaver机
a.配置主机名
1 2 3 |
vim /etc/sysconfig/network # 修改HOSTNAME HOSTNAME=salt_m1.localdomain |
b.配置master主机地址及salver主机名
1 2 3 4 5 6 |
vim /etc/salt/minion #取消注释#master这一行 master= 192.168.1.1 (master主机ip) # 取消注释 #id这一行 id= salt_m1 # 注意:‘=’后面要跟一个空格 |
3.启动服务
1 |
salt-minion -d |
2.master机
a.防火墙(如果开启了的话)开放4505和4506端口
http://docs.saltstack.cn/topics/tutorials/firewall.html
b.启动salt-master进程(改服务安装后为开机自启动,如有冲突检查一下是不是服务已经在运行了)
1 |
salt-master start |
c.验证slaver key
1 2 3 4 |
# 查看key状态 salt-key -L # 通过所有的key salt-key -A |
打完收工。
2014年6月23日 Linux 0 Read more >
多网卡分别连接内网、外网等多个Vlan——
一、重启失效的方法
-
配好路由表,来使用多个网络。
1 |
route add -net 172.19.0.0/16 gw 172.19.17.254 |
172.19网段全部走172.19.17.254网关。
2.给某个网卡添加静态路由
1 |
route add -host 192.168.254.1 dev eth1 |
3.route命令的使用
1 2 3 4 |
#删除默认路由 route del -net 0.0.0.0 gw 192.168.1.1 #增加默认路由 route add -net 0.0.0.0 gw 192.168.1.1 |
二、写到配置文件里(/etc/rc.local)
使路由在重启后依然有效,就要把配置写到开机配置文件中。
格式如下:
1 |
route add -net 172.19.17.0/24 gw 172.19.17.254 dev eth0 |
就是这样
打完收工
2014年6月19日 Linux 0 Read more >
Centos使用sed在脚本中处理文件
鸟哥的链接:http://linux.vbird.org/linux_basic/0330regularex.php
包含好多栗子的blog:http://www.cnblogs.com/emanlee/archive/2013/09/07/3307642.html
使用场景:查询文本文件行,对其进行修改。
1 |
sed -i 's/#MaxAuthTries 6/MaxAuthTries 3/g' /etc/ssh/sshd_config |
我需要注意的:
- sed的正则表达式在脚本中运行与bash不同(故不能使用bash测试其效果,放到脚本中去跑)
- sed的正则表达式还是用POSIX表达方式。vim格式表示空格的诸如s不生效。:
1 2 |
sed -i 's/password[[:blank:]]*substack[[:blank:]]*system-auth/password include system-auth/g' /etc/pam.d/passwd #假如使用s+,前述sed不能生效 |
TFTP与FTP的比较
2014年6月17日 Linux 0 Read more >
CentOS安装vsftpd并建立ftp服务
参考:http://blog.sina.com.cn/s/blog_4a55c0c50100i1ok.html
一、安装vdftpd
1 |
yum install vsftpd |
二、配置vsftpd
1、修改/etc/vsftpd/vsftpd.conf
1 2 3 4 5 6 7 8 9 10 11 12 |
#【a】开启匿名登录 # Allow anonymous FTP? (Beware - allowed by default if you comment this out). anonymous_enable=YES #【b】允许修改root目录 # You may specify an explicit list of local users to chroot() to their home # directory. If chroot_local_user is YES, then this list becomes a list of # users to NOT chroot(). chroot_list_enable=YES #【c】与user_list文件的关联 userlist_enable=YES |
2、修改/etc/vsftpd/user_list文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 全部注释(未注释的用户被拒绝访问,不给输密码的机会) # vsftpd userlist # If userlist_deny=NO, only allow users in this file # If userlist_deny=YES (default), never allow users in this file, and # do not even prompt for a password. # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers # for users that are denied. #root #bin #daemon #adm #lp #sync #shutdown #halt #mail #news #uucp #operator #games #nobody |
3、修改/etc/vsftpd/ftpusers文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# 全部注释(未注释的用户将无法登陆) # Users that are not allowed to login via ftp #root #bin #daemon #adm #lp #sync #shutdown #halt #mail #news #uucp #operator #games #nobody |
三、关闭selinux(否则无法列出目录)(有了新的未验证的解决办法,见五)
1 2 3 4 5 6 7 8 9 |
vim /etc/selinux/config # 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=enforcing SELINUX=disabled |
四、重启服务并添加该服务到自动启动项
1 2 |
service vsftpd restart chkconfig --level 35 vsftpd on |
五、在开启selinux的情况下使用ftp(修改selinux中ftp相关bool值)
1.查看selinux关于ftp的bool值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@i Desktop]# getsebool -a|grep ftp allow_ftpd_anon_write --> off allow_ftpd_full_access --> off allow_ftpd_use_cifs --> off allow_ftpd_use_nfs --> off ftp_home_dir --> off ftpd_connect_db --> off ftpd_use_fusefs --> off ftpd_use_passive_mode --> off httpd_enable_ftp_server --> off tftp_anon_write --> off tftp_use_cifs --> off tftp_use_nfs --> off |
2.修改selinux bool
1 2 3 4 5 6 7 8 9 10 |
经过尝试发现,打开ftp_home_dir或者 ftpd_disable_trans。都可以达到在enforcing级别下,允许FTP正常登录的效果。 setsebool -P ftpd_disable_trans 1 或者 setsebool -P ftp_home_dir 1 #【确保!】 allow_ftpd_full_access on service vsftpd restart 加-P是保存选项,每次重启时不必重新执行这个命令了。最后别忘了在/etc/sysconfig/selinux中,修改SELINUX=enforcing。 |
六、限制ftp用户于自己的home目录
参见参考博客吧 好困,去睡觉
七、使用被动模式
当1024以上端口不可用时,需要采用被动模式连接ftp
因端口不可用产生的报错:
1 2 3 4 5 |
ftp> cd / 250 Directory successfully changed. ftp> dir 200 PORT command successful. Consider using PASV. 425 Failed to establish connection. |
使用被动模式:
1 2 3 4 5 6 7 8 9 10 |
ftp> dir 200 PORT command successful. Consider using PASV. 425 Failed to establish connection. ftp> passive Passive mode on. ftp> dir 227 Entering Passive Mode (). 150 Here comes the directory listing. drwxr-xr-x 4 0 0 4096 Mar 04 07:05 app …… |
打完收工
CentOS dnsmasq 功能外篇
放大招,师父的blog.
PXE:http://debugo.com/dnsmasq-pxe/
KICKSTART:http://debugo.com/kickstart-install-centos/
一、PXE篇
1.配置PXE服务的工作都在/etc/dnsmasq.conf文件里:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# 【A】配置DHCP启动的程序 # Set the boot filename for netboot/PXE. You will only need # this is you want to boot machines over the network and you will need # a TFTP server; either dnsmasq's built in TFTP server or an # external one. (See below for how to enable the TFTP server.) dhcp-boot=pxelinux.0 # 【B】建立tftp服务(为dhcp-boot提供启动所需文件) # Enable dnsmasq's built-in TFTP server enable-tftp # Set the root directory for files availble via FTP. tftp-root=/tftp |
2.安装syslinux
syslinux科普:http://baike.baidu.com/view/3867652.htm?fr=aladdin
安装很简单:
1 |
yum install syslinux |
3.在tftp目录放置需要的文件
【A】syslinux在远端机器运行所需的文件
安装后查看syslinux安装情况:
1 |
rpm -ql syslinux |
syslinux运行所需文件目录:/usr/share/syslinux/
拷贝到tftp目录:
1 |
cp -rf /usr/share/syslinux/* /tftp/ |
【B】安装linux所需的ISOLinux文件
在linux的yum源或者安装文件里,有isolinux目录。
PXE运行时需要该目录下三个文件。
[1]启动镜像
*/isolinux/initrb.img
*/isolinux/vmlinuz
拷贝到tfpt根目录。
[2]安装配置文件
*/isolinux/isolinux.cfg
拷贝并变更文件名如下
/tftp/pxelinux.cfg/default
至此,pxe的配置完成。在本网段能够拿到由dnsmasq分发的IP,并通过网卡启动的机器,已经可以通过网络启动linux。
二、kickstart
使用kickstart进行远程安装
1.安装vsftpd及autofs作为安装镜像源
安装vsftpd:http://chaihuo.blog.51cto.com/6386339/1426938
安装autofs:http://chaihuo.blog.51cto.com/6386339/1426941
2.安装kickstart
1 2 3 |
yum install system-config-kickstart # 运行后根据图形界面提示生成kickstart文件ks.cfg system-config-kickstart |
3.在pxelinux中配置ks.cfg
【a】将ks.cfg文件放到var/ftp/ (ftp根目录)
【b】编辑pxelinux配置文件,在initrd=initrd.img后加上ks=ftp://ftpserver/ks.cfg
1 2 3 4 5 |
label linux menu label ^Install or upgrade an existing system menu default kernel vmlinuz append initrd=initrd.img ks=ftp://IPADDR/ks.cfg |
4.在%end之前添加%post及内容
1 2 3 4 5 6 7 |
%post ####System hardening#### # close service chkconfig NetworkManager off chkconfig abrt-ccpp off %end |
CentOS安装autofs以建
一、安装
1 |
yum install autofs |
二、配置目录的配置文件map
修改/etc/autofs.master
1 2 3 4 5 6 7 8 |
# 标记/var/ftp/pub目录的配置文件为/etc/auto.vsftpd # Sample auto.master file # This is an automounter map and it has the following format # key [ -mount-options-separated-by-comma ] location # For details of the format look at autofs(5). # #/misc /etc/auto.misc /var/ftp/pub /etc/auto.vsftpd |
三、创建目录配置文件/etc/auto.vsftpd
1 2 3 4 |
vim /etc/auto.vsftpd #添加一行 iso6 -fstype=iso9660,ro,loop :/home/admin/Downloads/CentOS-6.5-x86_64-bin-DVD1.iso |
注1:man 5 autofs获得帮助
注2:前述格式为:
A B C
mount到的目录 文件格式 被mount的(镜像)文件目录
四、重启服务
1 |
service autofs restart |
2014年6月16日 Linux 0 Read more >
CentOS建立DHCP服务2——系统自带的dnsmasq
先祭出师父的不老歌:http://debugo.com/dnsmasq/
dnsmasq is a lightweight DNS, TFTP and DHCP server.
这货可以用于dns,tftp,DHCP。
配置文档位置:/etc/dnsmasq.conf
使用文档(巨特么长):See”/usr/sbin/dnsmasq –help” or “man 8 dnsmasq” for details.
Getting start
一、DHCP server的几个小配置:
1.配置监听端口(就是我从哪个网卡或者ip接受DHCP请求):
1 2 3 4 5 6 7 8 9 10 |
# If you want dnsmasq to listen for DHCP and DNS requests only on # specified interfaces (and the loopback) give the name of the # interface (eg eth0) here. # Repeat the line for more than one interface. #interface= # Or you can specify which interface _not_ to listen on #except-interface= # Or which to listen on by address (remember to include 127.0.0.1 if # you use this.) listen-address=192.168.0.101(本机IP),127.0.0.1 |
2.DHCP地址池及有效时间
1 2 3 4 5 6 |
# Uncomment this to enable the integrated DHCP server, you need # to supply the range of addresses available for lease and optionally # a lease time. If you have more than one network, you will need to # repeat this for each network on which you want to supply DHCP # service. dhcp-range=192.168.0.50,192.168.0.150,12h |
3.给MAC地址为的主机分配:IP,主机名,有效时间
1 2 3 |
# Always give the host with ethernet address 11:22:33:44:55:66 # the name fred and IP address 192.168.0.60 and lease time 45 minutes dhcp-host=11:22:33:44:55:66,fred,192.168.0.60,45m |
4.配域
1 2 3 4 5 6 7 8 |
# Set the domain for dnsmasq. this is optional, but if it is set, it # does the following things. # 1) Allows DHCP hosts to have fully qualified domain names, as long # as the domain part matches this setting. # 2) Sets the "domain" DHCP option thereby potentially setting the # domain of all systems configured by DHCP # 3) Provides the domain part for "expand-hosts" domain=thekelleys.org.uk |
二、dns server的配置
犯懒了,直接看师父的吧:
注:如果IP池里的IP被占用,或者没有可用IP,则分配IP的任何操作都不会生效。这时应该先检查IP的使用情况,而不是配置文件表述错误(毕竟有例子,书写错误的概率太低了好嘛!)
没打完,也收工了
CentOS建立DHCP服务1——安装dhcp
OPTION 1:
一、安装dhcp
1 |
yum install dhcp |
二、打开并修改配置文件etc/dhcpd.conf
1. 复制配置范例/usr/share/doc/dhcp*/dhcpd.conf.sample到前述文件
2. 修改配置文件中内容
主要是域信息和子网信息
三、重启服务&开机自启动
1 2 |
service dhcpd restart chkconfig dhcpd on |
打完收工
reference:http://debugo.com/linux-dhcpd/