├── Centos7_install.sh ├── README.md └── ubuntu_install.sh /Centos7_install.sh: -------------------------------------------------------------------------------- 1 | #Centos 7 install Librenms 2 | 3 | #get ip 4 | ip=`ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'` 5 | #安裝相關套件 6 | yum install -y epel-release git net-tools 7 | rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 8 | yum install -y composer cronie fping git ImageMagick jwhois mariadb mariadb-server mtr MySQL-python net-snmp net-snmp-utils nginx nmap php72w php72w-cli php72w-common php72w-curl php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-process php72w-snmp php72w-xml php72w-zip python-memcached rrdtool python3 9 | 10 | #新增使用者 11 | useradd librenms -d /opt/librenms -M -r 12 | usermod -a -G librenms nginx 13 | 14 | #下載LibreNMS 15 | cd /opt 16 | git clone https://github.com/librenms/librenms.git librenms 17 | 18 | #設定資料庫(這邊注意要修改密碼,預設為KH_password) 19 | systemctl start mariadb 20 | systemctl enable mariadb 21 | mysql -u root < /etc/my.cnf.d/server.cnf 30 | echo [server] >> /etc/my.cnf.d/server.cnf 31 | echo [mysqld] >> /etc/my.cnf.d/server.cnf 32 | echo innodb_file_per_table=1 >> /etc/my.cnf.d/server.cnf 33 | echo sql-mode=\"\" >> /etc/my.cnf.d/server.cnf 34 | echo lower_case_table_names=0 >> /etc/my.cnf.d/server.cnf 35 | echo [embedded] >> /etc/my.cnf.d/server.cnf 36 | echo [mysqld-5.5] >> /etc/my.cnf.d/server.cnf 37 | echo [mariadb] >> /etc/my.cnf.d/server.cnf 38 | echo [mariadb-5.5] >> /etc/my.cnf.d/server.cnf 39 | 40 | systemctl restart mariadb 41 | 42 | #設定Web Server 43 | echo date.timezone = \"Asia/Taipei\" >> /etc/php.ini 44 | 45 | sed -e 's/user = apache/user = nginx/' -i /etc/php-fpm.d/www.conf 46 | sed -e 's/\listen = 127.0.0.1:9000/listen = \/var\/run\/php-fpm\/php7.2-fpm.sock/' -i /etc/php-fpm.d/www.conf 47 | echo listen.owner = nginx >> /etc/php-fpm.d/www.conf 48 | echo listen.group = nginx >> /etc/php-fpm.d/www.conf 49 | echo listen.mode = 0660 >> /etc/php-fpm.d/www.conf 50 | 51 | systemctl enable php-fpm 52 | systemctl restart php-fpm 53 | 54 | #設定NGINX 55 | echo server { >> /etc/nginx/conf.d/librenms.conf 56 | echo listen 80\; >> /etc/nginx/conf.d/librenms.conf 57 | echo server_name $ip\; >> /etc/nginx/conf.d/librenms.conf 58 | echo root \/opt\/librenms\/html\; >> /etc/nginx/conf.d/librenms.conf 59 | echo index index.php\; >> /etc/nginx/conf.d/librenms.conf 60 | echo >> /etc/nginx/conf.d/librenms.conf 61 | echo charset utf-8\; >> /etc/nginx/conf.d/librenms.conf 62 | echo gzip on\; >> /etc/nginx/conf.d/librenms.conf 63 | echo gzip_types text\/css application\/javascript text\/javascript application\/x-javascript image\/svg+xml text\/plain text\/xsd text\/xsl text\/xml image\/x-icon\; >> /etc/nginx/conf.d/librenms.conf 64 | echo location \/ { >> /etc/nginx/conf.d/librenms.conf 65 | echo try_files \$uri \$uri\/ \/index.php?\$query_string\; >> /etc/nginx/conf.d/librenms.conf 66 | echo } >> /etc/nginx/conf.d/librenms.conf 67 | echo location \/api\/v0 { >> /etc/nginx/conf.d/librenms.conf 68 | echo try_files \$uri \$uri\/ \/api_v0.php?\$query_string\; >> /etc/nginx/conf.d/librenms.conf 69 | echo } >> /etc/nginx/conf.d/librenms.conf 70 | echo location \~ \\.php { >> /etc/nginx/conf.d/librenms.conf 71 | echo include fastcgi.conf\; >> /etc/nginx/conf.d/librenms.conf 72 | echo fastcgi_split_path_info \^\(.+\\.php\)\(\/.+\)\$\; >> /etc/nginx/conf.d/librenms.conf 73 | echo fastcgi_pass unix:\/var\/run\/php-fpm\/php7.2-fpm.sock\; >> /etc/nginx/conf.d/librenms.conf 74 | echo } >> /etc/nginx/conf.d/librenms.conf 75 | echo location \~ \/\\.ht { >> /etc/nginx/conf.d/librenms.conf 76 | echo deny all\; >> /etc/nginx/conf.d/librenms.conf 77 | echo } >> /etc/nginx/conf.d/librenms.conf 78 | echo } >> /etc/nginx/conf.d/librenms.conf 79 | systemctl enable nginx 80 | systemctl restart nginx 81 | 82 | 83 | #設定SELinux 84 | yum install -y policycoreutils-python 85 | semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/logs(/.*)?' 86 | semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/logs(/.*)?' 87 | restorecon -RFvv /opt/librenms/logs/ 88 | semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/rrd(/.*)?' 89 | semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/rrd(/.*)?' 90 | restorecon -RFvv /opt/librenms/rrd/ 91 | semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/storage(/.*)?' 92 | semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/storage(/.*)?' 93 | restorecon -RFvv /opt/librenms/storage/ 94 | semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/bootstrap/cache(/.*)?' 95 | semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/bootstrap/cache(/.*)?' 96 | restorecon -RFvv /opt/librenms/bootstrap/cache/ 97 | setsebool -P httpd_can_sendmail=1 98 | 99 | #建立http_fping.tt 100 | echo module http_fping 1.0\; >> /opt/http_fping.tt 101 | echo >> /opt/http_fping.tt 102 | echo require { >> /opt/http_fping.tt 103 | echo type httpd_t\; >> /opt/http_fping.tt 104 | echo class capability net_raw\; >> /opt/http_fping.tt 105 | echo class rawip_socket { getopt create setopt write read }\; >> /opt/http_fping.tt 106 | echo } >> /opt/http_fping.tt 107 | echo >> /opt/http_fping.tt 108 | echo #============= httpd_t ============== >> /opt/http_fping.tt 109 | echo allow httpd_t self:capability net_raw\; >> /opt/http_fping.tt 110 | echo allow httpd_t self:rawip_socket { getopt create setopt write read }\; >> /opt/http_fping.tt 111 | 112 | cd /opt 113 | checkmodule -M -m -o http_fping.mod http_fping.tt 114 | semodule_package -o http_fping.pp -m http_fping.mod 115 | semodule -i http_fping.pp 116 | 117 | #設定防火牆 118 | firewall-cmd --zone public --add-service http 119 | firewall-cmd --permanent --zone public --add-service http 120 | firewall-cmd --zone public --add-service https 121 | firewall-cmd --permanent --zone public --add-service https 122 | 123 | #配置snmpd 124 | cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf 125 | 126 | #加入排程 127 | cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms 128 | #轉出 logs 目錄下的記錄檔 129 | cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms 130 | 131 | #設定LibreNMS 132 | chown -R librenms:librenms /opt/librenms 133 | setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs 134 | setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs 135 | cd /opt/librenms 136 | ./scripts/composer_wrapper.php install --no-dev 137 | chown -R librenms:librenms /opt/librenms 138 | setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs 139 | setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs 140 | 141 | #clear 142 | echo "安裝完成" 143 | echo "請開啟網址: http://"$ip"/install.php" 144 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 自動化安裝LibreNMS 2 | LibreNMS是一套開源的網路裝置管理軟體,其分支於Observium,並且加入了社群版沒有的Alert功能。 3 | 4 | 本專案為自動化安裝LibreNMS Shell Script。 5 | 6 | ## 安裝準備: 7 | 安裝git 8 | centos: yum install git -y 9 | ubuntu: apt install git -y 10 | 11 | ## 安裝步驟: 12 | 13 | ### Step 1: 14 | git clone https://github.com/BensonRUEI/Librenms-Install-Shell.git 15 | 16 | ### Step 2: 17 | 根據系統不同執行不同的Shell Script,並且建議使用root來進行安裝。 18 | 19 | 20 | #### CentOS 7 以上 21 | 22 | sh Librenms-Install-Shell/Centos7_install.sh 23 | 24 | #### Ubuntu 16.04 以上 25 | 26 | sh Librenms-Install-Shell/ubuntu_install.sh 27 | 28 | ### Step 3: 29 | 開啟瀏覽器連至:http://YourIP/install.php ,根據內容進行相關設定(如DB Password、DB Name)。 30 | 31 | ### Step 4: 32 | 將Step所顯示的config.php文件寫入至/opt/librenms/config.php 33 | 34 | vim /opt/librenms/config.php 35 | 36 | ### Step 5: 37 | chown librenms:librenms /opt/librenms/config.php 38 | 39 | ### Switch SNMP 設定教學 40 | 請自行修改IP與CommunityString 41 | 42 | #CISCO 43 | conf t 44 | snmp-server community CommunityString 45 | snmp-server enable trap 46 | snmp-server host IP version 2c CommunityString 47 | end 48 | write memory 49 | 50 | 51 | #Aruba 52 | configure t 53 | snmp-server community CommunityString 54 | snmp-server enable trap 55 | snmp-server host IP version 2c CommunityString 56 | exit 57 | write memory 58 | 59 | 60 | ### 安裝教學影片 61 | Ubuntu 18.04 install LibreNMS 62 | [![](http://img.youtube.com/vi/PDYOwL5pDG8/0.jpg)](http://www.youtube.com/watch?v=PDYOwL5pDG8 "") 63 | 64 | CentOS 7 install LibreNMS 65 | [![](http://img.youtube.com/vi/UxsgXax2wBE/0.jpg)](http://www.youtube.com/watch?v=UxsgXax2wBE "") 66 | -------------------------------------------------------------------------------- /ubuntu_install.sh: -------------------------------------------------------------------------------- 1 | #Ubuntu install Librenms 2 | #20210320 改PHP7.4 3 | 4 | #get ip 5 | sudo apt install -y -q net-tools git 6 | ip=`ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.2.0.1'` 7 | #安裝相關套件 8 | echo "安裝相關套件" 9 | sudo add-apt-repository universe -y 10 | sudo apt update -y -q 11 | #sudo apt install -y acl curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.2-cli php7.2-curl php7.2-fpm php7.2-gd php7.2-json php7.2-mbstring php7.2-mysql php7.2-snmp php7.2-xml php7.2-zip python-memcache python-mysqldb rrdtool snmp snmpd whois vim curl 12 | sudo apt install software-properties-common -y -q 13 | #sudo apt install -y curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.2-cli php7.2-curl php7.2-fpm php7.2-gd php7.2-json php7.2-mbstring php7.2-mysql php7.2-snmp php7.2-xml php7.2-zip python-memcache python-mysqldb rrdtool snmp snmpd whois vim curl 14 | #sudo apt install -y curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.2-cli php7.2-curl php7.2-fpm php7.2-gd php7.2-json php7.2-mbstring php7.2-mysql php7.2-snmp php7.2-xml php7.2-zip python-memcache python-mysqldb rrdtool snmp snmpd whois unzip python3-pip 15 | #20210319更新php7.4 16 | sudo apt install -y -q curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-snmp php7.4-xml php7.4-zip acl rrdtool snmp snmpd whois unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-pip vim 17 | #新增使用者 18 | echo "新增使用者" 19 | useradd librenms -d /opt/librenms -M -r -s "$(which bash)" 20 | #useradd librenms -d /opt/librenms -M -r 21 | #usermod -a -G librenms www-data 22 | 23 | #下載LibreNMS 24 | echo "下載LibreNMS" 25 | cd /opt 26 | #git clone https://github.com/librenms/librenms.git librenms 27 | git clone https://github.com/librenms/librenms.git 28 | 29 | #設定權限 30 | echo "設定權限" 31 | chown -R librenms:librenms /opt/librenms 32 | chmod 771 /opt/librenms 33 | setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/ 34 | setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/ 35 | 36 | #設定PHP依賴 37 | echo "設定PHP依賴" 38 | #su - librenms 39 | #cd /opt/librenms 40 | #./scripts/composer_wrapper.php install --no-dev 41 | #exit 42 | sudo -u librenms php /opt/librenms/scripts/composer_wrapper.php install --no-dev 43 | 44 | #設定資料庫(這邊注意要修改密碼,預設為KH_password) 45 | echo "設定資料庫" 46 | systemctl restart mysql 47 | mysql -uroot < /etc/mysql/mariadb.conf.d/50-server.cnf 56 | echo [server] >> /etc/mysql/mariadb.conf.d/50-server.cnf 57 | echo [mysqld] >> /etc/mysql/mariadb.conf.d/50-server.cnf 58 | echo innodb_file_per_table=1 >> /etc/mysql/mariadb.conf.d/50-server.cnf 59 | echo sql-mode=\"\" >> /etc/mysql/mariadb.conf.d/50-server.cnf 60 | echo lower_case_table_names=0 >> /etc/mysql/mariadb.conf.d/50-server.cnf 61 | echo user = mysql >> /etc/mysql/mariadb.conf.d/50-server.cnf 62 | echo pid-file = /var/run/mysqld/mysqld.pid >> /etc/mysql/mariadb.conf.d/50-server.cnf 63 | echo socket = /var/run/mysqld/mysqld.sock >> /etc/mysql/mariadb.conf.d/50-server.cnf 64 | echo port = 3306 >> /etc/mysql/mariadb.conf.d/50-server.cnf 65 | echo basedir = /usr >> /etc/mysql/mariadb.conf.d/50-server.cnf 66 | echo datadir = /var/lib/mysql >> /etc/mysql/mariadb.conf.d/50-server.cnf 67 | echo tmpdir = /tmp >> /etc/mysql/mariadb.conf.d/50-server.cnf 68 | echo lc-messages-dir = /usr/share/mysql >> /etc/mysql/mariadb.conf.d/50-server.cnf 69 | echo skip-external-locking >> /etc/mysql/mariadb.conf.d/50-server.cnf 70 | echo bind-address = 127.2.0.1 >> /etc/mysql/mariadb.conf.d/50-server.cnf 71 | echo key_buffer_size = 16M >> /etc/mysql/mariadb.conf.d/50-server.cnf 72 | echo max_allowed_packet = 16M >> /etc/mysql/mariadb.conf.d/50-server.cnf 73 | echo thread_stack = 192K >> /etc/mysql/mariadb.conf.d/50-server.cnf 74 | echo thread_cache_size = 8 >> /etc/mysql/mariadb.conf.d/50-server.cnf 75 | echo myisam-recover = BACKUP >> /etc/mysql/mariadb.conf.d/50-server.cnf 76 | echo query_cache_limit = 1M >> /etc/mysql/mariadb.conf.d/50-server.cnf 77 | echo query_cache_size = 16M >> /etc/mysql/mariadb.conf.d/50-server.cnf 78 | echo log_error = /var/log/mysql/error.log >> /etc/mysql/mariadb.conf.d/50-server.cnf 79 | echo expire_logs_days = 10 >> /etc/mysql/mariadb.conf.d/50-server.cnf 80 | echo max_binlog_size = 100M >> /etc/mysql/mariadb.conf.d/50-server.cnf 81 | echo character-set-server = utf8mb4 >> /etc/mysql/mariadb.conf.d/50-server.cnf 82 | echo collation-server = utf8mb4_general_ci >> /etc/mysql/mariadb.conf.d/50-server.cnf 83 | echo [embedded] >> /etc/mysql/mariadb.conf.d/50-server.cnf 84 | echo [mariadb] >> /etc/mysql/mariadb.conf.d/50-server.cnf 85 | echo [mariadb-10.0] >> /etc/mysql/mariadb.conf.d/50-server.cnf 86 | systemctl restart mysql 87 | 88 | 89 | #設定Web Server 90 | echo date.timezone = \"Asia/Taipei\" >> /etc/php/7.4/fpm/php.ini 91 | echo date.timezone = \"Asia/Taipei\" >> /etc/php/7.4/cli/php.ini 92 | phpenmod mcrypt 93 | 94 | #設定PHP-FPM 95 | #cp /etc/php/7.4/fpm/pool.d/www.conf /etc/php/7.4/fpm/pool.d/librenms.conf 96 | cp /etc/php/7.4/fpm/pool.d/www.conf /etc/php/7.4/fpm/pool.d/librenms.conf 97 | sed -i 's/\[www\]/\[librenms\]/g' /etc/php/7.4/fpm/pool.d/librenms.conf 98 | sed -i 's/user \= www-data/user = librenms/g' /etc/php/7.4/fpm/pool.d/librenms.conf 99 | sed -i 's/group \= www-data/group = librenms/g' /etc/php/7.4/fpm/pool.d/librenms.conf 100 | sed -i 's/php\/php7.4-fpm.sock/php-fpm-librenms.sock/g' /etc/php/7.4/fpm/pool.d/librenms.conf 101 | sed -i 's/listen.group \= librenms/listen.group = www-data/g' /etc/php/7.4/fpm/pool.d/librenms.conf 102 | systemctl restart php7.4-fpm 103 | 104 | #設定NGINX 105 | echo server { >> /etc/nginx/conf.d/librenms.conf 106 | echo listen 80\; >> /etc/nginx/conf.d/librenms.conf 107 | echo server_name $ip\; >> /etc/nginx/conf.d/librenms.conf 108 | echo root \/opt\/librenms\/html\; >> /etc/nginx/conf.d/librenms.conf 109 | echo index index.php\; >> /etc/nginx/conf.d/librenms.conf 110 | echo >> /etc/nginx/conf.d/librenms.conf 111 | echo charset utf-8\; >> /etc/nginx/conf.d/librenms.conf 112 | echo gzip on\; >> /etc/nginx/conf.d/librenms.conf 113 | echo gzip_types text\/css application\/javascript text\/javascript application\/x-javascript image\/svg+xml text\/plain text\/xsd text\/xsl text\/xml image\/x-icon\; >> /etc/nginx/conf.d/librenms.conf 114 | echo location \/ { >> /etc/nginx/conf.d/librenms.conf 115 | echo try_files \$uri \$uri\/ \/index.php?\$query_string\; >> /etc/nginx/conf.d/librenms.conf 116 | echo } >> /etc/nginx/conf.d/librenms.conf 117 | echo location \/api\/v0 { >> /etc/nginx/conf.d/librenms.conf 118 | echo try_files \$uri \$uri\/ \/api_v0.php?\$query_string\; >> /etc/nginx/conf.d/librenms.conf 119 | echo } >> /etc/nginx/conf.d/librenms.conf 120 | echo location \~ \\.php { >> /etc/nginx/conf.d/librenms.conf 121 | echo include fastcgi.conf\; >> /etc/nginx/conf.d/librenms.conf 122 | echo fastcgi_split_path_info \^\(.+\\.php\)\(\/.+\)\$\; >> /etc/nginx/conf.d/librenms.conf 123 | echo fastcgi_pass unix:\/var\/run\/php-fpm-librenms.sock\; >> /etc/nginx/conf.d/librenms.conf 124 | echo } >> /etc/nginx/conf.d/librenms.conf 125 | echo location \~ \/\\.ht { >> /etc/nginx/conf.d/librenms.conf 126 | echo deny all\; >> /etc/nginx/conf.d/librenms.conf 127 | echo } >> /etc/nginx/conf.d/librenms.conf 128 | echo } >> /etc/nginx/conf.d/librenms.conf 129 | rm /etc/nginx/sites-enabled/default 130 | systemctl restart nginx 131 | 132 | #Enable lnms 133 | ln -s /opt/librenms/lnms /usr/bin/lnms 134 | cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/ 135 | 136 | #配置snmpd 137 | cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf 138 | sed -e 's/RANDOMSTRINGGOESHERE/public/' -i /etc/snmp/snmpd.conf 139 | curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro 140 | chmod +x /usr/bin/distro 141 | systemctl restart snmpd 142 | #加入排程 143 | cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms 144 | #轉出 logs 目錄下的記錄檔 145 | cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms 146 | 147 | #設定LibreNMS 148 | #chown -R librenms:librenms /opt/librenms 149 | #setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/ 150 | #setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/ 151 | #cd /opt/librenms 152 | #./scripts/composer_wrapper.php install --no-dev 153 | #chown -R librenms:librenms /opt/librenms 154 | #setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/ 155 | #setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/ 156 | 157 | 158 | #clear 159 | echo "安裝完成" 160 | echo "請開啟網址: http://"$ip"/install.php" 161 | --------------------------------------------------------------------------------