Press "Enter" to skip to content

Category: Linux运维

Linux,unix,mysql,database,oracle,mysql

linux下安装中文字体

装了redhat 5后发现,安装系统时没安装中文字体,没办法显示中文网页,都是乱码。
上网找到了安装的方法,步骤如下:
1.windows的字体一般存放在c:\windows\fonts目录下,copy你要的字体到linux下,文件是

ttf格式
2.把字体copy到/usr/share/fonts 目录下,然后执行以下命令
mkfontscale
mkfontdir//这两条命令是生成字体的索引信息
fc-cache //更新字体缓存
3.安装好了,可以查看中文网页了

via

Leave a Comment

RedHat5.5配置安装lnmp全过程(Linux+Nginx+Mysql+PHP)

一,安装必要的库和相关软件

# rpm -e mysql-server php-mysql php perl-DBD-MySQL mysql httpd
# yum -y install gcc gcc-c++ autoconf libtool* ncurses-devel pcre-devel zlib-devel libxml2-devel libpng-devel libjpeg-devel-6b freetype-devel gd-devel curl-devel libmcrypt-devel bison

# wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz   #下载cmake
# tar -zxvf cmake-2.8.4.tar.gz
# cd cmake-2.8.4
# ./configure && make && make install

二,安装mysql

Leave a Comment

MySQL Usage

1. User Management

# Create a database (replace '<DB NAME>' to your Database name)
CREATE DATABASE <DB NAME> CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

# Create a user and grant the database's permission to it
grant all privileges on <DB NAME>.* to <USER_NAME>@localhost identified by '<PASSWORD>';
# In MySQL 8.0 and later, the use of the IDENTIFIED BY clause with GRANT is deprecated. 
# Instead, you should use CREATE USER and ALTER USER statements to create and modify users,
CREATE USER '<USER_NAME>'@'localhost' IDENTIFIED BY '<PASSWORD>';
GRANT ALL PRIVILEGES ON <DB NAME>.* TO '<USER_NAME>'@'localhost';
flush privileges;

# Create a user and grant parts of the database's permission
grant select,update on <DB NAME>.* to <USER_NAME>@localhost identified by '<PASSWORD>';
CREATE USER '<USER_NAME>'@'localhost' IDENTIFIED BY '<PASSWORD>';
GRANT select,update ON <DB NAME>.* TO '<USER_NAME>'@'localhost';
flush privileges;

# See the User's Permission
show grants for <USER_NAME>@localhost;

# Delete a database
drop database <DB NAME>;

# Delete a user
DELETE FROM mysql.user WHERE User="<USER_NAME>" and Host="localhost";
flush privileges;

# Change Password for a User
update mysql.user set password=password('<NEW_PASSWORD>') where User="<USER_NAME>" and Host="localhost";
flush privileges;

2. DATABASE and Table Management

# Check a DB's Charset and Collection
SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME
FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '<DB NAME>';


# Alter a DB's charset and Collection
ALTER DATABASE <DB NAME> CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;


# Check the DB size
SELECT table_schema "DB Name",
        ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" 
FROM information_schema.tables GROUP BY table_schema; 


# Check the Table size (replace myDB with your DB name)
SELECT TABLE_NAME, table_rows, data_length, index_length, 
round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
FROM information_schema.TABLES WHERE table_schema = "<DB NAME>" ORDER BY (data_length + index_length) DESC;


# Optimize Table
OPTIMIZE TABLE <table name>;
OPTIMIZE TABLE <table 1>, <table 2>, <table 3>;

# Optimize Tables Using the Terminal
mysqlcheck -u root -p --auto-repair --optimize --myDB  # For a Single DB
mysqlcheck -u root -p --auto-repair --optimize --all-databases

3. Optimize Table

use <DB NAME>;

# Find tables need to be optimized
select table_name, data_length, data_free from information_schema.tables
where table_schema='<DB NAME>' order by data_free desc;
+-----------------------------------+-------------+-----------+
| table_name                        | data_length | data_free |
+-----------------------------------+-------------+-----------+
| wordpress_commentmeta             |       44028 |     19784 |
| wordpress_comments                |     2005588 |     13024 |
| wordpress_postmeta                |      569124 |       112 |
| wordpress_links                   |        1220 |         0 |
| wordpress_aioseo_posts            |       16384 |         0 |
| wordpress_terms                   |       38876 |         0 |
| wordpress_tla_rss_map             |           0 |         0 |
| wordpress_actionscheduler_groups  |       16384 |         0 |

the output shows some general information about the table. The following two numbers are important:

  • Data_length represents the amount of space the database takes up in total.
  • Data_free shows the allocated unused bytes within the database table. This information helps identify which tables need optimization and how much space will be released afterward.
optimize table wordpress_commentmeta, wordpress_comments;

# Check tables again
select table_name, data_length, data_free from information_schema.tables
where table_schema='<DB NAME>' order by data_free desc;
+-----------------------------------+-------------+-----------+
| table_name                        | data_length | data_free |
+-----------------------------------+-------------+-----------+
| wordpress_commentmeta             |       44028 |         0 |
| wordpress_comments                |     2005588 |         0 |
| wordpress_postmeta                |      569124 |       112 |
| wordpress_links                   |        1220 |         0 |
| wordpress_aioseo_posts            |       16384 |         0 |
| wordpress_terms                   |       38876 |         0 |
| wordpress_tla_rss_map             |           0 |         0 |
| wordpress_actionscheduler_groups  |       16384 |         0 |

The results of the optimization change the values of data_length and data_free of the optimized table. Both values are lowered, indicating:

1. The optimization freed the unused allocated memory.
2. The overall memory of the database is lower because of the released space.

3 Comments

在CentOS/RedHat中使用bind搭建主域名服务器

在CentOS/RedHat中使用bind搭建主域名服务器,记录一下。

1,安装必要软件

yum install bind bind-utils bind-chroot caching-nameserver -y

其中,bind是主程序,bind-utils提供测试工具(如nslookup等),bind-chroot提供伪装目录增强安全性,caching-nameserver是作为缓存域名服务器的。
安装完成以后,bind在系统中的服务名为named,可以通过以下方式来启动服务:

service named start
或者 /etc/init.d/named start

2,配置
因为安装了bind-chroot,故named的主配置文件位于/var/named/chroot/etc/,但目前没有配置文件,需要手动创建一个

Leave a Comment

Linux模拟硬盘资源耗尽故障

Linux硬盘资源包括[容量]及[文件数量(i节点)]两种,接下来,我们来模拟一下这两种资源分别被耗尽的故障。

环境搭建:
添加一块硬盘sdb,并在其中划分一块15M大小的分区/dev/sdb1,并将分区挂载至/mnt/111下。最后的挂载情况:

[root@localhost ~]# df -m        #查看容量
Filesystem           1M-blocks      Used Available Use% Mounted on
……省略内容
/dev/sdb1                   16         2        14   8% /mnt/111
[root@localhost ~]# df -i        #查看文件数量
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
……省略内容
/dev/sdb1               4016      11    4005    1% /mnt/111

1,模拟文件数量(i节点)耗尽故障
首先写一段bash脚本1.sh,不停地向分区系统里写入空文件。脚本内容如下:

2 Comments

Linux不重启识别新添加的磁盘

众所周知,VMWare可以在线为linux添加磁盘,但是添加磁盘过后,一般linux需要重新启动才可以识别新增加的磁盘。一直以来,在添加硬盘的时候下面这条提示让我很疑惑,根据多年经验,这里一定有玄机,后来上百度Google了一下,让我发现了不重启就能识别新添加的硬盘的方法。

Linux不重启识别新添加的磁盘

1、在开机状态下新增磁盘
2、执行下面的命令

echo "- - -" >  /sys/class/scsi_host/host0/scan

然后再运行fdisk -l就能发现新添加的硬盘已经被系统识别了,查看系统日志/var/log/messages,发现对SCSI设备进行了一次重新扫描
注意:三个- – -号之间有空隔。

3 Comments