2016年(11)
分类: 系统运维
2016-04-05 01:09:56
注意首先先修改服务器时间,并且关闭selinux。
这里用到的是传统LAMP环境,安装分为以下几个方面。
iptables
[root@localhost snmp]# iptables -I INPUT 3 -p udp --dport 161 -j ACCEPT #######snmp端口
[root@localhost snmp]# iptables -I INPUT 3 -m state --state NEW -p tcp --dport 80 -j ACCEPT ####http端口
[root@localhost snmp]# service iptables save
[root@localhost snmp]# service iptables restart
Apache
[root@localhost src]# tar zxvf httpd-2.2.31.tar.gz
[root@localhost src]# cd httpd-2.2.31
[root@localhost httpd-2.2.31]# ./configure --prefix=/usr/local/apache --enable-so
configure: error: Cannot use an external APR with the bundled APR-util
[root@localhost httpd-2.2.31]# yum install apr-util-devel gcc
[root@localhost httpd-2.2.31]# make
[root@localhost httpd-2.2.31]# make install
把httpd服务加入启动项
[root@localhost ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@localhost ~]# vi /etc/init.d/httpd
#chkconfig: 2345 10 90
#description: Activates/Deactivates Apache Web Server
[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# chkconfig --list | grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost ~]# vi /usr/local/apache/conf/httpd.conf
ServerName localhost:80
Mysql
[root@localhost ~]# useradd -s /sbin/nologin mysql
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar zxvf mysql-5.5.47-linux2.6-x86_64.tar.gz
[root@localhost src]# mv mysql-5.5.47-linux2.6-x86_64 /usr/local/mysql
[root@localhost src]# cd /usr/local/mysql
[root@localhost mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
数据库的安装及初始化
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod 755 /etc/init.d/mysqld
[root@localhost mysql]# vim /etc/init.d/mysqld
需要修改的地方有 “basedir=/usr/local/mysql”
需要修改的地方有 “datadir=/data/mysql” (前面初始化数据库时定义的目录)
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
[root@localhost mysql]# chkconfig --list |grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost mysql]# service mysqld start
[root@localhost ~]# mysqladmin -uroot password '123456'
php
[root@localhost src]# tar zxvf php-5.6.17.tar.gz
[root@localhost src]# yum install libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel gd gd-devel libxml2-devel libxml2
[root@localhost src]# cd php-5.6.17
[root@localhost php-5.6.17]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql/ --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --enable-sockets
[root@localhost php-5.6.17]#make
[root@localhost php-5.6.17]#make install
[root@localhost php-5.6.17]#cp php.ini-production /usr/local/php/lib/php.ini
[root@localhost php-5.6.17]#vi /usr/local/php/lib/php.ini
timezone = PRC
将 Apache、 PHP 二者整合
编辑 Apache 配置文件 httpd.conf,在配置文件加入如下内容
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
然后将 DirectoryIndex 后的 index.html 修改为 index.php
测试
# cd /usr/local/apache/htdocs/
# vi index.php
在 index.php 文件中写入下面三行
phpinfo();
?>
重启 apache 服务后在浏览器中输入IP则可以看到php页面。
rrdtool
[root@localhost src]# yum install libpng freetype zlib glib fontconfig pixman pkgconfig cairo cairo-devel libxml2 libxml2-devel pango pango-devel perl-devel perl-CPAN perl-ExtUtils-Embed rrdtool-perl perl-ExtUtils-MakeMaker perl-ExtUtils-CBuilderlibart_lgpl-devel ruby ruby-libs
[root@localhost src]# tar zxv rrdtool-1.5.4.tar.gz
[root@localhost src]# ./configure --prefix=/usr/local/rrdtool --disable-tcl --disable-python
[root@localhost src]# make
[root@localhost src]# make install
[root@localhost rrdtool]# ln -s /usr/local/rrdtool/bin/* /usr/local/bin/
snmp
yum install rrdtool rrdtool-devel net-snmp net-snmp-devel net-snmp-utils net-snmp-python net-snmp-perl
cacti
[root@localhost src]#tar zxvf cacti-0.8.8g.tar.gz
[root@localhost src]#mv cacti-0.8.8g/* /usr/local/apache/htdocs/
[root@localhost src]#mysql -uroot -p123456
mysql>
create database cacti; //创建 cacti 数据库
mysql> flush privileges; //重载 MySQL 授权表
mysql> grant all on cacti.* to cacti@'localhost' identified by 'cacti123';
//把数据库 cacti 授权
于用户 cacti
cd /usr/local/apache/htdocs/cacti
[root@localhost cacti]# mysql -uroot -p123456 cacti < cacti.sql导入 cacti 数据库
[root@localhost cacti]# cd include/
[root@localhost include]# vi config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "123456";
$database_port = "3306";
$database_ssl = false;
增加 cacti 用户以用来写入rrd和log目录的数据,否则就会生成不了图片
[root@localhost cacti]# chown -R cacti:cacti rra/ log/ ? 是不是cacti:root
[root@localhost cacti]# crontab –e
*/1 * * * * php /usr/local/apache/htdocs/cacti/poller.php > /dev/null 2>&1
最后!
默认密码admin admin
密码修改为cacti123