一、nginx部署
1.安装nginx前的系统依赖环境检查
yum install pcre pcre-devel openssl openssl-devel gcc -y
2.下载nginx源代码包
wget http://nginx.org/download/nginx-1.16.0.tar.gz
3.解压缩源码包
tar -zxvf nginx-1.16.0.tar.gz mkdir /opt/nginx-1.16.0/
4.创建普通的nginx用户
用于运行nginx的进程,降低nginx的系统权限
-M选项,不自动建立用户的家目录
-u,制定用户uid
useradd nginx -u 1111 -s /sbin/nologin -M
5.开始编译安装nginx服务
cd nginx-1.16.0 ./configure --user=nginx --group=nginx --prefix=/opt/nginx-1.16.0/ --with-http_stub_status_module --with-http_ssl_module make && make install
这样就是成功了
6.创建一个软连接以供集中管理
mkdir -p /nginx/ngin116 ln -s /opt/nginx-1.16.0/ /nginx/ngin116/
7.配置nginx环境变量
添加nginx的sbin目录添加到path中
vim /etc/profile PATH="$PATH:/nginx/ngin116/sbin"
重新打开一个tty
二、mysql
1.创建普通mysql用户
降低程序运行权限
useradd -s /sbin/nologin mysql
2.下载mysql二进制代码包
注意提前下载好wget工具
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
3.创建mysql的快捷方式
tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local cd /usr/local ln -s mysql-5.7.26-linux-glibc2.12-x86_64 mysql
4.安全性的准备工作
卸载可能centos7存在的mariadb相关的依赖关系
rpm -e --nodeps mariadb-libs
5.设置环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile source /etc/profile
6.启动mysql的配置文件
[root@localhost local]# mkdir -pv /data/mysql mkdir: created directory ‘/data’ mkdir: created directory ‘/data/mysql’ [root@localhost local]# chown mysql.mysql /data/mysql [root@localhost local]# chmod go-rwx /data/mysql
vim /etc/my.cnf
[mysqld] basedir=/usr/local/mysql/ datadir=/usr/local/mysql/data socket=/tmp/mysql.sock server_id=1 port=3306 log_error=/usr/local/mysql/data/mysql_err.log [mysql] socket=/tmp/mysql.sock
7.检查mysql所依赖的环境
yum install libaio-devel -y
8.创建mysql数据文件夹
用于初始化数据
mkdir -p /usr/local/mysql/data/ chown -R mysql.mysql /usr/local/mysql/
9.初始化mysql数据库
mkdir -p /usr/local/mysql/data/ chown -R mysql.mysql /usr/local/mysql/
10.使用systemctl命令管理mysql数据库
编写mysql启动脚本,定义一个mysqld.service
vim /etc/systemd/system/mysqld.service
[Unit] Description=MySQL server by nginx Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE=5000
systemctl restart mysqld.service
11.登录mysql数据库
先检查下以前有没有默认的MySQL
[root@localhost system]# yum remove mysql -y Loaded plugins: fastestmirror No Match for argument: mysql No Packages marked for removal [root@localhost system]# which mysql /usr/bin/which: no mysql in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/nginx/ngin116/sbin:/root/bin)
编辑profile文件
vim /etc/profile
在最后添加
PATH="$PATH:/usr/local/mysql/bin"
重新编译一下
source /etc/profile
登录默认没有密码
mysql -uroot -p
修改密码
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> UPDATE user SET authentication_string=PASSWORD("123456") WHERE User="root"; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)