centos lnmp

—nginx—
yum install -y gcc pcre-devel openssl openssl-devel

wget http://nginx.org/download/nginx-1.13.2.tar.gz
tar zxvf nginx-1.13.2.tar.gz

make && make install

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

—mysql5.7—

1.准备工作
首先需要准备mysql的源码包,最新版本是5.7.12
下载地址为:
http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.12.tar.gz

同时,mysql 5.7需要boost 1.59以及以上版本,需要在sourceforge上下载。地址为:
http://www.boost.org/users/download/

安装之前最好检查一下是否已安装了mysql和boost

rpm -qa | grep mysql //查看系统自带mysql
yum -y remove mysql-* //卸载mysql
rpm -e –nodeps mysql-5.1.73-3.el6_5.x86_64 //卸载mysql
rpm -qa | grep boost //查看系统自带boost
yum -y remove boost-* //卸载boost
rpm -e –nodeps boost-filesystem-1.41.0-11.el6_1.2.x86_64 //卸载boost
然后安装其它得依赖包:

yum install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl cmake

2.准备安装
首先将boost库解压出来

tar -zxvf boost_1_59_0.tar.gz
然后拷贝到一个目录中
mv boost_1_59_0 /usr/local/boost

然后创建用户组以及用户

cat /etc/group | grep mysql //查看是否存在mysql用户组
cat /etc/passwd | grep mysql //查看是否存在mysql用户
groupadd mysql //创建用户组
useradd -r -g mysql mysql //创建用户

上面得工作完成以后,就可以开始编译mysql了,当然,先将mysql的源码解压出来:

tar xzvf mysql-5.7.12.tar.gz
cd mysql-5.7.12

wget https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.tar.gz

groupadd mysql
useradd -gmysql mysql
mkdir -p /data/mysql
mkdir /data/mysqlData
chown -R mysql:mysql /data/mysql /data/mysqlData

上面得工作完成以后,就可以开始编译mysql了,当然,先将mysql的源码解压出来:

tar xzvf mysql-5.7.12.tar.gz
cd mysql-5.7.12
使用cmake和make命令来进行编译

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost

make && make install

编译会消耗较多的时间,期间可以喝杯茶,或者来创建几个目录,因为我们指定编译参数得时候,指定了mysql得数据存储的目录,因此,这个时候可以先把目录都创建出来:

chmod +w /usr/local/mysql/
chown -R mysql:mysql /usr/local/mysql/

mkdir -p /var/mysql
mkdir -p /var/mysql/data/
mkdir -p /var/mysql/log/
chown -R mysql:mysql /var/mysql/

cp my-medium.cnf /etc/my.cnf

cp mysql.server /etc/init.d/mysql

mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
mkdir /usr/local/mysql/logs
mkdir /usr/local/mysql/pids

最后还有重要得一步,需要将目录得所有权交给mysql用户

chown -R mysql:mysql /usr/local/mysql //需要root权限

ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

编译完成后执行make install 安装即可
随后,我们需要配置/etc/my.cnf文件:

vim /etc/my.cnf

datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
explicit_defaults_for_timestamp=true

log-error=/usr/local/mysql/logs/mysqld.log
pid-file=/usr/local/mysql/pids/mysqld.pid

4.其它配置
通常我们需要重启服务器,最好在重启服务器的时候就启动mysql

cp support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld //需要root权限

然后将mysql添加到环境变量,修改/etc/profile文件

vim /etc/profile //需要root
//在文件的最后面加入
#mysql path
export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
最后执行 source /etc/profile

随后我们也需要多数据库进行初始化操作。自 mysql5.7 开始,初始化系统表不再使用 mysql_install_db 工具, 而是使用 mysqld –initialize-insecure –user=mysql , 其中 –initialize 表示默认生成一个安全的密码, –initialize-insecure 表示不生成密码, 密码为空

mysqld –initialize-insecure –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data
现在可以启动mysql 服务器:

chkconfig mysqld on
最后我们将root密码修改一下:

mysql -u root
mysql> use mysql;
mysql>update user set authentication_string=password(‘123456′) where user=’root’ and Host = ‘localhost’;
mysql> FLUSH PRIVILEGES;

特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Password字段了

而是将加密后的用户密码存储于authentication_string字段

5.tips
执行make命令的时候可以加-j(多进程)参数来加快编译速度
make -j “cpu 核数”

比如已知CPU是4核心的,可以使用:
make -j 4

mysqld –initialize-insecure –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data

—php7—
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum install php-mcrypt libmcrypt libmcrypt-devel -y
yum install -y libxml2 libxml2-devel curl-devel libjpeg-devel libpng libpng-devel freetype-devel

./configure –prefix=/usr/local/php7 –exec-prefix=/usr/local/php7 –bindir=/usr/local/php7/bin –sbindir=/usr/local/php7/sbin –includedir=/usr/local/php7/include –libdir=/usr/local/php7/lib/php –mandir=/usr/local/php7/php/man –with-config-file-path=/usr/local/php7/etc –with-mysql-sock=/var/run/mysql/mysql.sock –with-mcrypt=/usr/include –with-mhash –with-openssl –with-mysql=shared,mysqlnd –with-mysqli=shared,mysqlnd –with-pdo-mysql=shared,mysqlnd –with-gd –with-iconv –with-zlib –enable-zip –enable-inline-optimization –disable-debug –disable-rpath –enable-shared –enable-xml –enable-bcmath –enable-shmop –enable-sysvsem –enable-mbregex –enable-mbstring –enable-ftp –enable-gd-native-ttf –enable-pcntl –enable-sockets –with-xmlrpc –enable-soap –without-pear –with-gettext –enable-session –with-curl –with-jpeg-dir –with-freetype-dir –enable-opcache –enable-fpm –with-fpm-user=php7 –with-fpm-group=php7 –without-gdbm –with-mcrypt=/usr/local/related/libmcrypt –disable-fileinfo

Jason.wang

When you find your talent can't afford to be ambitious, be quiet and study !

You may also like...