阿里雲上安裝mariadb10.2.6,和php-5.6.30

安裝mariadb

  • 背景
    • 在阿里雲上安裝
  1. 首先切換到/usr/local/src目錄下
[root@hf-02 ~]# cd /usr/local/src
[root@hf-02 src]#
  1. 而後安裝mariadb包,並解壓mariadb包
[root@hf-02 src]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
  1. 查看解壓的包
[root@hf-02 src]# ls
mariadb-10.2.6-linux-glibc_214-x86_64  mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
  1. 移動並更名mariadb包
[root@hf-02 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
  1. 切換到/usr/local/mariadb目錄下
[root@hf-02 src]# cd !$
cd /usr/local/mariadb
  1. 建立用戶和目錄
[root@hf-02 mariadb]# useradd mysql
[root@hf-02 mariadb]# mkdir /data/
  1. 初始化
[root@hf-02 mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
  • 這裏提示是缺乏安裝包,只須要安裝perl-Data-Dumper包和libaio包便可
[root@hf-02 mariadb]# .yum install -y perl-Data-Dumper

[root@hf-02 mariadb]# .yum install -y libaio
  1. 而後再次初始化,在echo $?檢查是否成功
[root@hf-02 mariadb]# echo $?
0
  1. 編輯配置文件
[root@hf-02 mariadb]# vim /etc/my.cnf

修改配置文件內容
在 [mysqld] 中
把datadir=/var/lib/mysql 改爲 datadir=/data/mysql
把socket=/var/lib/mysql/mysql.sock 改爲 socket=/tmp/mysql.sock

在 [mysqld_safe] 中
在log-error行和pid-file行前面 加 # ,把它們註釋掉

在 !includedir /etc/my.cnf.d 也註釋掉
  1. 拷貝配置文件和啓動腳本
[root@hf-02 mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
[root@hf-02 mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
  1. 編輯啓動腳本
[root@hf-02 mariadb]# vim /etc/init.d/mariadb

在文件中定義
basedir=/usr/local/mariadb
datadir=/data/mariadb
  1. 查看文件的權限,是否爲755,默認是755權限
[root@hf-02 mariadb]# ls -l /etc/init.d/mariadb
-rwxr-xr-x 1 root root 12258 Dec 22 16:19 /etc/init.d/mariadb
  1. 設置開機啓動,將服務加入到服務列表中
[root@hf-02 mariadb]# chkconfig --add mariadb
[root@hf-02 mariadb]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

aegis          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
agentwatch     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
mariadb        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
opensmd        	0:off	1:off	2:off	3:off	4:off	5:off	6:off
srpd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
  1. 啓動mariadb服務
[root@hf-02 mariadb]# service mariadb start
Starting MySQL.171222 16:22:16 mysqld_safe Logging to '/data/mariadb/hf-02.err'.
171222 16:22:16 mysqld_safe Starting mysqld daemon with databases from /data/mariadb
                                                           [  OK  ]
  1. 查看mariadb服務是否啓動
[root@hf-02 ~]# ps aux |grep mariadb
root      1017  0.0  0.0 115376  1724 ?        S    12:58   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --datadir=/data/mariadb --pid-file=/data/mariadb/hf-02.pid
mysql     1570  0.0  3.4 1125016 65304 ?       Sl   12:58   0:00 /usr/local/mariadb/bin/mysqld --basedir=/usr/local/mariadb --datadir=/data/mariadb --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mariadb/hf-02.err --pid-file=/data/mariadb/hf-02.pid --socket=/tmp/mysql.sock --port=3306
root      2532  0.0  0.0 112644   964 pts/0    R+   13:36   0:00 grep --color=auto mariadb
[root@hf-02 ~]#
  1. 查看端口
[root@hf-02 mariadb]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      3005/sshd           
tcp6       0      0 :::3306                 :::*                    LISTEN      22840/mysqld
  1. 這樣mariadb服務則就安裝啓動完成,在開機的時候會自動啓動,如果要殺死進程,則killall mysqld ,就會把mariadb服務殺掉。

安裝phpphp-5.6.30

  1. 首先進入到/usr/local/src/目錄下
[root@hf-02 ~]# cd /usr/local/src/
[root@hf-02 src]#
  1. 而後下載php安裝包
[root@hf-02 src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
  1. 解壓安裝包
[root@hf-02 src]# tar zxvf php-5.6.30.tar.gz
  1. 切換到/usr/local/src/php-5.6.30/目錄下
[root@hf-02 src]# cd php-5.6.30
[root@hf-02 php-5.6.30]#
  1. 安裝所須要的包
[root@hf-02 php-5.6.30]# yum install -y libxml2-devel

[root@hf-02 php-5.6.30]# yum install -y openssl-devel

[root@hf-02 php-5.6.30]#yum install bzip2-devel

[root@hf-02 php-5.6.30]# yum install -y libjpeg-devel

[root@hf-02 php-5.6.30]#yum install -y libpng-devel

[root@hf-02 php-5.6.30]# yum install -y freetype-devel

[root@hf-02 php-5.6.30]# yum install -y epel-release
[root@hf-02 php-5.6.30]# yum install -y libmcrypt-devel
  1. 而後進行初始化,第一次初始化
[root@hf-02 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/sbin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
  • 錯誤
    • 在初始化的時候,提示這個錯誤
Sorry, I cannot run apxs.  Possible reasons follow:

1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)

The output of /usr/local/apache2.4/bin/apxs follows:
./configure: line 8417: /usr/local/apache2.4/bin/apxs: No such file or directory
configure: error: Aborting
  • 解決辦法,將--with-apxs2=/usr/local/sbin/apxs改爲--with-apxs2=/usr/bin/apxs
  1. 第二次初始化,把--with-mysql --with-pdo-mysql --with-mysqli這三個=號後面的全乾掉,初始化就能夠成功了
    • 由於mariadb太新,php暫時只能使用較老版本的mysql的lib庫文件
    • 把=號後面的全乾掉意思就是編譯的時候所需的mysql的lib庫文件用mysql默認的文件,而不是你以前報錯時指定的庫文件
[root@hf-02 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql --with-pdo-mysql --with-mysqli --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
  1. 而後檢查是否初始化成功
[root@hf-02 php-5.6.30]# echo $?
0
  1. 再來make && make install
[root@hf-02 php-5.6.30]# make && make install

最後顯示的結果
Installing PEAR environment:      /usr/local/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.0
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.3.0
[PEAR] PEAR           - installed: 1.10.1
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/local/src/php-5.6.30/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/
  1. 這樣就成功安裝了php5
相關文章
相關標籤/搜索