blob: 7f38c2a4bb7b9a0122467ac7821567a8d817d9be [file] [log] [blame]
Filip Pytlounf5383a42015-10-06 16:28:32 +02001
2=====
3Linux
4=====
5
6Linux Operating Systems.
7
8* Ubuntu
9* CentOS
10* RedHat
11* Fedora
12* Arch
13
14Sample pillars
15==============
16
17Linux system
18------------
19
20Basic 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
34Linux 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
57Linux with package, latest version
58
59.. code-block:: yaml
60
61 linux:
62 system:
63 ...
64 package:
65 package-name:
66 version: latest
67
68Linux 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
81Linux 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
Bruno Binet69a9d8d2017-02-16 22:34:32 +010094Linux with autoupdates (automatically install security package updates)
95
96.. code-block:: yaml
97
98 linux:
99 system:
100 ...
101 autoupdates:
102 enabled: true
103 mail: root@localhost
104 mail_only_on_error: true
105 remove_unused_dependencies: false
106 automatic_reboot: true
107 automatic_reboot_time: "02:00"
108
Filip Pytlounf5383a42015-10-06 16:28:32 +0200109Linux with cron jobs
110
111.. code-block:: yaml
112
113 linux:
114 system:
115 ...
116 job:
117 cmd1:
118 command: '/cmd/to/run'
119 enabled: true
120 user: 'root'
121 hour: 2
122 minute: 0
123
Filip Pytlound0a29e72015-11-30 15:23:34 +0100124Linux security limits (limit sensu user memory usage to max 1GB):
125
126.. code-block:: yaml
127
128 linux:
129 system:
130 ...
131 limit:
132 sensu:
133 enabled: true
134 domain: sensu
135 limits:
136 - type: hard
137 item: as
138 value: 1000000
139
Filip Pytloun7fee0542015-10-15 11:19:24 +0200140Enable autologin on tty1 (may work only for Ubuntu 14.04):
141
142.. code-block:: yaml
143
144 linux:
145 system:
146 console:
147 tty1:
148 autologin: root
Filip Pytloun281d0202016-01-29 14:03:51 +0100149 # Enable serial console
150 ttyS0:
151 autologin: root
152 rate: 115200
153 term: xterm
Filip Pytloun7fee0542015-10-15 11:19:24 +0200154
155To disable set autologin to `false`.
156
Filip Pytloun7731b852016-02-01 11:13:47 +0100157Set ``policy-rc.d`` on Debian-based systems. Action can be any available
158command in ``while true`` loop and ``case`` context.
159Following will disallow dpkg to stop/start services for cassandra package automatically:
160
161.. code-block:: yaml
162
163 linux:
164 system:
165 policyrcd:
166 - package: cassandra
167 action: exit 101
168 - package: '*'
169 action: switch
170
Filip Pytlounc49445a2016-04-04 14:23:20 +0200171Set system locales:
172
173.. code-block:: yaml
174
175 linux:
176 system:
177 locale:
178 en_US.UTF-8:
179 default: true
Filip Pytlounee1745f2016-04-04 17:39:41 +0200180 "cs_CZ.UTF-8 UTF-8":
Filip Pytlounc49445a2016-04-04 14:23:20 +0200181 enabled: true
182
Filip Pytloun281034a2016-01-04 18:06:22 +0100183Kernel
184~~~~~~
185
186Install always up to date LTS kernel and headers from Ubuntu trusty:
187
188.. code-block:: yaml
189
190 linux:
191 system:
192 kernel:
193 type: generic
194 lts: trusty
195 headers: true
196
Tomáš Kukrálba35b212017-02-15 17:59:46 +0100197Load kernel modules and add them to `/etc/modules`:
198
199.. code-block:: yaml
200
201 linux:
202 system:
203 kernel:
204 modules:
205 - nf_conntrack
206 - tp_smapi
207 - 8021q
208
Filip Pytloun281034a2016-01-04 18:06:22 +0100209Install specific kernel version and ensure all other kernel packages are
210not present. Also install extra modules and headers for this kernel:
211
212.. code-block:: yaml
213
214 linux:
215 system:
216 kernel:
217 type: generic
218 extra: true
219 headers: true
220 version: 4.2.0-22
221
Jakub Pavlik32c2cb02016-01-29 12:45:29 +0100222Systcl kernel parameters
223
224.. code-block:: yaml
225
226 linux:
227 system:
228 kernel:
229 sysctl:
230 net.ipv4.tcp_keepalive_intvl: 3
231 net.ipv4.tcp_keepalive_time: 30
232 net.ipv4.tcp_keepalive_probes: 8
233
Jiri Broulikf8f55a22017-01-26 14:36:46 +0100234
235CPU
236~~~
237
238Disable ondemand cpu mode service:
239
240.. code-block:: yaml
241
242 linux:
243 system:
244 cpu:
245 governor: performance
246
Jakub Pavlikb148c8c2017-02-12 21:30:48 +0100247Huge Pages
248~~~~~~~~~~~~
249
250Huge Pages give a performance boost to applications that intensively deal
251with memory allocation/deallocation by decreasing memory fragmentation.
252
253.. code-block:: yaml
254
255 linux:
256 system:
257 kernel:
258 hugepages:
259 small:
260 size: 2M
261 count: 107520
262 mount_point: /mnt/hugepages_2MB
263 mount: false/true # default false
264 large:
265 default: true # default automatically mounted
266 size: 1G
267 count: 210
268 mount_point: /mnt/hugepages_1GB
269
270Note: not recommended to use both pagesizes in concurrently.
Jiri Broulikf8f55a22017-01-26 14:36:46 +0100271
Jakub Pavlik5398d872017-02-13 22:30:47 +0100272Intel SR-IOV
273~~~~~~~~~~~~
274
275PCI-SIG Single Root I/O Virtualization and Sharing (SR-IOV) specification defines a standardized mechanism to virtualize PCIe devices. The mechanism can virtualize a single PCIe Ethernet controller to appear as multiple PCIe devices.
276
277.. code-block:: yaml
278
279 linux:
280 system:
281 kernel:
282 sriov: True
283 unsafe_interrupts: False # Default is false. for older platforms and AMD we need to add interrupt remapping workaround
284 rc:
285 local: |
286 #!/bin/sh -e
287 # Enable 7 VF on eth1
288 echo 7 > /sys/class/net/eth1/device/sriov_numvfs; sleep 2; ifup -a
289 exit 0
290
Jakub Pavlik6c9ead12017-02-16 21:53:13 +0100291Isolate CPU options
292~~~~~~~~~~~~~~~~~~~
293
294Remove the specified CPUs, as defined by the cpu_number values, from the general kernel
295SMP balancing and scheduler algroithms. The only way to move a process onto or off an
296"isolated" CPU is via the CPU affinity syscalls. cpu_number begins at 0, so the
297maximum value is 1 less than the number of CPUs on the system.
298
299.. code-block:: yaml
300
301 linux:
302 system:
303 kernel:
304 isolcpu: 1,2,3,4,5,6,7 # isolate first cpu 0
Jiri Broulikf8f55a22017-01-26 14:36:46 +0100305
Filip Pytlounf5383a42015-10-06 16:28:32 +0200306Repositories
307~~~~~~~~~~~~
308
309RedHat based Linux with additional OpenStack repo
310
311.. code-block:: yaml
312
313 linux:
314 system:
315 ...
316 repo:
317 rdo-icehouse:
318 enabled: true
319 source: 'http://repos.fedorapeople.org/repos/openstack/openstack-icehouse/epel-6/'
320 pgpcheck: 0
321
322Ensure system repository to use czech Debian mirror (``default: true``)
323Also pin it's packages with priority 900.
324
325.. code-block:: yaml
326
327 linux:
328 system:
329 repo:
330 debian:
331 default: true
332 source: "deb http://ftp.cz.debian.org/debian/ jessie main contrib non-free"
333 # Import signing key from URL if needed
334 key_url: "http://dummy.com/public.gpg"
335 pin:
336 - pin: 'origin "ftp.cz.debian.org"'
337 priority: 900
338 package: '*'
339
Jakub Pavlik78859382016-01-21 11:26:39 +0100340rc.local example
341
342.. code-block:: yaml
343
344 linux:
345 system:
346 rc:
347 local: |
348 #!/bin/sh -e
349 #
350 # rc.local
351 #
352 # This script is executed at the end of each multiuser runlevel.
353 # Make sure that the script will "exit 0" on success or any other
354 # value on error.
355 #
356 # In order to enable or disable this script just change the execution
357 # bits.
358 #
359 # By default this script does nothing.
360 exit 0
361
Filip Pytloun1f40dac2016-01-22 15:52:57 +0100362Prompt
363~~~~~~
364
365Setting prompt is implemented by creating ``/etc/profile.d/prompt.sh``. Every
366user can have different prompt.
367
368.. code-block:: yaml
369
370 linux:
371 system:
372 prompt:
373 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\\]
374 default: \\n\\D{%y/%m/%d %H:%M:%S} $(hostname -f)\\n[\\u@\\h:\\w]
375
376On Debian systems to set prompt system-wide it's necessary to remove setting
377PS1 in ``/etc/bash.bashrc`` and ``~/.bashrc`` (which comes from
378``/etc/skel/.bashrc``). This formula will do this automatically, but will not
Filip Pytlound9b68da2016-01-22 15:58:41 +0100379touch existing user's ``~/.bashrc`` files except root.
Jakub Pavlik78859382016-01-21 11:26:39 +0100380
Filip Pytlouneef11c12016-03-25 11:00:23 +0100381Bash
382~~~~
383
384Fix bash configuration to preserve history across sessions (like ZSH does by
385default).
386
387.. code-block:: yaml
388
389 linux:
390 system:
391 bash:
392 preserve_history: true
393
Filip Pytloune874dfb2016-01-22 16:57:34 +0100394Message of the day
395~~~~~~~~~~~~~~~~~~
396
397``pam_motd`` from package ``update-motd`` is used for dynamic messages of the
398day. Setting custom motd will cleanup existing ones.
399
400.. code-block:: yaml
401
402 linux:
403 system:
404 motd:
405 - release: |
406 #!/bin/sh
407 [ -r /etc/lsb-release ] && . /etc/lsb-release
408
409 if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
410 # Fall back to using the very slow lsb_release utility
411 DISTRIB_DESCRIPTION=$(lsb_release -s -d)
412 fi
413
414 printf "Welcome to %s (%s %s %s)\n" "$DISTRIB_DESCRIPTION" "$(uname -o)" "$(uname -r)" "$(uname -m)"
415 - warning: |
416 #!/bin/sh
417 printf "This is [company name] network.\n"
418 printf "Unauthorized access strictly prohibited.\n"
419
Filip Pytloun2f70b492016-02-19 15:55:25 +0100420RHEL / CentOS
Filip Pytloun8296bb92016-02-19 18:42:09 +0100421^^^^^^^^^^^^^
Filip Pytloun2f70b492016-02-19 15:55:25 +0100422
423Unfortunately ``update-motd`` is currently not available for RHEL so there's
424no native support for dynamic motd.
425You can still set static one, only pillar structure differs:
426
427.. code-block:: yaml
428
429 linux:
430 system:
431 motd: |
432 This is [company name] network.
433 Unauthorized access strictly prohibited.
434
Filip Pytloun8296bb92016-02-19 18:42:09 +0100435Haveged
436~~~~~~~
437
438If you are running headless server and are low on entropy, it may be a good
439idea to setup Haveged.
440
441.. code-block:: yaml
442
443 linux:
444 system:
445 haveged:
446 enabled: true
447
Filip Pytlounf5383a42015-10-06 16:28:32 +0200448Linux network
449-------------
450
451Linux with network manager
452
453.. code-block:: yaml
454
455 linux:
456 network:
457 enabled: true
458 network_manager: true
459
460Linux with default static network interfaces, default gateway interface and DNS servers
461
462.. code-block:: yaml
463
464 linux:
465 network:
466 enabled: true
467 interface:
468 eth0:
469 enabled: true
470 type: eth
471 address: 192.168.0.102
472 netmask: 255.255.255.0
473 gateway: 192.168.0.1
474 name_servers:
475 - 8.8.8.8
476 - 8.8.4.4
477 mtu: 1500
478
jan kaufman6d30adf2016-01-18 17:30:12 +0100479Linux with bonded interfaces and disabled NetworkManager
Filip Pytlounf5383a42015-10-06 16:28:32 +0200480
481.. code-block:: yaml
482
483 linux:
484 network:
485 enabled: true
486 interface:
487 eth0:
488 type: eth
489 ...
490 eth1:
491 type: eth
492 ...
493 bond0:
494 enabled: true
495 type: bond
496 address: 192.168.0.102
497 netmask: 255.255.255.0
498 mtu: 1500
499 use_in:
500 - interface: ${linux:interface:eth0}
501 - interface: ${linux:interface:eth0}
jan kaufman6d30adf2016-01-18 17:30:12 +0100502 network_manager:
503 disable: true
Filip Pytlounf5383a42015-10-06 16:28:32 +0200504
Jan Kaufman6a1ad712015-12-11 14:44:19 +0100505Linux with vlan interface_params
506
507.. code-block:: yaml
508
509 linux:
510 network:
511 enabled: true
512 interface:
513 vlan69:
514 type: vlan
jan kaufmanc0bd76f2015-12-15 16:45:44 +0100515 use_interfaces:
Jan Kaufman6a1ad712015-12-11 14:44:19 +0100516 - interface: ${linux:interface:bond0}
Jan Kaufman6a1ad712015-12-11 14:44:19 +0100517
Filip Pytlounf5383a42015-10-06 16:28:32 +0200518Linux with wireless interface parameters
519
520.. code-block:: yaml
521
522 linux:
523 network:
524 enabled: true
525 gateway: 10.0.0.1
Jan Kaufman6a1ad712015-12-11 14:44:19 +0100526 default_interface: eth0
Filip Pytlounf5383a42015-10-06 16:28:32 +0200527 interface:
528 wlan0:
529 type: eth
530 wireless:
531 essid: example
532 key: example_key
533 security: wpa
534 priority: 1
535
536Linux networks with routes defined
537
538.. code-block:: yaml
539
540 linux:
541 network:
542 enabled: true
543 gateway: 10.0.0.1
Jan Kaufman6a1ad712015-12-11 14:44:19 +0100544 default_interface: eth0
Filip Pytlounf5383a42015-10-06 16:28:32 +0200545 interface:
546 eth0:
547 type: eth
548 route:
549 default:
550 address: 192.168.0.123
551 netmask: 255.255.255.0
552 gateway: 192.168.0.1
553
554Native Linux Bridges
555
556.. code-block:: yaml
557
558 linux:
559 network:
560 interface:
561 eth1:
562 enabled: true
563 type: eth
564 proto: manual
565 up_cmds:
566 - ip address add 0/0 dev $IFACE
567 - ip link set $IFACE up
568 down_cmds:
569 - ip link set $IFACE down
570 br-ex:
571 enabled: true
572 type: bridge
573 address: ${linux:network:host:public_local:address}
574 netmask: 255.255.255.0
575 use_interfaces:
576 - eth1
577
578OpenVswitch Bridges
579
580.. code-block:: yaml
581
582 linux:
583 network:
584 bridge: openvswitch
585 interface:
586 eth1:
587 enabled: true
588 type: eth
589 proto: manual
590 up_cmds:
591 - ip address add 0/0 dev $IFACE
592 - ip link set $IFACE up
593 down_cmds:
594 - ip link set $IFACE down
595 br-ex:
596 enabled: true
597 type: bridge
598 address: ${linux:network:host:public_local:address}
599 netmask: 255.255.255.0
600 use_interfaces:
601 - eth1
602
603Linux with proxy
604
605.. code-block:: yaml
606
607 linux:
608 network:
609 ...
610 proxy:
611 host: proxy.domain.com
612 port: 3128
613
614Linux with hosts
615
Filip Pytloun86506fe2017-01-26 14:36:16 +0100616Parameter purge_hosts will enforce whole /etc/hosts file, removing entries
617that are not defined in model except defaults for both IPv4 and IPv6 localhost
618and hostname + fqdn.
619It's good to use this option if you want to ensure /etc/hosts is always in a
620clean state however it's not enabled by default for safety.
621
Filip Pytlounf5383a42015-10-06 16:28:32 +0200622.. code-block:: yaml
623
624 linux:
625 network:
626 ...
Filip Pytloun86506fe2017-01-26 14:36:16 +0100627 purge_hosts: true
Filip Pytlounf5383a42015-10-06 16:28:32 +0200628 host:
Filip Pytloun86506fe2017-01-26 14:36:16 +0100629 # No need to define this one if purge_hosts is true
630 hostname:
631 address: 127.0.1.1
632 names:
633 - ${linux:network:fqdn}
634 - ${linux:network:hostname}
Filip Pytlounf5383a42015-10-06 16:28:32 +0200635 node1:
636 address: 192.168.10.200
637 names:
638 - node2.domain.com
639 - service2.domain.com
640 node2:
641 address: 192.168.10.201
642 names:
643 - node2.domain.com
644 - service2.domain.com
645
Filip Pytloun86506fe2017-01-26 14:36:16 +0100646
Filip Pytlounde9bea52016-01-11 15:39:10 +0100647Setup resolv.conf, nameservers, domain and search domains
648
649.. code-block:: yaml
650
651 linux:
652 network:
653 resolv:
654 dns:
655 - 8.8.4.4
656 - 8.8.8.8
657 domain: my.example.com
658 search:
659 - my.example.com
660 - example.com
Marek Celoudf6cd1922016-12-05 13:39:49 +0100661 options:
662 - ndots:5
663 - timeout:2
664 - attempts:2
Filip Pytlounde9bea52016-01-11 15:39:10 +0100665
Filip Pytlounf5383a42015-10-06 16:28:32 +0200666Linux storage pillars
667---------------------
668
669Linux with mounted Samba
670
671.. code-block:: yaml
672
673 linux:
674 storage:
675 enabled: true
676 mount:
677 samba1:
Simon Pasquier376262a2016-11-16 15:21:51 +0100678 - enabled: true
Filip Pytlounf5383a42015-10-06 16:28:32 +0200679 - path: /media/myuser/public/
680 - device: //192.168.0.1/storage
681 - file_system: cifs
682 - options: guest,uid=myuser,iocharset=utf8,file_mode=0777,dir_mode=0777,noperm
683
684Linux with file swap
685
686.. code-block:: yaml
687
688 linux:
689 storage:
690 enabled: true
691 swap:
692 file:
693 enabled: true
694 engine: file
695 device: /swapfile
696 size: 1024
697
Lachlan Evenson30676512016-01-22 15:43:28 -0800698Linux with partition swap
699
700.. code-block:: yaml
701
702 linux:
703 storage:
704 enabled: true
705 swap:
706 partition:
707 enabled: true
708 engine: partition
709 device: /dev/vg0/swap
710
Filip Pytlounc8a001a2015-12-15 14:09:19 +0100711LVM group `vg1` with one device and `data` volume mounted into `/mnt/data`
712
713.. code-block:: yaml
714
715 parameters:
716 linux:
717 storage:
718 mount:
719 data:
Simon Pasquier376262a2016-11-16 15:21:51 +0100720 enabled: true
Filip Pytlounc8a001a2015-12-15 14:09:19 +0100721 device: /dev/vg1/data
722 file_system: ext4
723 path: /mnt/data
724 lvm:
725 vg1:
726 enabled: true
727 devices:
728 - /dev/sdb
729 volume:
730 data:
731 size: 40G
732 mount: ${linux:storage:mount:data}
733
Ales Komareka634f4b2016-10-02 13:11:04 +0200734
735Multipath with Fujitsu Eternus DXL
736
737.. code-block:: yaml
738
739 parameters:
740 linux:
741 storage:
742 multipath:
743 enabled: true
744 blacklist_devices:
745 - /dev/sda
746 - /dev/sdb
747 backends:
748 - fujitsu_eternus_dxl
749
750Multipath with Hitachi VSP 1000
751
752.. code-block:: yaml
753
754 parameters:
755 linux:
756 storage:
757 multipath:
758 enabled: true
759 blacklist_devices:
760 - /dev/sda
761 - /dev/sdb
762 backends:
763 - hitachi_vsp1000
764
765Multipath with IBM Storwize
766
767.. code-block:: yaml
768
769 parameters:
770 linux:
771 storage:
772 multipath:
773 enabled: true
774 blacklist_devices:
775 - /dev/sda
776 - /dev/sdb
777 backends:
778 - ibm_storwize
779
780Multipath with multiple backends
781
782.. code-block:: yaml
783
784 parameters:
785 linux:
786 storage:
787 multipath:
788 enabled: true
789 blacklist_devices:
790 - /dev/sda
791 - /dev/sdb
792 - /dev/sdc
793 - /dev/sdd
794 backends:
795 - ibm_storwize
796 - fujitsu_eternus_dxl
797 - hitachi_vsp1000
798
799Disabled multipath (the default setup)
800
801.. code-block:: yaml
802
803 parameters:
804 linux:
805 storage:
806 multipath:
807 enabled: false
808
Simon Pasquier375001e2017-01-26 13:22:33 +0100809Linux with local loopback device
810
811.. code-block:: yaml
812
813 linux:
814 storage:
815 loopback:
816 disk1:
817 file: /srv/disk1
818 size: 50G
819
Filip Pytlounb2c8f852016-11-21 17:03:43 +0100820External config generation
821--------------------------
822
823You are able to use config support metadata between formulas and only generate
824config files for external use, eg. docker, etc.
825
826.. code-block:: yaml
827
828 parameters:
829 linux:
830 system:
831 config:
832 pillar:
833 jenkins:
834 master:
835 home: /srv/volumes/jenkins
836 approved_scripts:
837 - method java.net.URL openConnection
838 credentials:
839 - type: username_password
840 scope: global
841 id: test
842 desc: Testing credentials
843 username: test
844 password: test
845
Ales Komareka634f4b2016-10-02 13:11:04 +0200846
Filip Pytlounf5383a42015-10-06 16:28:32 +0200847Usage
848=====
849
850Set mtu of network interface eth0 to 1400
851
852.. code-block:: bash
853
854 ip link set dev eth0 mtu 1400
855
856Read more
857=========
858
859* https://www.archlinux.org/
860* http://askubuntu.com/questions/175172/how-do-i-configure-proxies-in-ubuntu-server-or-minimal-cli-ubuntu
Filip Pytloun018f8712017-02-02 13:02:03 +0100861
862Documentation and Bugs
863======================
864
865To learn how to install and update salt-formulas, consult the documentation
866available online at:
867
868 http://salt-formulas.readthedocs.io/
869
870In the unfortunate event that bugs are discovered, they should be reported to
871the appropriate issue tracker. Use Github issue tracker for specific salt
872formula:
873
874 https://github.com/salt-formulas/salt-formula-linux/issues
875
876For feature requests, bug reports or blueprints affecting entire ecosystem,
877use Launchpad salt-formulas project:
878
879 https://launchpad.net/salt-formulas
880
881You can also join salt-formulas-users team and subscribe to mailing list:
882
883 https://launchpad.net/~salt-formulas-users
884
885Developers wishing to work on the salt-formulas projects should always base
886their work on master branch and submit pull request against specific formula.
887
888 https://github.com/salt-formulas/salt-formula-linux
889
890Any questions or feedback is always welcome so feel free to join our IRC
891channel:
892
893 #salt-formulas @ irc.freenode.net