源码安装HTTPD和MySQL

源码安装HTTPD

从网上下载httpd安装包
[root@localhost src]# wget https://downloads.apache.org/httpd/httpd-2.4.58.tar.bz2
--2023-12-05 14:26:06--  https://downloads.apache.org/httpd/httpd-2.4.58.tar.bz2
Resolving downloads.apache.org (downloads.apache.org)... 135.181.214.104, 88.99.95.219, 2a01:4f8:10a:201a::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|135.181.214.104|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7485817 (7.1M) [application/x-bzip2]
Saving to: ‘httpd-2.4.58.tar.bz2’

httpd-2.4.58.tar.bz2   100%[==========================>]   7.14M  2.04MB/s    in 3.5s    

2023-12-05 14:26:10 (2.04 MB/s) - ‘httpd-2.4.58.tar.bz2’ saved [7485817/7485817]

创建apache用户与组
[root@localhost ~]# groupadd -r apache
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g apache apache

解压httpd
[root@localhost ~]# cd /usr/src
[root@localhost src]# tar xf httpd-2.4.58.tar.bz2 
[root@localhost src]# ls
debug  httpd-2.4.58  httpd-2.4.58.tar.bz2  kernels

安装必要软件
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
[root@localhost httpd-2.4.58]# sudo yum -y install apr-devel apr-util-devel
[root@localhost httpd-2.4.58]# sudo yum -y groupinstall "Development Tools"
[root@localhost httpd-2.4.58]# .configure --prefix=/opt/httpd-2.4.58
[root@localhost httpd-2.4.58]# echo $?
0

编译并安装
[root@localhost httpd-2.4.58]# make
make[1]: Leaving directory '/usr/src/httpd-2.4.58'
[root@localhost httpd-2.4.58]# make install
make[1]: Leaving directory '/usr/src/httpd-2.4.58'
[root@localhost httpd-2.4.58]# echo $?
0

创建软连接并把配置写入环境变量里面
[root@localhost ~]# ln -s /opt/httpd-2.4.58 /opt/httpd
[root@localhost ~]# sed -i '/#ServerName/s/#//g' /opt/httpd-2.4.58/conf/httpd.conf
[root@localhost ~]# echo 'export PATH=/opt/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh 
[root@localhost ~]# httpd
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port         Peer Address:Port    Process    
LISTEN    0         128                0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         4096             127.0.0.1:631               0.0.0.0:*                  
LISTEN    0         511                      *:80                      *:*                  
LISTEN    0         128                   [::]:22                   [::]:*                  
LISTEN    0         4096                 [::1]:631                  [::]:*                 

二进制部署mysql8.0.35,并使用navicat workbench

创建MySQL用户
[root@localhost ~]# useradd -r -s /sbin/nologin -M mysql
[root@localhost ~]# ls
anaconda-ks.cfg  Documents  Music                                       Pictures  Templates
Desktop          Downloads  mysql-8.0.35-linux-glibc2.28-x86_64.tar.xz  Public    Videos

解压软件包
[root@localhost ~]# tar xf mysql-8.0.35-linux-glibc2.28-x86_64.tar.xz -C /usr/local/
[root@localhost ~]# cd /usr/local/

改名字
[root@localhost local]# mv mysql-8.0.35-linux-glibc2.28-x86_64/ mysql
[root@localhost local]# pwd
/usr/local
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src

设置环境变量
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh

刷新
[root@localhost local]# cd mysql
[root@localhost mysql]# source /etc/profile.d/mysql.sh 

创建软连接
[root@localhost mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql

创建并编辑mysql.conf文件
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost mysql]# ldconfig 
[root@localhost mysql]# vim /etc/man_db.conf 
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/mysql/man
[root@localhost mysql]# cd

设置目录的所有者和所属组
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/

使用mysql用户初始化MySQL服务器,并将数据目录设置为/opt/data/
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/
2023-12-05T09:24:09.978475Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.35) initializing of server in progress as process 24881
2023-12-05T09:24:10.064879Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-12-05T09:24:10.777403Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-12-05T09:24:15.277207Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: D&zn,Xdd-9mr  //一次性密码

把mysql开机自启编辑到配置文件里面
[root@localhost ~]# vi /etc/my.cnf
[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# mkdir /etc/init.d
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# cp -a mysql.server /etc/init.d/mysqld
[root@localhost support-files]# ll /etc/init.d/mysqld 
-rwxr-xr-x. 1 mysql mysql 10576 Oct 12 21:47 /etc/init.d/mysqld
[root@localhost support-files]# vim /etc/init.d/mysqld
basedir=usr/local/mysql
datadir=/opt/data
[root@localhost support-files]# systemctl daemon-reload 
[root@localhost support-files]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
.. SUCCESS! 
[root@localhost support-files]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port       Peer Address:Port   Process   
LISTEN   0        128              0.0.0.0:22              0.0.0.0:*                
LISTEN   0        4096           127.0.0.1:631             0.0.0.0:*                
LISTEN   0        511                    *:80                    *:*                
LISTEN   0        128                 [::]:22                 [::]:*                
LISTEN   0        151                    *:3306                  *:*                
LISTEN   0        70                     *:33060                 *:*                
LISTEN   0        4096               [::1]:631                [::]:*    
[root@localhost ~]# service mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service mysqld.service
[root@localhost system]# vim mysqld.service 
[Unit]
Description=mysqld server daemon
After=network.target 

[Service]
Type=forking
ExecStart=service mysqld start
ExecStop=service mysqld stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

设置开机自启
[root@localhost system]# systemctl daemon-reload 
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; preset: disa>
     Active: active (running) since Tue 2023-12-05 17:56:41 CST; 8s ago
    Process: 25973 ExecStart=service mysqld start (code=exited, status=0/SUCCESS)
   Main PID: 25990 (mysqld_safe)
      Tasks: 39 (limit: 11913)
     Memory: 391.2M
        CPU: 1.920s
     CGroup: /system.slice/mysqld.service
             ├─25990 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data ->
             └─26180 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datad>

Dec 05 17:56:39 localhost.localdomain systemd[1]: Starting mysqld server daemon...
Dec 05 17:56:41 localhost.localdomain service[25977]: Starting MySQL.. SUCCESS!
Dec 05 17:56:41 localhost.localdomain systemd[1]: Started mysqld server daemon.
[root@localhost ~]# systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disab>
     Active: active (running) since Tue 2023-12-05 17:56:41 CST; 50s ago
   Main PID: 25990 (mysqld_safe)
      Tasks: 39 (limit: 11913)
     Memory: 391.2M
        CPU: 2.385s
     CGroup: /system.slice/mysqld.service
             ├─25990 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data ->
             └─26180 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datad>

Dec 05 17:56:39 localhost.localdomain systemd[1]: Starting mysqld server daemon...
Dec 05 17:56:41 localhost.localdomain service[25977]: Starting MySQL.. SUCCESS!
Dec 05 17:56:41 localhost.localdomain systemd[1]: Started mysqld server daemon.

更改密码
[root@localhost ~]# mysql -uroot -p'D&zn,Xdd-9mr'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.35

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'Passw0rd@_';
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值