rhel6.4 安装nodejs和Mysql DB服务

安装好redhat6.4虚拟机后, 安装软件:

# yum install gcc-c++ openssl-devel
Loaded plugins: product-id, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
No package openssl-devel available.
Error: Nothing to do


上网查询得知, redhat的yum源是收费的. 因此需要配置本地yum源. 步骤如下:

1) 将安装光盘镜像文件 rhel-server-6.4-x86_64-dvd.iso 上传到RHEL64虚拟机中:

$ scp ./rhel-server-6.4-x86_64-dvd.iso root@vm-ipaddr:~/

2) 在RHEL64虚拟机中挂载 ISO 文件(已将 rhel-server-6.4-x86_64-dvd.iso 移动到 /opt/ 下):

# mount -t iso9660 -o loop /opt/rhel-server-6.4-x86_64-dvd.iso /mnt/repo
# df -h


3) 创建rhel-debuginfo.repo

# vi /etc/yum.repos.d/rhel-debuginfo.repo


输入以下内容


[Server]
name=Red Hat Enterprise Linux Server
baseurl=file:///mnt/repo #本地iso的挂载路径
enabled=1 #可以使用yum
gpgcheck=1 #设置检查gpgkey
gpgkey=file:///mnt/repo/RPM-GPG-KEY-redhat-release # 配置gpgkey的路径

4) 修改yumRepo.py配置文件

# vi /usr/lib/python2.6/site-packages/yum/yumRepo.py
:802
找到802行, 将下面的语句:
remote = url + ‘/’ + relative
改为:
remote = '/mnt/repo' + '/' + relative


好了, 安装软件试试, 清理缓存:

# yum clean all
# yum install gcc-c++ openssl-devel

一切正常.

5) 为方便, 把这些mount写进 /etc/fstab,以便开机就挂载ISO:

/opt/rhel-server-6.4-x86_64-dvd.iso /mnt/repo iso9660 loop 0 0

==============================================================

下面安装nodejs:

1) 升级系统

# yum install gcc-c++ openssl-devel


2) 下载合适的nodejs包:


# wget http://nodejs.org/dist/v0.10.26/node-v0.10.26-linux-x64.tar.gz


3) 编译nodejs


# tar -zxvf node-v0.10.26-linux-x64.tar.gz
# cd node-v0.10.26
# ./configure
# make && make install


make时出现类似错误:ImportError: No module named bz2

多半是由于python的版本问题,新安装的python版本与系统自带的版本路径冲突,导致代码在import bz2模块时找不到路径。解决方案是通过临时改变PATH路径的方式解决:

​$ export PATH=/usr/bin:$PATH

​$ make && make install


4) 运行 nodejs


# node --version

使用yum安装mysql

1) 系统自动下载和安装Mysql

安装mysql-client:

# yum -y install mysql

安装mysql-server:

# yum -y install mysql mysql-server mysql-devel
# chgrp -R mysql /var/lib/mysql
# chmod -R 770 /var/lib/mysql

2) 服务启动, 更改root密码
# service mysqld start

第一次root登录不用输入密码:
# mysql -u root

更改root密码,例如: abc123456
mysql> SET PASSWORD FOR 'root'@'*' = PASSWORD('abc123456');

3) 在服务清单中添加mysql服务
# chkconfig --add mysqld

4) 更改root密码,例如: abc123456
# mysqladmin -u root password 'abc123456'

5) 可选: 登陆mysql, 然后删除test数据库
# mysql -u root -pabc123456
mysql> DROP DATABASE test;

删除匿名帐户
mysql> DELETE FROM mysql.user WHERE user = '';

重载权限
mysql> FLUSH PRIVILEGES;

添加mysql用户, 例如:car/abc789

mysql> GRANT ALL PRIVILEGES ON your_db_name.* TO 'car'@'%' IDENTIFIED BY 'abc789';

6) 要机器启动之后,自动启动mysqld:
# chkconfig --levels 345 mysqld on

7) 如要其他机器能访问,在mysql.user中添加一个Host为'%'的user,然后flush priviledges;

mysql> update mysql.user set host='%' where user='car';

mysql> FLUSH PRIVILEGES;

最后防火墙加一句类似这样的语句即可(开通3306端口):

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

8) 给用户赋予binlog权限, 以root登陆db:

mysql>GRANT SUPER, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO car@'%' IDENTIFIED BY 'abc789';


=============================================================

1. 打开Mysql的binlog:

mysql> show binary logs;
ERROR 1381 (HY000): You are not using binary logging

mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | OFF   |
+---------------+-------+
1 row in set (0.00 sec)

在my.cnf文件的[mysqld]下加上一行(windows为mysql.ini)

#vi /etc/my.cnf
[mysqld]

...

#添加这一行就ok了=号后面的路径和名字自己定义吧

log-bin=/var/lib/mysql/mysql-bin-log

# service mysqld restart;


mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+
1 row in set (0.00 sec)

mysql> show binlog events;
+----------------------+-----+-------------+-----------+-------------+----------------------------------------------------+
| Log_name             | Pos | Event_type  | Server_id | End_log_pos | Info                                               |
+----------------------+-----+-------------+-----------+-------------+----------------------------------------------------+
| mysql-bin-log.000001 |   4 | Format_desc |         1 |         106 | Server ver: 5.1.66-log, Binlog ver: 4              |
| mysql-bin-log.000001 | 106 | Query       |         1 |         207 | use `test`; insert into bigdata values (1,'zhang') |
+----------------------+-----+-------------+-----------+-------------+----------------------------------------------------+
2 rows in set (0.00 sec)

2. 查看当前工作的logfile名及大小: show binary logs /show master logs;

mysql> show binary logs;
+-----------------+-----------+
| Log_name           | File_size |
+-----------------+-----------+
| bin-log.000011 |    148329 |
+-----------------+-----------+

mysql> show master logs;
+-----------------+-----------+
| Log_name           | File_size |
+-----------------+-----------+
| bin-log.000011 |    148329 |
+-----------------+-----------+

mysql> show binary logs;
ERROR 1381 (HY000): You are not using binary logging ###没有开启binary logs

3. 清除所有binary logs;

1)

mysql> show master logs;
+-----------------+-----------+
| Log_name        | File_size |
+-----------------+-----------+
| log-bin.000001 |    259548 |
| log-bin.000002 |     37200 |
| log-bin.000003 |     74219 |
+-----------------+-----------+
3 rows in set (0.00 sec)

mysql> reset master; (在slave上,用reset slave,之前应stop slave,之后再start slave)
Query OK, 0 rows affected (0.00 sec)

mysql> show master logs;
+-----------------+-----------+
| Log_name        | File_size |
+-----------------+-----------+
| log-bin.000001 |        98 |
+-----------------+-----------+
1 row in set (0.00 sec)

4. 清除指定部分logs:

mysql>purge binary logs to 'log-bin.000012';

将log-bin.000012之前的binary logs清掉;

mysql>purge binary logs before '2011-05-28 12:05:38';

将指定时间之前的binary logs清掉;

5.查看当前binary log的情况:

mysql>show master status;

6. 查看binary logs的内容:

mysql>show binlog events;

命令行下:

#mysqlbinlog /var/log/mysql/log-bin.000140; 或者

#mysqlbinlog --start-datetime='2011-07-01 00:00:00' --stop-datetime='2010-07-15 00:00:00' /var/log/mysql/log-bin.000020 > ./tmp.log

7. 在my.cnf/my.ini中设定binary logs回滚天数:

expire_logs_days = 7