LoginSignup
119
118

More than 3 years have passed since last update.

ubuntuパッケージ管理centosとの対比備忘録

Last updated at Posted at 2017-11-07

centos使いが最近ubuntuさわる機会が増えたため苦しまぎれの備忘録。

ubuntuとcentosのパッケージ関連操作比較一覧

(yumやrpmは空で出てくるがaptやdpkgは即刻忘れて毎度調べなおすのがだるいので自分用に)

作業項目 ubuntu centos
OS確認 cat /etc/lsb-release cat /etc/redhat-release
パッケージインストール apt-get install pkgname yum install pkgname
導入済みパッケージのリストを取得 dpkg -l rpm -qaか、yum list installed
パッケージの削除 apt-get purge pkgname rpm -e pkgnameyum remove pkgname
入れられるパッケージ検索 apt-cache madison [query] yum search [query]yum --showduplicate list [pkgname]
パッケージの更新ロックする apt-mark hold pkgname yum-plugin-versionlockを入れて/etc/yum/pluginconf.d/versionlock.listpkgname-versionを書く
パッケージ更新ロック解除 apt-mark unhold pkgname /etc/yum/pluginconf.d/versionlock.listから消す
インストールしたパッケージに含まれるファイルの一覧 dpkg -L pkgname rpm -ql pkgname
インストールされてるパッケージの更新 apt-get upgradeapt-get install pkgname yum update [pkgname]
バージョン指定インストール apt-get install pkgname=version~code-name yum install pkgname-version
パッケージの情報表示 dpkg -s pkgname rpm -qi pkgname
依存パッケージ情報表示 apt-cache depends rpm -qR pkgname
ファイル(絶対PATH)からパッケージを特定 apt-file search relaytive-path-filename rpm -qf relaytive-path-filename
PATHなしファイルからパッケージ特定 dpkg -S filename yum whatprovides filename
リポジトリのリスト表示 grep -h ^deb /etc/apt/sources.list /etc/apt/sources.list.d/* yum repolist
パッケージグループインストール apt-get install meta-packagename yum groupinstall group-id_or_group-name
パッケージグループ表示 apt-cache search meta package yum grouplist,yum -v groups list
パッケージグループに含まれるパッケージ表示 yum groups info group-(name_or_id)
キャッシュを削除 apt-get cleanapt-get autoremove yum clean all
http-proxyを仕込む 環境変数https_proxy指定か/etc/apt/apt.confにAcquire::https::proxy "url";指定 /etc/yum.confにproxy=urlを指定
update対象のパッケージの一覧を表示 apt list --upgradable yum check-update
downloadだけする apt-get download [package name] yum update --downloadonly --downloaddir=/home/user/yumdir
downloadしたローカルパッケージをinstall dpkg -i [.deb file path] yum localupdate /home/user/yumdir/*

https://qiita.com/white_aspara25/items/723ae4ebf0bfefe2115c
http://d.hatena.ne.jp/yutamoty/20091021/1256107870
https://qiita.com/showsuzu/items/9ee031208d38ff8ac889

ややこしい違いが多いような気がするけど気のせいでしょうか。

・リポジトリ管理について

yumの場合/etc/yum.repos.d/~.repoという名前でリポジトリファイルが置かれる

aptだと/etc/apt/sources.list.d/~.listにリポジトリファイルが置かれる

centosの場合メジャーバージョンとマイナーバージョンは数字だが
ubuntuの場合アルファベットのコードネームみたいなもんがあるubuntu-xenialみたいなの。
https://wiki.ubuntu.com/Releases
baseのDebianのバージョンは/etc/debian_versionみるとわかるようです。
https://askubuntu.com/questions/445487/what-debian-version-are-the-different-ubuntu-versions-based-on

追ってgpg鍵の管理やオレオレリポジトリなどについて特定して書きたい気がする。
→Ubuntuのgpg鍵サーバはpoolアドレス(pool.sks-keyservers.net)つかうのがタイムアウトしづらいのでオススメ。
https://stackoverflow.com/questions/30739178/how-to-add-apt-key-with-recv-keys-instead-of-recv
https://docs.ansible.com/ansible/latest/modules/apt_key_module.html

ansibleだとchefと違ってパッケージ名抽象化してくれないらしいので以下の感じにwhenにfact変数指定で分岐させる。

- name: yum install glibc 
  yum:
    name: glibc
    state: latest
  tags: install_glibc
  when: "ansible_os_family == 'RedHat'"

- name: apt install libc6
  apt:
    name: libc6
    state: latest
    update_cache: yes
  tags: install_libc6
  when: "ansible_os_family == 'Debian'"

関連しそうなとれるfact例↓

$ ansible -m setup -i hosts_test 10.0.0.222
~略~
        "ansible_distribution": "Ubuntu",
        "ansible_distribution_file_parsed": true,
        "ansible_distribution_file_path": "/etc/os-release",
        "ansible_distribution_file_variety": "Debian",
        "ansible_distribution_major_version": "18",
        "ansible_distribution_release": "bionic",
        "ansible_distribution_version": "18.04",
        "ansible_lsb": {
            "codename": "bionic",
            "description": "Ubuntu 18.04.2 LTS",
            "id": "Ubuntu",
            "major_release": "18",
            "release": "18.04"
        },
        "ansible_os_family": "Debian",
        "ansible_pkg_mgr": "apt",

ubuntuとcentosのネットワークがらみの設定ファイルの場所比較

ついでに追記。確認操作コマンドなどは大差なさそう。

項目 Ubuntu CentOS
IF設定ファイルの場所 /etc/network/interfaces.d/*.cfg(※1) /etc/sysconfig/network-scripts/ifcfg-<if-device-name>
ルーティング設定 /etc/network/if-up.d/static-routesに書くか/etc/network/interfacesに設定 /etc/sysconfig/network-scripts/route-に書く
iptables設定される場所 どうやら任意? /etc/sysconfig/iptables-config
ファイヤーウォール AppArmorが有効、ufwを任意で有効化 selinuxとfirewalld(iptablesラッパー)がデフォルトで入ってる
hosts dhcpだと自分自身は127.0.0.1に設定するらしい 場所は同じで/etc/hosts

このほかresolv.confの場所などは同じだった。(NetworkManagerが不穏な動きで更新きかない的な事情は似たかんじ)
(※1)/etc/cloud/cloud.cfg.d/99-disable-network-config.cfgnetwork: {config: disabled}と書くと cloud-initによる設定を無効化可能になる

あとmysqlのパッケージ名とかデーモン名とか設定ファイルの位置とか結構全然違ったのでansible的な分岐がアレでした。jinja2便利。

templateで設定ファイルのif分岐したい例
{% if ansible_os_family == "Debian" %}
log-error=/var/log/mysql/error.log
{% else %}
log-error=/var/log/mysqld.log
{% endif %}

あとdebconfモジュールを使うと便利な感じでした。

参考
https://www.server-world.info/query?os=Ubuntu_16.04&p=initial_conf&f=3
https://qiita.com/kooohei/items/b0931ae210911cc52adc
https://server-setting.info/debian/network-config-debian.html

119
118
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
119
118