前言
系统环境
[root@lnmp mysql]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@lnmp mysql]# uname -r
3.10.0-514.el7.x86_64
官方下载地址
安装mariadb10.3.13
1. 下载mariadb二进制包
由于源码包编译时间过长就不选用了,而选用已经编译过的二进制包
$ wget https://mirrors.shu.edu.cn/mariadb//mariadb-10.3.13/bintar-linux-x86_64/mariadb-10.3.13-linux-x86_64.tar.gz
2. 解压
$ tar -zxvf mariadb-10.3.13-linux-x86_64.tar.gz
3. 将解压后的二进制包放置软件目录
这里我习惯放置在/usr/local下,并改名mysql
$ mv mariadb-10.3.13-linux-x86_64 /usr/local/mysql
4. 创建数据存储目录与管理用户mysql
$ groupadd mysql
$ useradd -s /sbin/nologin -M mysql
$ cd /usr/local/mysql
$ chown -R mysql:mysql .
5.初始化
$ ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
这一步如果报错:
/usr/local/mariadb/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:yum install -y libaio-devel
6.检查是否安装成功
在初始化命令之后使用$ ech $?,查看返回结果是否为0,为0表示成功,不为0表示失败。
7.拷贝启动脚本,并用chkconfig工具管理
$ cd /usr/local/mysql
$ cp support-files/mysql.server /etc/init.d/mysqld
# 定义启动脚本内容,修改datadir和basedir
$ vim /etc/init.d/mysqld
# 修改
basedir=/usr/local/mysql # 软件的目录
datadir==/usr/local/mysql/data # 存放数据目录
# 修改完,设置开机自启动
$ chkconfig --add mysqld
$ chkconfig mysqld on
8.设置mariadb配置文件/etc/my.cnf
$ vim /etc/my.cnf
# 修改配置内容为
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mariadb.log
pid-file=/usr/local/mysql/data/mariadb.pid
保存退出。
9. 启动mariadb服务
$ /etc/init.d/mysqld start #启动mariadb
10. 查看端口进程
[root@lnmp mysql]$ netstat -lntp | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 4225/mysqld
[root@lnmp mysql]$ ps aux | grep mysql
root 4140 0.0 0.0 115436 1756 ? S 13:31 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/lnmp.pid
mysql 4225 0.0 4.8 1713716 90736 ? Sl 13:31 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/mariadb.log --pid-file=/usr/local/mysql/data/lnmp.pid --socket=/tmp/mysql.sock
root 4280 0.0 0.0 112728 964 pts/1 S+ 13:43 0:00 grep --color=auto mysql
11. 进入mariadb数据库
$ /usr/local/mysql/bin/mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.3.13-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
12. 设置软连接
$ ln -s /usr/local/mysql/bin/mysql /usr/bin
$ ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
13. 设置root密码
$ mysqladmin -u root -p '!@#123qwe'
14. root用户登录mysql
[root@lnmp mysql]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.13-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
至此mariadb安装完毕。
安装php7.3.3
1. 下载软件包
下载地址:http://php.net/get/php-7.3.3.tar.bz2/from/a/mirror
选择中国镜像站点下载,或者复制链接地址wget下载也可以。
这里我是先下载到我的window再上传到linux。
2. 解压
$ tar -jxvf php-7.3.3.tar.bz2
# 如果没有安装bzip2工具会报错
$ yum install -y bzip2
3. 安装依赖包
$ yum install -y gcc libxml2-devel zlib-devel openssl-devel bzip2-devel libjpeg-devel libpng-devel epel-release libmcrypt-devel curl-devel freetype-devel
4. 编译参数
$ ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
5. 安装
make && make install
6. 拷贝配置文件
$ cp /usr/local/src/php-7.3.3/php.ini-development /usr/local/php-fpm/etc/php.ini
$ cp /usr/local/php-fpm/etc/php-fpm.conf.default /usr/local/php-fpm/etc/php-fpm.conf
7. 配置启动脚本设置开机启动
$ cp /usr/local/src/php-7.3.3/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
$ chmod +x php-fpm
$ chkconfig --add php-fpm
$ chkconfig php-fom on
8. 创建用户,配置pool
$ useradd php-fpm
$ cp /usr/local/php-fpm/etc/php-fpm.d/www.conf.default /usr/local/php-fpm/etc/php-fpm.d/www.conf
9.启动服务,查看进程
[root@lnmp ~]$ service php-fpm start
Starting php-fpm done
[root@lnmp ~]$ ps aux | grep php-fpm
root 18747 0.0 0.3 115992 6284 ? Ss 13:27 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 18748 0.0 0.3 115992 5836 ? S 13:27 0:00 php-fpm: pool www
php-fpm 18749 0.0 0.3 115992 5836 ? S 13:27 0:00 php-fpm: pool www
root 18751 0.0 0.0 112724 988 pts/0 S+ 13:27 0:00 grep --color=auto php-fpm
[root@lnmp ~]$ netstat -lntp | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 18747/php-fpm: mast
php安装完毕。
编译安装nginx1.14.2
1. 下载软件包
$ cd /usr/local/src
$ wget http://nginx.org/download/nginx-1.14.2.tar.gz
2. 解压
$ tar -zxvf nginx-1.14.2.tar.gz
3. 编译安装
$ cd nginx-1.14.2
$ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
$ make && make install
4. 添加nginx启动脚本
$ vim /etc/init.d/nginx
内容如下:
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart()
{
stop
start
}
configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
5. 设置nginx开机启动
$ chmod +x /etc/init.d/nginx
$ chkconfig --add nginx
$ chkconfig nginx on
6. 启动nignx,查看进程端口
[root@lnmp nginx-1.14.2]$ /etc/init.d/nginx start
Starting nginx (via systemctl): [ 确定 ]
[root@lnmp nginx-1.14.2]$ ps aux | grep nginx
root 21486 0.0 0.0 45948 1120 ? Ss 13:50 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 21487 0.0 0.1 46384 1900 ? S 13:50 0:00 nginx: worker process
root 21489 0.0 0.0 112724 988 pts/0 S+ 13:50 0:00 grep --color=auto nginx
[root@lnmp nginx-1.14.2]$ netstat -lntp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21486/nginx: master
至此nginx安装完毕。