[原创]sysrc命令简介_VMware, Unix及操作系统讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  VMware, Unix及操作系统讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 3357 | 回复: 0   主题: [原创]sysrc命令简介        下一篇 
wulcan
版主
等级:中校
经验:1795
发帖:124
精华:0
注册:2014-3-19
状态:离线
发送短消息息给wulcan 加好友    发送短消息息给wulcan 发消息
发表于: IP:您无权察看 2015-7-25 9:33:11 | [全部帖] [楼主帖] 楼主

在传统的FreeBSD中,如果要添加一个启动项目,必须手工编辑/etc/rc.conf,这对于单机来说算不上什么,但是如果有大量的机器需要添加,逐个机器编辑,那么就太麻烦了。可以写shell或其他程序,但是也比较麻烦,因为需要配合sed/awk等工具才可以。
那么有没有可以在命令行中,或者在其他程序中可以方便调用的启动项目编译工具呢?
自从FreeBSD9.2开始,提供了一个新的工具:sysrc。
这个工具的目的就是安全地编辑/etc/rc.conf,可以方便地在命令行进行添加或修改启动项目。

例一、查看当前的启动配置项目:

root@test: # sysrc -a
defaultrouter: 192.168.1.1
dumpdev: NO
firewall_enable: yes
firewall_script: /etc/ipfw.sh
fsck_y_enable: yes
gateway_enable: yes
gerbil_enable: yes
hostname: db2
ifconfig_igb0: inet 192.168.1.22 netmask 255.255.255.0
powerd_enable: YES
sendmail_enable: NONE
sendmail_msp_queue_enable: NO
sendmail_outbound_enable: NO
sendmail_submit_enable: NO
sshd_enable: YES
syslogd_enable: yes
syslogd_flags: -s -s


这是我比较常用的配置,这个命令显示当前配置与默认配置(/etc/default/rc.conf)中不一致的项目。

例二、查看可以配置的启动项,并显示当前的值

 root@test: # sysrc -A grep zfs
zfs_enable: NO
root@test: # sysrc -A grep sendmail
mta_start_script: /etc/rc.sendmail
sendmail_cert_create: YES
sendmail_enable: NONE
sendmail_flags: -L sm-mta -bd -q30m
sendmail_msp_queue_enable: NO
sendmail_msp_queue_flags: -L sm-msp-queue -Ac -q30m
sendmail_outbound_enable: NO
sendmail_outbound_flags: -L sm-queue -q30m
sendmail_pidfile: /var/run/sendmail.pid
sendmail_procname: /usr/sbin/sendmail
sendmail_rebuild_aliases: NO
sendmail_submit_enable: NO
sendmail_submit_flags: -L sm-mta -bd -q30m -ODaemonPortOptions=Addr=localhost


Sendmail的配置项目很多,也经常忘记具体的拼写,有了这个提示,就可以复制粘贴了。

例三、查看某个项目的说明:

 root@test: # sysrc -d sendmail_rebuild_aliases
DEBUG: f_debug_init: debug=[1] debugFile=[]
DEBUG: UNAME_S=[FreeBSD] UNAME_P=[amd64] UNAME_R=[10.0-RELEASE]
DEBUG: common.subr: Successfully loaded.
DEBUG: f_include: file=[/usr/share/bsdconfig/sysrc.subr]
DEBUG: sysrc.subr: loading includes...
DEBUG: f_include_lang: file=[/usr/libexec/bsdconfig/include/messages.subr] lang=[]
DEBUG: sysrc.subr: Successfully loaded.
sendmail_rebuild_aliases: Run newaliases if necessary (YES/NO).


从DEBUG信息可以看到,sysrc本身需要加载很多文件。

例四、启用鼠标(moused)服务:

 root@test: # sysrc moused_enable=yes
moused_enable: NO -> yes


验证一下:

 root@test: # tail -n 1 /etc/rc.conf
moused_enable="yes"


例五、再禁用鼠标服务:

 root@test: # sysrc moused_enable=no
moused_enable: yes -> no


再来验证一下:

 root@test: # tail -n 1 /etc/rc.conf
moused_enable="no"


例六:查看现在的配置

 root@test: # sysrc sshd_enable
sshd_enable: YES
root@test: # sysrc nginx_enable
sysrc: unknown variable 'nginx_enable'


请注意第二个nginx的项目,等下还要用到

例七:添加一个启动项目

 root@test: # sysrc nginx_enable=yes
nginx_enable: -> yes


注意输出,显示空->yes,这表明以前没有,并且不在默认的配置(/etc/default/rc.conf)里面。
这个命令还有一个小bug:它不会解决你的手误:

root@test: # sysrc ngnix_enable=yes
ngnix_enable: -> yes


验证一下,注意两句的区别:

 root@test: # tail -n 2 /etc/rc.conf
nginx_enable="yes"
ngnix_enable="yes"


同样,它不会验证值是否正确:

 root@test: # sysrc ngnix_enable=yse
ngnix_enable: yes -> yse


所以运行命令的时候一定要小心。

最后,再提示一下:这个命令仅仅是添加/编辑启动项目,它不会“立即”启动项目,比如你添加了nginx_enable=”yes”,它不会马上把nginx服务启动,它仅仅是添加到系统启动中,下次启动的时候可以启动。
顺便提一句,如果马上启动nginx,可以用service命令:

service nginx start




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论