{"id":895,"date":"2023-10-18T18:25:00","date_gmt":"2023-10-18T18:25:00","guid":{"rendered":"https:\/\/james-batchelor.com\/?p=895"},"modified":"2023-10-18T10:31:51","modified_gmt":"2023-10-18T10:31:51","slug":"manually-install-net-snmpd-on-gentoo","status":"publish","type":"post","link":"https:\/\/james-batchelor.com\/index.php\/2023\/10\/18\/manually-install-net-snmpd-on-gentoo\/","title":{"rendered":"Manually install net-snmpd on Gentoo"},"content":{"rendered":"\n<p>Recently we\u2019ve moved from an aged Opsview instance to Zabbix for our system health monitoring, which in turn facilitated moving data collector agents from Nagios to snmp.<\/p>\n\n\n\n<p>Many of our PBX\u2019s were deployed from the vendors ISO and so run atop of Gentoo, and it has a couple of issues:<\/p>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\">\n<li>We\u2019ve been told not to \u201cemerge\u201d anything by the vendor, as the base OS on the image is not maintained.<\/li>\n\n\n\n<li>Portage (Gentoo\u2019s package manager) has fallen out of date, meaning even if emerge is attempted, it\u2019ll fail as all repository links are broke.<\/li>\n<\/ol>\n\n\n\n<p>If faced with the same issue, this is how to install net-snmpd from source, add it a startup service and be able to monitor via snmp\u2026<\/p>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">Installation<\/h3>\n\n\n\n<p>On the Gentoo box, move to your home directory<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~<\/code><\/pre>\n\n\n\n<p>Download the source .tar.gz file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/sourceforge.net\/projects\/net-snmp\/files\/net-snmp\/5.9.4\/net-snmp-5.9.4.tar.gz<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Visit <a rel=\"noreferrer noopener\" href=\"http:\/\/www.net-snmp.org\/download.html\" target=\"_blank\">http:\/\/www.net-snmp.org\/download.html<\/a> for the latest version. When I was downloading SourceForge&#8217;s SSL cert had expired, if this happens <em>add &#8211;no-check-certificate<\/em> after wget in the command above.<\/p>\n<\/blockquote>\n\n\n\n<p>Untar the file to your home directory, and change into it<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -xzvf net-snmp-5.9.4.tar.gz\ncd net-snmp-5.9.4<\/code><\/pre>\n\n\n\n<p>Run the configuration script<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/configure<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>This allows you to set snmp version, file installation locations and snmp details, with exception of snmp version these can be left as default (Hit enter at the prompt). snmp details will look like this if left default&#8230;<\/p>\n<\/blockquote>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/james-batchelor.com\/wp-content\/uploads\/2023\/10\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"95\" src=\"https:\/\/james-batchelor.com\/wp-content\/uploads\/2023\/10\/image.png\" alt=\"\" class=\"wp-image-899\"\/><\/a><\/figure><\/div>\n\n\n<p>Compile and install snmpd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make\nmake install<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>The make process is quite CPU intensive, may want to do this during a quiet period for the server.<\/p>\n<\/blockquote>\n\n\n\n<p>Some libraries are not where they need to be, namely:<br>libnetsnmpagent.so.40<br>libnetsnmpmibs.so.40<br>libnetsnmp.so.40<br><br>Find where they were installed<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/ -name libnetsnmpagent.so.40<\/code><\/pre>\n\n\n\n<p>Pick the result that is not in your current working folder (the install setup) and link it to \/usr\/lib<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ln -s \/usr\/local\/lib64\/libnetsnmpagent.so.40 \/usr\/lib\/<\/code><\/pre>\n\n\n\n<p>Repeat this process with the other two files<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ln -s \/usr\/local\/lib64\/libnetsnmpmibs.so.40 \/usr\/lib\/\nln -s \/usr\/local\/lib64\/libnetsnmp.so.40 \/usr\/lib\/<\/code><\/pre>\n\n\n\n<p>Now can test to see if snmpd can run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>snmpd -v<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/james-batchelor.com\/wp-content\/uploads\/2023\/10\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"587\" height=\"140\" src=\"https:\/\/james-batchelor.com\/wp-content\/uploads\/2023\/10\/image-1.png\" alt=\"\" class=\"wp-image-902\"\/><\/a><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Configuration<\/h3>\n\n\n\n<p>Create a configuration file, the &#8220;snmpconf&#8221; command can be used but I found it easier to create from scratch<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/usr\/local\/share\/snmp\/snmpd.conf<\/code><\/pre>\n\n\n\n<p>For my needs, only this line is needed<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rocommunity {community} {ip address}<\/code><\/pre>\n\n\n\n<p>Save and exit the editor.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Testing<\/h3>\n\n\n\n<p>If you&#8217;d like to test your configuration, run snmpd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>snmpd<\/code><\/pre>\n\n\n\n<p>Test on the snmp target machine, for quick results snmpwalk can be run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>snmpwalk -c {community} -v 2c {ip address}<\/code><\/pre>\n\n\n\n<p>When run, snmpd automatically switches to a background process. To stop the process ID needs to be found and killed<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps aux | grep snmpd<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/james-batchelor.com\/wp-content\/uploads\/2023\/10\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"911\" height=\"97\" src=\"https:\/\/james-batchelor.com\/wp-content\/uploads\/2023\/10\/image-2.png\" alt=\"\" class=\"wp-image-906\"\/><\/a><\/figure><\/div>\n\n\n<p>Here the process ID (PID) is 5716, use this with the kill command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kill -9 {PID}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Add Service<\/h3>\n\n\n\n<p>Create the new service file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/etc\/init.d\/snmpd<\/code><\/pre>\n\n\n\n<p>Paste the following<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/sbin\/openrc-run\r\n \r\ndepend() {\r\n    after modules\r\n}\r\n \r\nstart() {\r\n    ebegin \"Starting snmpd\"\r\n    start-stop-daemon --background --start --exec \/usr\/local\/sbin\/snmpd --pidfile \/var\/run\/snmpd.pid \\\r\n    -- -p \/var\/run\/snmpd.pid -c \/usr\/local\/share\/snmp\/snmpd.conf\r\n    eend $?\r\n}\r\n \r\nstop() {\r\n    ebegin \"Stopping snmpd\"\r\n    start-stop-daemon --stop --exec \/usr\/local\/sbin\/snmpd \\\r\n    --pidfile \/var\/run\/snmpd.pid\r\n    eend $?\r\n}\r\nrestart() {\r\n    ebegin \"Restarting snmpd\"\r\n    start-stop-daemon --stop --exec \/usr\/local\/sbin\/snmpd\r\n    start-stop-daemon --background --start --exec \/usr\/local\/sbin\/snmpd --pidfile \/var\/run\/snmpd.pid \\\r\n    -- -p \/var\/run\/snmpd.pid -c \/usr\/local\/share\/snmp\/snmpd.conf\r\n    eend $?\r\n}<\/code><\/pre>\n\n\n\n<p>Save and exit the text editor, then make the file executable<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod +x \/etc\/init.d\/snmpd<\/code><\/pre>\n\n\n\n<p>Start the service, and check its running<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/etc\/init.d\/snmpd start\r\r\n\/etc\/init.d\/snmpd status<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/james-batchelor.com\/wp-content\/uploads\/2023\/10\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"407\" height=\"66\" src=\"https:\/\/james-batchelor.com\/wp-content\/uploads\/2023\/10\/image-3.png\" alt=\"\" class=\"wp-image-908\"\/><\/a><\/figure><\/div>\n\n\n<p>Finally, to make snmpd start with the system, run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rc-update add snmpd default<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">References<\/h3>\n\n\n\n<p>Help Creating init.d file<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/big-elephants.com\/2013-01\/writing-your-own-init-scripts\/\" target=\"_blank\">https:\/\/big-elephants.com\/2013-01\/writing-your-own-init-scripts\/<\/a><br><a href=\"https:\/\/tecadmin.net\/startup-shutdown-script-on-gentoo\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/tecadmin.net\/startup-shutdown-script-on-gentoo\/<\/a><\/p>\n\n\n\n<p>Experienced issue where the process-id in the PID file was not matching the PID of process. With help of below found flag for snmpd to specify PID file, and match that to init.d<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/forums.gentoo.org\/viewtopic-t-886230-start-0.html\" target=\"_blank\">https:\/\/forums.gentoo.org\/viewtopic-t-886230-start-0.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently we\u2019ve moved from an aged Opsview instance to Zabbix for our system health monitoring, which in turn facilitated moving data collector agents from Nagios to snmp. Many of our PBX\u2019s were deployed from the vendors ISO and so run atop of Gentoo, and it has a couple of issues: If faced with the same &hellip; <a href=\"https:\/\/james-batchelor.com\/index.php\/2023\/10\/18\/manually-install-net-snmpd-on-gentoo\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Manually install net-snmpd on Gentoo&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[154,5],"tags":[369,334,40,371,370,372,368,373,367],"class_list":["post-895","post","type-post","status-publish","format-standard","hentry","category-code","category-servers","tag-compile","tag-gentoo","tag-install","tag-install-from-scratch","tag-install-from-source","tag-manual-install","tag-net-snmpd","tag-service","tag-snmpd"],"_links":{"self":[{"href":"https:\/\/james-batchelor.com\/index.php\/wp-json\/wp\/v2\/posts\/895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/james-batchelor.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/james-batchelor.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/james-batchelor.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/james-batchelor.com\/index.php\/wp-json\/wp\/v2\/comments?post=895"}],"version-history":[{"count":14,"href":"https:\/\/james-batchelor.com\/index.php\/wp-json\/wp\/v2\/posts\/895\/revisions"}],"predecessor-version":[{"id":913,"href":"https:\/\/james-batchelor.com\/index.php\/wp-json\/wp\/v2\/posts\/895\/revisions\/913"}],"wp:attachment":[{"href":"https:\/\/james-batchelor.com\/index.php\/wp-json\/wp\/v2\/media?parent=895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/james-batchelor.com\/index.php\/wp-json\/wp\/v2\/categories?post=895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/james-batchelor.com\/index.php\/wp-json\/wp\/v2\/tags?post=895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}