免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1336 | 回复: 4
打印 上一主题 下一主题

[FreeBSD] Renaming a jail [复制链接]

论坛徽章:
13
15-16赛季CBA联赛之同曦
日期:2016-01-28 19:52:032015亚冠之北京国安
日期:2015-10-07 14:28:19NBA常规赛纪念章
日期:2015-05-04 22:32:03处女座
日期:2015-01-15 19:45:44卯兔
日期:2014-10-28 16:17:14白羊座
日期:2014-05-24 15:10:46寅虎
日期:2014-05-10 09:50:35白羊座
日期:2014-03-12 20:52:17午马
日期:2014-03-01 08:37:27射手座
日期:2014-02-19 19:26:54子鼠
日期:2013-11-30 09:03:56狮子座
日期:2013-09-08 08:37:52
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-07-26 07:49 |只看该作者 |倒序浏览
本帖最后由 ulovko 于 2012-07-26 07:51 编辑

FreeBSD jails are a great tool. Whether you are using them to virtualize some of your systems (like I am) or to isolate certain processes, they are flexible enough and reliable enough to use for production.

Recently, I had to retire some old jails and add some new jails. Instead of just deleting one and creating an new jail, I wanted to rename the existing jail. I figured this was easier than recompiling all the apps that my jail would require.

A few notes on this decision:

  • My jails are all very similar.
  • In this case, I was moving from one version of PostgreSQL to another
  • One jail is called pg74 (as in PostgreSQL 7.4)
  • I was going to retire pg74 (which does regression tests on Bacula against PostgreSQL 7.4) and create pg91

Also, I am using ezjail to administer my jails. This tool is used several times in this article. That said, you will still see what I'm doing, and if you're not using ezjail, you'll be able to do the same thing with your admin tool of choice.

Removing, but not deleting, the old jail
The first step: stop the old jail.
  1. # /usr/local/etc/rc.d/ezjail stop pg74.example.org
  2. Stopping jails: pg74.example.org.
复制代码
Now, let's remove the jail from ezjail's configuration. Note that I could have skipped the previous step by adding the -f flag to this step:
  1. # ezjail-admin delete pg74_example_org
复制代码
At this point, the jail is no longer running. However, the files are still present on disk:
  1. # ls /usr/jails/pg74.example.org/
  2. .cshrc    COPYRIGHT bin       dev       home      libexec   mnt       rescue    sbin      tmp       var
  3. .profile  basejail  boot      etc       lib       media     proc      root      sys       usr
复制代码
Modifying the DNS (optional)
In my case, I wanted to create a new hostname to go with the new jail. But I was going to use the same IP address. This is the patch to my DNS zone files.
  1. $ cvs di example.org.db example.org.rev.db
  2. Index: example.org.db
  3. ===================================================================
  4. RCS file: /home/repositories/websites/dns-private/example.org.db,v
  5. retrieving revision 1.101
  6. diff -r1.101 example.org.db
  7. 5c5
  8. <                               2012011700      ; Serial
  9. ---
  10. >                               2012060800      ; Serial
  11. 157c157
  12. < pg74     IN A 10.0.0.104
  13. ---
  14. > pg91     IN A 10.0.0.104
  15. Index: example.org.rev.db
  16. ===================================================================
  17. RCS file: /home/repositories/websites/dns-private/example.org.rev.db,v
  18. retrieving revision 1.32
  19. diff -r1.32 example.org.rev.db
  20. 3c3
  21. <                               2011072600      ; Serial
  22. ---
  23. >                               2012060800      ; Serial
  24. 33c33
  25. < 104 IN  PTR pg74.example.org.
  26. ---
  27. > 104 IN  PTR pg91.example.org.
复制代码
Making these changes and updating your DNS is outside the scope of this article. I'm mentioning it here so I remember this step when I need to do this again.

'Creating' the 'new' jail
In this step, we rename the directory and create the new jail.

First, we rename the directory. Strictly speaking, this is optional. The name of the directory is not related to the hostname of the jail. But convention dictates that the jail directory name should reflect the hostname for that jail.
  1. # cd /usr/jails/
  2. # mv -i pg74.example.org pg91.example.org
复制代码
Now, let's start the new jail:
  1. # ezjail-admin create -x pg91.example.org 10.0.0.104
  2. Warning: Some services already seem to be listening on IP 10.0.0.104
  3.   This may cause some confusion, here they are:
  4. root     ntpd       1459  27 udp4   10.0.0.104:123       *:*
  5. Warning: Some services already seem to be listening on all IP, (including 10.0.0.104)
  6.   This may cause some confusion, here they are:
  7. root     ntpd       1459  20 udp4   *:123                 *:*
  8. root     ntpd       1459  21 udp6   *:123                 *:*
复制代码
Starting the new jail
This was easier than I thought. Starting the new jail is simple:
  1. # /usr/local/etc/rc.d/ezjail start pg91.example.org
复制代码
Then you ssh to it and check the host name:
  1. $ ssh -A pg91
  2. The authenticity of host 'pg91.example.org (10.0.0.104)' can't be established.
  3. RSA key fingerprint is 0a:03:db:1a:b4:28:da:fd:66:c0:29:a4:0a:4b:77:30.
  4. Are you sure you want to continue connecting (yes/no)? yes
  5. Warning: Permanently added 'pg91.example.org' (RSA) to the list of known hosts.
  6. Last login: Fri Jun  8 22:58:22 2012 from 10.0.0.104
  7. Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
  8.         The Regents of the University of California.  All rights reserved.

  9. FreeBSD 8.2-STABLE (KRAKEN) #3: Fri Nov 18 22:07:46 UTC 2011

  10. Welcome to FreeBSD!

  11. Before seeking technical support, please use the following resources:

  12. o  Security advisories and updated errata information for all releases are
  13.    at http://www.FreeBSD.org/releases/ - always consult the ERRATA section
  14.    for your release first as it's updated frequently.

  15. o  The Handbook and FAQ documents are at http://www.FreeBSD.org/ and,
  16.    along with the mailing lists, can be searched by going to
  17.    http://www.FreeBSD.org/search/.  If the doc distribution has
  18.    been installed, they're also available formatted in /usr/share/doc.

  19. If you still have a question or problem, please take the output of
  20. `uname -a', along with any relevant error messages, and email it
  21. as a question to the questions@FreeBSD.org mailing list.  If you are
  22. unfamiliar with FreeBSD's directory layout, please refer to the hier(7)
  23. manual page.  If you are not familiar with manual pages, type `man man'.

  24. You may also use sysinstall(8) to re-enter the installation and
  25. configuration utility.  Edit /etc/motd to change this login announcement.

  26. You can install extra packages for FreeBSD by using the ports system.
  27. If you have installed it, you can download, compile, and install software by
  28. just typing

  29.         # cd /usr/ports//
  30.         # make install && make clean

  31. as root.  The ports infrastructure will download the software, change it so
  32. it works on FreeBSD, compile it, install it, register the installation so it
  33. will be possible to automatically uninstall it, and clean out the temporary
  34. working space it used.  You can remove an installed port you decide you do not
  35. want after all by typing

  36.         # cd /usr/ports//
  37.         # make deinstall

  38. as root.
  39. $ hostname
  40. pg91.example.org
  41. $
复制代码
There. Done. Now all I need to do is remove PostgreSQ 7.4 and install PostgreSQL 9.1



FROM:  http://www.freebsddiary.org/jail-renaming.php

论坛徽章:
0
2 [报告]
发表于 2012-07-26 07:53 |只看该作者
正式生产环境很少使用JAIL,除非对安全性有特殊要求。

论坛徽章:
13
15-16赛季CBA联赛之同曦
日期:2016-01-28 19:52:032015亚冠之北京国安
日期:2015-10-07 14:28:19NBA常规赛纪念章
日期:2015-05-04 22:32:03处女座
日期:2015-01-15 19:45:44卯兔
日期:2014-10-28 16:17:14白羊座
日期:2014-05-24 15:10:46寅虎
日期:2014-05-10 09:50:35白羊座
日期:2014-03-12 20:52:17午马
日期:2014-03-01 08:37:27射手座
日期:2014-02-19 19:26:54子鼠
日期:2013-11-30 09:03:56狮子座
日期:2013-09-08 08:37:52
3 [报告]
发表于 2012-07-26 12:55 |只看该作者
macafee 发表于 2012-07-26 07:53
正式生产环境很少使用JAIL,除非对安全性有特殊要求。


感谢分享宝贵的经验 赞! ^_^

论坛徽章:
0
4 [报告]
发表于 2012-07-29 14:44 |只看该作者
macafee 发表于 2012-07-26 07:53
正式生产环境很少使用JAIL,除非对安全性有特殊要求。


除了安全,Jail 提供不少管理上的方便。

论坛徽章:
13
15-16赛季CBA联赛之同曦
日期:2016-01-28 19:52:032015亚冠之北京国安
日期:2015-10-07 14:28:19NBA常规赛纪念章
日期:2015-05-04 22:32:03处女座
日期:2015-01-15 19:45:44卯兔
日期:2014-10-28 16:17:14白羊座
日期:2014-05-24 15:10:46寅虎
日期:2014-05-10 09:50:35白羊座
日期:2014-03-12 20:52:17午马
日期:2014-03-01 08:37:27射手座
日期:2014-02-19 19:26:54子鼠
日期:2013-11-30 09:03:56狮子座
日期:2013-09-08 08:37:52
5 [报告]
发表于 2012-07-29 14:52 |只看该作者
本帖最后由 ulovko 于 2012-07-29 14:52 编辑
zeissoctopus 发表于 2012-07-29 14:44
除了安全,Jail 提供不少管理上的方便。

跟虚拟化有类似嘛 ^_^
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP