| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 1 |  | 
 | 2 | ===== | 
 | 3 | Linux | 
 | 4 | ===== | 
 | 5 |  | 
 | 6 | Linux Operating Systems. | 
 | 7 |  | 
 | 8 | * Ubuntu | 
 | 9 | * CentOS | 
 | 10 | * RedHat | 
 | 11 | * Fedora | 
 | 12 | * Arch | 
 | 13 |  | 
 | 14 | Sample pillars | 
 | 15 | ============== | 
 | 16 |  | 
 | 17 | Linux system | 
 | 18 | ------------ | 
 | 19 |  | 
 | 20 | Basic Linux box | 
 | 21 |  | 
 | 22 | .. code-block:: yaml | 
 | 23 |  | 
 | 24 |     linux: | 
 | 25 |       system: | 
 | 26 |         enabled: true | 
 | 27 |         name: 'node1' | 
 | 28 |         domain: 'domain.com' | 
 | 29 |         cluster: 'system' | 
 | 30 |         environment: prod | 
 | 31 |         timezone: 'Europe/Prague' | 
 | 32 |         utc: true | 
 | 33 |  | 
 | 34 | Linux with system users, sowe with password set | 
 | 35 |  | 
 | 36 | .. code-block:: yaml | 
 | 37 |  | 
 | 38 |     linux: | 
 | 39 |       system: | 
 | 40 |         ... | 
 | 41 |         user: | 
 | 42 |           jdoe: | 
 | 43 |             name: 'jdoe' | 
 | 44 |             enabled: true | 
 | 45 |             sudo: true | 
 | 46 |             shell: /bin/bash | 
 | 47 |             full_name: 'Jonh Doe' | 
 | 48 |             home: '/home/jdoe' | 
 | 49 |             email: 'jonh@doe.com' | 
 | 50 |           jsmith: | 
 | 51 |             name: 'jsmith' | 
 | 52 |             enabled: true | 
 | 53 |             full_name: 'Password' | 
 | 54 |             home: '/home/jsmith' | 
 | 55 |             password: userpassword | 
 | 56 |  | 
 | 57 | Linux with package, latest version | 
 | 58 |  | 
 | 59 | .. code-block:: yaml | 
 | 60 |  | 
 | 61 |     linux: | 
 | 62 |       system: | 
 | 63 |         ... | 
 | 64 |         package: | 
 | 65 |           package-name: | 
 | 66 |             version: latest | 
 | 67 |  | 
 | 68 | Linux with package from certail repo, version with no upgrades | 
 | 69 |  | 
 | 70 | .. code-block:: yaml | 
 | 71 |  | 
 | 72 |     linux: | 
 | 73 |       system: | 
 | 74 |         ... | 
 | 75 |         package: | 
 | 76 |           package-name: | 
 | 77 |             version: 2132.323 | 
 | 78 |             repo: 'custom-repo' | 
 | 79 |             hold: true | 
 | 80 |  | 
 | 81 | Linux with package from certail repo, version with no GPG verification | 
 | 82 |  | 
 | 83 | .. code-block:: yaml | 
 | 84 |  | 
 | 85 |     linux: | 
 | 86 |       system: | 
 | 87 |         ... | 
 | 88 |         package: | 
 | 89 |           package-name: | 
 | 90 |             version: 2132.323 | 
 | 91 |             repo: 'custom-repo' | 
 | 92 |             verify: false | 
 | 93 |  | 
 | 94 | Linux with cron jobs | 
 | 95 |  | 
 | 96 | .. code-block:: yaml | 
 | 97 |  | 
 | 98 |     linux: | 
 | 99 |       system: | 
 | 100 |         ... | 
 | 101 |         job: | 
 | 102 |           cmd1: | 
 | 103 |             command: '/cmd/to/run' | 
 | 104 |             enabled: true | 
 | 105 |             user: 'root' | 
 | 106 |             hour: 2 | 
 | 107 |             minute: 0 | 
 | 108 |  | 
| Filip Pytloun | d0a29e7 | 2015-11-30 15:23:34 +0100 | [diff] [blame] | 109 | Linux security limits (limit sensu user memory usage to max 1GB): | 
 | 110 |  | 
 | 111 | .. code-block:: yaml | 
 | 112 |  | 
 | 113 |     linux: | 
 | 114 |       system: | 
 | 115 |         ... | 
 | 116 |         limit: | 
 | 117 |           sensu: | 
 | 118 |             enabled: true | 
 | 119 |             domain: sensu | 
 | 120 |             limits: | 
 | 121 |               - type: hard | 
 | 122 |                 item: as | 
 | 123 |                 value: 1000000 | 
 | 124 |  | 
| Filip Pytloun | 7fee054 | 2015-10-15 11:19:24 +0200 | [diff] [blame] | 125 | Enable autologin on tty1 (may work only for Ubuntu 14.04): | 
 | 126 |  | 
 | 127 | .. code-block:: yaml | 
 | 128 |  | 
 | 129 |     linux: | 
 | 130 |       system: | 
 | 131 |         console: | 
 | 132 |           tty1: | 
 | 133 |             autologin: root | 
 | 134 |  | 
 | 135 | To disable set autologin to `false`. | 
 | 136 |  | 
| Filip Pytloun | 281034a | 2016-01-04 18:06:22 +0100 | [diff] [blame] | 137 | Kernel | 
 | 138 | ~~~~~~ | 
 | 139 |  | 
 | 140 | Install always up to date LTS kernel and headers from Ubuntu trusty: | 
 | 141 |  | 
 | 142 | .. code-block:: yaml | 
 | 143 |  | 
 | 144 |     linux: | 
 | 145 |       system: | 
 | 146 |         kernel: | 
 | 147 |           type: generic | 
 | 148 |           lts: trusty | 
 | 149 |           headers: true | 
 | 150 |  | 
 | 151 | Install specific kernel version and ensure all other kernel packages are | 
 | 152 | not present. Also install extra modules and headers for this kernel: | 
 | 153 |  | 
 | 154 | .. code-block:: yaml | 
 | 155 |  | 
 | 156 |     linux: | 
 | 157 |       system: | 
 | 158 |         kernel: | 
 | 159 |           type: generic | 
 | 160 |           extra: true | 
 | 161 |           headers: true | 
 | 162 |           version: 4.2.0-22 | 
 | 163 |  | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 164 | Repositories | 
 | 165 | ~~~~~~~~~~~~ | 
 | 166 |  | 
 | 167 | RedHat based Linux with additional OpenStack repo | 
 | 168 |  | 
 | 169 | .. code-block:: yaml | 
 | 170 |  | 
 | 171 |     linux: | 
 | 172 |       system: | 
 | 173 |         ... | 
 | 174 |         repo: | 
 | 175 |           rdo-icehouse: | 
 | 176 |             enabled: true | 
 | 177 |             source: 'http://repos.fedorapeople.org/repos/openstack/openstack-icehouse/epel-6/' | 
 | 178 |             pgpcheck: 0 | 
 | 179 |  | 
 | 180 | Ensure system repository to use czech Debian mirror (``default: true``) | 
 | 181 | Also pin it's packages with priority 900. | 
 | 182 |  | 
 | 183 | .. code-block:: yaml | 
 | 184 |  | 
 | 185 |    linux: | 
 | 186 |      system: | 
 | 187 |        repo: | 
 | 188 |          debian: | 
 | 189 |            default: true | 
 | 190 |            source: "deb http://ftp.cz.debian.org/debian/ jessie main contrib non-free" | 
 | 191 |            # Import signing key from URL if needed | 
 | 192 |            key_url: "http://dummy.com/public.gpg" | 
 | 193 |            pin: | 
 | 194 |              - pin: 'origin "ftp.cz.debian.org"' | 
 | 195 |                priority: 900 | 
 | 196 |                package: '*' | 
 | 197 |  | 
| Jakub Pavlik | 7885938 | 2016-01-21 11:26:39 +0100 | [diff] [blame] | 198 | rc.local example | 
 | 199 |  | 
 | 200 | .. code-block:: yaml | 
 | 201 |  | 
 | 202 |    linux: | 
 | 203 |      system: | 
 | 204 |        rc: | 
 | 205 |          local: | | 
 | 206 |            #!/bin/sh -e | 
 | 207 |            # | 
 | 208 |            # rc.local | 
 | 209 |            # | 
 | 210 |            # This script is executed at the end of each multiuser runlevel. | 
 | 211 |            # Make sure that the script will "exit 0" on success or any other | 
 | 212 |            # value on error. | 
 | 213 |            # | 
 | 214 |            # In order to enable or disable this script just change the execution | 
 | 215 |            # bits. | 
 | 216 |            # | 
 | 217 |            # By default this script does nothing. | 
 | 218 |            exit 0 | 
 | 219 |  | 
| Filip Pytloun | 1f40dac | 2016-01-22 15:52:57 +0100 | [diff] [blame] | 220 | Prompt | 
 | 221 | ~~~~~~ | 
 | 222 |  | 
 | 223 | Setting prompt is implemented by creating ``/etc/profile.d/prompt.sh``. Every | 
 | 224 | user can have different prompt. | 
 | 225 |  | 
 | 226 | .. code-block:: yaml | 
 | 227 |  | 
 | 228 |     linux: | 
 | 229 |       system: | 
 | 230 |         prompt: | 
 | 231 |           root: \\n\\[\\033[0;37m\\]\\D{%y/%m/%d %H:%M:%S} $(hostname -f)\\[\\e[0m\\]\\n\\[\\e[1;31m\\][\\u@\\h:\\w]\\[\\e[0m\\] | 
 | 232 |           default: \\n\\D{%y/%m/%d %H:%M:%S} $(hostname -f)\\n[\\u@\\h:\\w] | 
 | 233 |  | 
 | 234 | On Debian systems to set prompt system-wide it's necessary to remove setting | 
 | 235 | PS1 in ``/etc/bash.bashrc`` and ``~/.bashrc`` (which comes from | 
 | 236 | ``/etc/skel/.bashrc``). This formula will do this automatically, but will not | 
| Filip Pytloun | d9b68da | 2016-01-22 15:58:41 +0100 | [diff] [blame^] | 237 | touch existing user's ``~/.bashrc`` files except root. | 
| Jakub Pavlik | 7885938 | 2016-01-21 11:26:39 +0100 | [diff] [blame] | 238 |  | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 239 | Linux network | 
 | 240 | ------------- | 
 | 241 |  | 
 | 242 | Linux with network manager | 
 | 243 |  | 
 | 244 | .. code-block:: yaml | 
 | 245 |  | 
 | 246 |     linux: | 
 | 247 |       network: | 
 | 248 |         enabled: true | 
 | 249 |         network_manager: true | 
 | 250 |  | 
 | 251 | Linux with default static network interfaces, default gateway interface and DNS servers | 
 | 252 |  | 
 | 253 | .. code-block:: yaml | 
 | 254 |  | 
 | 255 |     linux: | 
 | 256 |       network: | 
 | 257 |         enabled: true | 
 | 258 |         interface: | 
 | 259 |           eth0: | 
 | 260 |             enabled: true | 
 | 261 |             type: eth | 
 | 262 |             address: 192.168.0.102 | 
 | 263 |             netmask: 255.255.255.0 | 
 | 264 |             gateway: 192.168.0.1 | 
 | 265 |             name_servers: | 
 | 266 |             - 8.8.8.8 | 
 | 267 |             - 8.8.4.4 | 
 | 268 |             mtu: 1500 | 
 | 269 |  | 
| jan kaufman | 6d30adf | 2016-01-18 17:30:12 +0100 | [diff] [blame] | 270 | Linux with bonded interfaces and disabled NetworkManager | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 271 |  | 
 | 272 | .. code-block:: yaml | 
 | 273 |  | 
 | 274 |     linux: | 
 | 275 |       network: | 
 | 276 |         enabled: true | 
 | 277 |         interface: | 
 | 278 |           eth0: | 
 | 279 |             type: eth | 
 | 280 |             ... | 
 | 281 |           eth1: | 
 | 282 |             type: eth | 
 | 283 |             ... | 
 | 284 |           bond0: | 
 | 285 |             enabled: true | 
 | 286 |             type: bond | 
 | 287 |             address: 192.168.0.102 | 
 | 288 |             netmask: 255.255.255.0 | 
 | 289 |             mtu: 1500 | 
 | 290 |             use_in: | 
 | 291 |             - interface: ${linux:interface:eth0} | 
 | 292 |             - interface: ${linux:interface:eth0} | 
| jan kaufman | 6d30adf | 2016-01-18 17:30:12 +0100 | [diff] [blame] | 293 |         network_manager: | 
 | 294 |           disable: true | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 295 |  | 
| Jan Kaufman | 6a1ad71 | 2015-12-11 14:44:19 +0100 | [diff] [blame] | 296 | Linux with vlan interface_params | 
 | 297 |  | 
 | 298 | .. code-block:: yaml | 
 | 299 |  | 
 | 300 |     linux: | 
 | 301 |       network: | 
 | 302 |         enabled: true | 
 | 303 |         interface: | 
 | 304 |           vlan69: | 
 | 305 |             type: vlan | 
| jan kaufman | c0bd76f | 2015-12-15 16:45:44 +0100 | [diff] [blame] | 306 |             use_interfaces: | 
| Jan Kaufman | 6a1ad71 | 2015-12-11 14:44:19 +0100 | [diff] [blame] | 307 |             - interface: ${linux:interface:bond0} | 
| Jan Kaufman | 6a1ad71 | 2015-12-11 14:44:19 +0100 | [diff] [blame] | 308 |  | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 309 | Linux with wireless interface parameters | 
 | 310 |  | 
 | 311 | .. code-block:: yaml | 
 | 312 |  | 
 | 313 |     linux: | 
 | 314 |       network: | 
 | 315 |         enabled: true | 
 | 316 |         gateway: 10.0.0.1 | 
| Jan Kaufman | 6a1ad71 | 2015-12-11 14:44:19 +0100 | [diff] [blame] | 317 |         default_interface: eth0 | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 318 |         interface: | 
 | 319 |           wlan0: | 
 | 320 |             type: eth | 
 | 321 |             wireless: | 
 | 322 |               essid: example | 
 | 323 |               key: example_key | 
 | 324 |               security: wpa | 
 | 325 |               priority: 1 | 
 | 326 |  | 
 | 327 | Linux networks with routes defined | 
 | 328 |  | 
 | 329 | .. code-block:: yaml | 
 | 330 |  | 
 | 331 |     linux: | 
 | 332 |       network: | 
 | 333 |         enabled: true | 
 | 334 |         gateway: 10.0.0.1 | 
| Jan Kaufman | 6a1ad71 | 2015-12-11 14:44:19 +0100 | [diff] [blame] | 335 |         default_interface: eth0 | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 336 |         interface: | 
 | 337 |           eth0: | 
 | 338 |             type: eth | 
 | 339 |             route: | 
 | 340 |               default: | 
 | 341 |                 address: 192.168.0.123 | 
 | 342 |                 netmask: 255.255.255.0 | 
 | 343 |                 gateway: 192.168.0.1 | 
 | 344 |  | 
 | 345 | Native Linux Bridges | 
 | 346 |  | 
 | 347 | .. code-block:: yaml | 
 | 348 |  | 
 | 349 |     linux: | 
 | 350 |       network: | 
 | 351 |         interface: | 
 | 352 |           eth1: | 
 | 353 |             enabled: true | 
 | 354 |             type: eth | 
 | 355 |             proto: manual | 
 | 356 |             up_cmds: | 
 | 357 |             - ip address add 0/0 dev $IFACE | 
 | 358 |             - ip link set $IFACE up | 
 | 359 |             down_cmds: | 
 | 360 |             - ip link set $IFACE down | 
 | 361 |           br-ex: | 
 | 362 |             enabled: true | 
 | 363 |             type: bridge | 
 | 364 |             address: ${linux:network:host:public_local:address} | 
 | 365 |             netmask: 255.255.255.0 | 
 | 366 |             use_interfaces: | 
 | 367 |             - eth1 | 
 | 368 |  | 
 | 369 | OpenVswitch Bridges | 
 | 370 |  | 
 | 371 | .. code-block:: yaml | 
 | 372 |  | 
 | 373 |     linux: | 
 | 374 |       network: | 
 | 375 |         bridge: openvswitch | 
 | 376 |         interface: | 
 | 377 |           eth1: | 
 | 378 |             enabled: true | 
 | 379 |             type: eth | 
 | 380 |             proto: manual | 
 | 381 |             up_cmds: | 
 | 382 |             - ip address add 0/0 dev $IFACE | 
 | 383 |             - ip link set $IFACE up | 
 | 384 |             down_cmds: | 
 | 385 |             - ip link set $IFACE down | 
 | 386 |           br-ex: | 
 | 387 |             enabled: true | 
 | 388 |             type: bridge | 
 | 389 |             address: ${linux:network:host:public_local:address} | 
 | 390 |             netmask: 255.255.255.0 | 
 | 391 |             use_interfaces: | 
 | 392 |             - eth1 | 
 | 393 |  | 
 | 394 | Linux with proxy | 
 | 395 |  | 
 | 396 | .. code-block:: yaml | 
 | 397 |  | 
 | 398 |     linux: | 
 | 399 |       network: | 
 | 400 |         ... | 
 | 401 |         proxy: | 
 | 402 |           host: proxy.domain.com | 
 | 403 |           port: 3128 | 
 | 404 |  | 
 | 405 | Linux with hosts | 
 | 406 |  | 
 | 407 | .. code-block:: yaml | 
 | 408 |  | 
 | 409 |     linux: | 
 | 410 |       network: | 
 | 411 |         ... | 
 | 412 |         host: | 
 | 413 |           node1: | 
 | 414 |             address: 192.168.10.200 | 
 | 415 |             names: | 
 | 416 |             - node2.domain.com | 
 | 417 |             - service2.domain.com | 
 | 418 |           node2: | 
 | 419 |             address: 192.168.10.201 | 
 | 420 |             names: | 
 | 421 |             - node2.domain.com | 
 | 422 |             - service2.domain.com | 
 | 423 |  | 
| Filip Pytloun | de9bea5 | 2016-01-11 15:39:10 +0100 | [diff] [blame] | 424 | Setup resolv.conf, nameservers, domain and search domains | 
 | 425 |  | 
 | 426 | .. code-block:: yaml | 
 | 427 |  | 
 | 428 |     linux: | 
 | 429 |       network: | 
 | 430 |         resolv: | 
 | 431 |           dns: | 
 | 432 |             - 8.8.4.4 | 
 | 433 |             - 8.8.8.8 | 
 | 434 |           domain: my.example.com | 
 | 435 |           search: | 
 | 436 |             - my.example.com | 
 | 437 |             - example.com | 
 | 438 |  | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 439 | Linux storage pillars | 
 | 440 | --------------------- | 
 | 441 |  | 
 | 442 | Linux with mounted Samba | 
 | 443 |  | 
 | 444 | .. code-block:: yaml | 
 | 445 |  | 
 | 446 |     linux: | 
 | 447 |       storage: | 
 | 448 |         enabled: true | 
 | 449 |         mount: | 
 | 450 |           samba1: | 
 | 451 |           - path: /media/myuser/public/ | 
 | 452 |           - device: //192.168.0.1/storage | 
 | 453 |           - file_system: cifs | 
 | 454 |           - options: guest,uid=myuser,iocharset=utf8,file_mode=0777,dir_mode=0777,noperm | 
 | 455 |  | 
 | 456 | Linux with file swap | 
 | 457 |  | 
 | 458 | .. code-block:: yaml | 
 | 459 |  | 
 | 460 |     linux: | 
 | 461 |       storage: | 
 | 462 |         enabled: true | 
 | 463 |         swap: | 
 | 464 |           file: | 
 | 465 |             enabled: true | 
 | 466 |             engine: file | 
 | 467 |             device: /swapfile | 
 | 468 |             size: 1024 | 
 | 469 |  | 
| Filip Pytloun | c8a001a | 2015-12-15 14:09:19 +0100 | [diff] [blame] | 470 | LVM group `vg1` with one device and `data` volume mounted into `/mnt/data` | 
 | 471 |  | 
 | 472 | .. code-block:: yaml | 
 | 473 |  | 
 | 474 |     parameters: | 
 | 475 |       linux: | 
 | 476 |         storage: | 
 | 477 |           mount: | 
 | 478 |             data: | 
 | 479 |               device: /dev/vg1/data | 
 | 480 |               file_system: ext4 | 
 | 481 |               path: /mnt/data | 
 | 482 |           lvm: | 
 | 483 |             vg1: | 
 | 484 |               enabled: true | 
 | 485 |               devices: | 
 | 486 |                 - /dev/sdb | 
 | 487 |               volume: | 
 | 488 |                 data: | 
 | 489 |                   size: 40G | 
 | 490 |                   mount: ${linux:storage:mount:data} | 
 | 491 |  | 
| Filip Pytloun | f5383a4 | 2015-10-06 16:28:32 +0200 | [diff] [blame] | 492 | Usage | 
 | 493 | ===== | 
 | 494 |  | 
 | 495 | Set mtu of network interface eth0 to 1400 | 
 | 496 |  | 
 | 497 | .. code-block:: bash | 
 | 498 |  | 
 | 499 |     ip link set dev eth0 mtu 1400 | 
 | 500 |  | 
 | 501 | Read more | 
 | 502 | ========= | 
 | 503 |  | 
 | 504 | * https://www.archlinux.org/ | 
 | 505 | * http://askubuntu.com/questions/175172/how-do-i-configure-proxies-in-ubuntu-server-or-minimal-cli-ubuntu |